-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathValidationExtensions.ReferenceDataRule.cs
More file actions
57 lines (50 loc) · 4.45 KB
/
Copy pathValidationExtensions.ReferenceDataRule.cs
File metadata and controls
57 lines (50 loc) · 4.45 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
53
54
55
56
57
namespace CoreEx.Validation;
public static partial class ValidationExtensions
{
/// <summary>
/// Chains an <see cref="IReferenceData"/> (<see cref="ReferenceDataRule{TEntity, TProperty}"/>) validation.
/// </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="allowInactive">Indicates whether to allow an <see cref="IReferenceData"/> value where <see cref="IReferenceData.IsActive"/> is set to <see langword="false"/>.</param>
public static IPropertyRule<TEntity, TProperty> ReferenceData<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, bool allowInactive = false) where TEntity : class where TProperty : IReferenceData
=> Chain(rule, new ReferenceDataRule<TEntity, TProperty>(allowInactive));
/// <summary>
/// Chains an <see cref="IReferenceData"/> (<see cref="ReferenceDataRule{TEntity, TProperty}"/>) validation.
/// </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="allowInactive">Indicates whether to allow an <see cref="IReferenceData"/> value where <see cref="IReferenceData.IsActive"/> is set to <see langword="false"/>.</param>
public static IPropertyRule<TEntity, TProperty> IsValid<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, bool allowInactive = false) where TEntity : class where TProperty : IReferenceData
=> ReferenceData(rule, allowInactive);
/* ReferenceData-string */
/// <summary>
/// Chains a <see langword="string"/>-based <see cref="IReferenceData.Code"/> (<see cref="ReferenceDataCodeRule{TEntity}"/>) validation to the existing <paramref name="rule"/>.
/// </summary>
/// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="with">The <see cref="ReferenceDataCodeRule{TEntity}.ReferenceDataWith"/> function.</param>
public static IPropertyRule<TEntity, string> ReferenceData<TEntity>(this IPropertyRule<TEntity, string> rule, Func<ReferenceDataCodeRule<TEntity>.ReferenceDataWith, ReferenceDataCodeRule<TEntity>.ReferenceDataWith> with) where TEntity : class
=> Chain(rule, new ReferenceDataCodeRule<TEntity>(with));
/* IReferenceDataCodeCollection */
/// <summary>
/// Chains an <see cref="IReferenceDataCodeCollection"/> (<see cref="ReferenceDataRule{TEntity, TProperty}"/>) validation.
/// </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="allowInactive">Indicates whether to allow an <see cref="IReferenceData"/> value where <see cref="IReferenceData.IsActive"/> is set to <see langword="false"/>.</param>
public static IPropertyRule<TEntity, TProperty> ReferenceDataCodes<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, bool allowInactive = false) where TEntity : class where TProperty : IReferenceDataCodeCollection
=> Chain(rule, new ReferenceDataCodeCollectionRule<TEntity, TProperty>(allowInactive));
/// <summary>
/// Chains an <see cref="IReferenceDataCodeCollection"/> (<see cref="ReferenceDataRule{TEntity, TProperty}"/>) validation.
/// </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="allowInactive">Indicates whether to allow an <see cref="IReferenceData"/> value where <see cref="IReferenceData.IsActive"/> is set to <see langword="false"/>.</param>
public static IPropertyRule<TEntity, TProperty> AreValid<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, bool allowInactive = false) where TEntity : class where TProperty : IReferenceDataCodeCollection
=> ReferenceDataCodes(rule, allowInactive);
}