Repository navigation
Expand file tree
/
Copy pathValidationExtensions.NullNoneEmptyRule.cs
More file actions
52 lines (46 loc) · 3.89 KB
/
Copy pathValidationExtensions.NullNoneEmptyRule.cs
File metadata and controls
52 lines (46 loc) · 3.89 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
52
namespace CoreEx.Validation;
public static partial class ValidationExtensions
{
/// <summary>
/// Chains a must be <see langword="null"/> (<see cref="NullNoneEmptyRule{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>
public static IPropertyRule<TEntity, TProperty> Null<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule) where TEntity : class where TProperty : class?
=> Chain(rule, new NullNoneEmptyRule<TEntity, TProperty>(mustBeNull: _ => true, mustBeDefault: _ => false, mustBeEmpty: _ => false));
/// <summary>
/// Chains a must be <see langword="default"/> (<see cref="NullNoneEmptyRule{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>
public static IPropertyRule<TEntity, TProperty> None<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule) where TEntity : class
=> Chain(rule, new NullNoneEmptyRule<TEntity, TProperty>(mustBeNull: _ => false, mustBeDefault: _ => true, mustBeEmpty: _ => false));
/// <summary>
/// Chains a must be empty (<see cref="NullNoneEmptyRule{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>
public static IPropertyRule<TEntity, TProperty> Empty<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule) where TEntity : class where TProperty : class?
=> Chain(rule, new NullNoneEmptyRule<TEntity, TProperty>(mustBeNull: _ => false, mustBeDefault: _ => false, mustBeEmpty: _ => true));
/// <summary>
/// Chains a must be null (<see cref="NullNoneEmptyRule{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>
public static IPropertyRule<TEntity, TProperty?> Null<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule) where TEntity : class where TProperty : struct
=> Chain(rule, new NullNoneEmptyRule<TEntity, TProperty?>(mustBeNull: _ => true, mustBeDefault: _ => false, mustBeEmpty: _ => false));
/// <summary>
/// Chains a must be <see langword="default"/> (<see cref="NullNoneEmptyRule{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>
public static IPropertyRule<TEntity, TProperty> None<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule) where TEntity : class where TProperty : struct
=> Chain(rule, new NullNoneEmptyRule<TEntity, TProperty>(mustBeNull: _ => false, mustBeDefault: _ => true, mustBeEmpty: _ => false));
/// <summary>
/// Chains a must be empty (<see cref="NullNoneEmptyRule{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>
public static IPropertyRule<TEntity, TProperty> Empty<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule) where TEntity : class where TProperty : struct
=> Chain(rule, new NullNoneEmptyRule<TEntity, TProperty>(mustBeNull: _ => false, mustBeDefault: _ => false, mustBeEmpty: _ => true));
}