Repository navigation
Expand file tree
/
Copy pathValidationExtensions.ErrorRule.cs
More file actions
51 lines (46 loc) · 3.93 KB
/
Copy pathValidationExtensions.ErrorRule.cs
File metadata and controls
51 lines (46 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace CoreEx.Validation;
public static partial class ValidationExtensions
{
/// <summary>
/// Chains a specified <paramref name="error"/> (<see cref="ErrorRule{TEntity, TProperty}"/>) validation to the existing <paramref name="rule"/>.
/// </summary>
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam>
/// <typeparam name="TProperty">The property <see cref="Type"/>.</typeparam>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="error">The error text.</param>
/// <remarks>Use a succeeding conditional clause to control whether the <paramref name="error"/> is emitted.</remarks>
public static IPropertyRule<TEntity, TProperty> Error<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, LText error) where TEntity : class
=> Chain(rule, new ErrorRule<TEntity, TProperty>(error));
/// <summary>
/// Chains a duplicate (<see cref="ErrorRule{TEntity, TProperty}"/>) validation to the existing <paramref name="rule"/>.
/// </summary>
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam>
/// <typeparam name="TProperty">The property <see cref="Type"/>.</typeparam>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <remarks>Use a succeeding conditional clause to control whether the error (<see cref="ValidatorStrings.DuplicateFormat"/>) is emitted.</remarks>
public static IPropertyRule<TEntity, TProperty> Duplicate<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule) where TEntity : class => Error(rule, ValidatorStrings.DuplicateFormat);
/// <summary>
/// Chains a not-found (<see cref="ErrorRule{TEntity, TProperty}"/>) validation to the existing <paramref name="rule"/>.
/// </summary>
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam>
/// <typeparam name="TProperty">The property <see cref="Type"/>.</typeparam>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <remarks>Use a succeeding conditional clause to control whether the error (<see cref="ValidatorStrings.NotFoundFormat"/>) is emitted.</remarks>
public static IPropertyRule<TEntity, TProperty> NotFound<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule) where TEntity : class => Error(rule, ValidatorStrings.NotFoundFormat);
/// <summary>
/// Chains an invalid (<see cref="ErrorRule{TEntity, TProperty}"/>) validation to the existing <paramref name="rule"/>.
/// </summary>
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam>
/// <typeparam name="TProperty">The property <see cref="Type"/>.</typeparam>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <remarks>Use a succeeding conditional clause to control whether the error (<see cref="ValidatorStrings.InvalidFormat"/>) is emitted.</remarks>
public static IPropertyRule<TEntity, TProperty> Invalid<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule) where TEntity : class => Error(rule, ValidatorStrings.InvalidFormat);
/// <summary>
/// Chains an invalid (<see cref="ErrorRule{TEntity, TProperty}"/>) validation to the existing <paramref name="rule"/>.
/// </summary>
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam>
/// <typeparam name="TProperty">The property <see cref="Type"/>.</typeparam>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <remarks>Use a succeeding conditional clause to control whether the error (<see cref="ValidatorStrings.ImmutableFormat"/>) is emitted.</remarks>
public static IPropertyRule<TEntity, TProperty> Immutable<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule) where TEntity : class => Error(rule, ValidatorStrings.ImmutableFormat);
}