-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathValidationExtensions.BetweenRule.cs
More file actions
178 lines (165 loc) · 18.1 KB
/
Copy pathValidationExtensions.BetweenRule.cs
File metadata and controls
178 lines (165 loc) · 18.1 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
namespace CoreEx.Validation;
public static partial class ValidationExtensions
{
/// <summary>
/// Chains a between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="minText">The minimum text (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="exclusiveBetween">Indicates whether the between comparison is exclusive or inclusive (default).</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> Between<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, TProperty min, TProperty max, LText? minText = null, LText? maxText = null, bool exclusiveBetween = false, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(_ => min, _ => max, _ => minText, _ => maxText, exclusiveBetween, comparer));
/// <summary>
/// Chains a between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The function to get the minimum value.</param>
/// <param name="max">The function to get the maximum value.</param>
/// <param name="minText">The minimum text formatter (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text formatter (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="exclusiveBetween">Indicates whether the between comparison is exclusive or inclusive (default).</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> Between<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, Func<PropertyContext<TEntity, TProperty>, TProperty> min, Func<PropertyContext<TEntity, TProperty>, TProperty> max, Func<TProperty, LText?>? minText = null, Func<TProperty, LText?>? maxText = null, bool exclusiveBetween = false, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(c => min.ThrowIfNull()(c), c => max.ThrowIfNull()(c), minText, maxText, exclusiveBetween, comparer));
/// <summary>
/// Chains an inclusive between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="minText">The minimum text (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> InclusiveBetween<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, TProperty min, TProperty max, LText? minText = null, LText? maxText = null, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(_ => min, _ => max, _ => minText, _ => maxText, false, comparer));
/// <summary>
/// Chains an inclusive between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The function to get the minimum value.</param>
/// <param name="max">The function to get the maximum value.</param>
/// <param name="minText">The minimum text formatter (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text formatter (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> InclusiveBetween<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, Func<PropertyContext<TEntity, TProperty>, TProperty> min, Func<PropertyContext<TEntity, TProperty>, TProperty> max, Func<TProperty, LText?>? minText = null, Func<TProperty, LText?>? maxText = null, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(c => min.ThrowIfNull()(c), c => max.ThrowIfNull()(c), minText, maxText, false, comparer));
/// <summary>
/// Chains an exclusive between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="minText">The minimum text (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> ExclusiveBetween<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, TProperty min, TProperty max, LText? minText = null, LText? maxText = null, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(_ => min, _ => max, _ => minText, _ => maxText, true, comparer));
/// <summary>
/// Chains an exclusive between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The function to get the minimum value.</param>
/// <param name="max">The function to get the maximum value.</param>
/// <param name="minText">The minimum text formatter (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text formatter (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> ExclusiveBetween<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, Func<PropertyContext<TEntity, TProperty>, TProperty> min, Func<PropertyContext<TEntity, TProperty>, TProperty> max, Func<TProperty, LText?>? minText = null, Func<TProperty, LText?>? maxText = null, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(c => min.ThrowIfNull()(c), c => max.ThrowIfNull()(c), minText, maxText, true, comparer));
/* Nullable/Struct */
/// <summary>
/// Chains a between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="minText">The minimum text (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="exclusiveBetween">Indicates whether the between comparison is exclusive or inclusive (default).</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> Between<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule, TProperty min, TProperty max, LText? minText = null, LText? maxText = null, bool exclusiveBetween = false, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : struct, IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(_ => min, _ => max, _ => minText, _ => maxText, exclusiveBetween, comparer));
/// <summary>
/// Chains a between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The function to get the minimum value.</param>
/// <param name="max">The function to get the maximum value.</param>
/// <param name="minText">The minimum text formatter (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text formatter (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="exclusiveBetween">Indicates whether the between comparison is exclusive or inclusive (default).</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> Between<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule, Func<PropertyContext<TEntity, TProperty>, TProperty> min, Func<PropertyContext<TEntity, TProperty>, TProperty> max, Func<TProperty, LText?>? minText = null, Func<TProperty, LText?>? maxText = null, bool exclusiveBetween = false, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : struct, IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(c => min.ThrowIfNull()(c), c => max.ThrowIfNull()(c), minText, maxText, exclusiveBetween, comparer));
/// <summary>
/// Chains an inclusive between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="minText">The minimum text (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> InclusiveBetween<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule, TProperty min, TProperty max, LText? minText = null, LText? maxText = null, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : struct, IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(_ => min, _ => max, _ => minText, _ => maxText, false, comparer));
/// <summary>
/// Chains an inclusive between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The function to get the minimum value.</param>
/// <param name="max">The function to get the maximum value.</param>
/// <param name="minText">The minimum text formatter (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text formatter (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> InclusiveBetween<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule, Func<PropertyContext<TEntity, TProperty>, TProperty> min, Func<PropertyContext<TEntity, TProperty>, TProperty> max, Func<TProperty, LText?>? minText = null, Func<TProperty, LText?>? maxText = null, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : struct, IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(c => min.ThrowIfNull()(c), c => max.ThrowIfNull()(c), minText, maxText, false, comparer));
/// <summary>
/// Chains an exclusive between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="minText">The minimum text (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> ExclusiveBetween<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule, TProperty min, TProperty max, LText? minText = null, LText? maxText = null, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : struct, IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(_ => min, _ => max, _ => minText, _ => maxText, true, comparer));
/// <summary>
/// Chains an exclusive between comparison (<see cref="BetweenRule{TEntity, TProperty}"/>) validation of a <paramref name="min"/> and <paramref name="max"/> value.
/// </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="min">The function to get the minimum value.</param>
/// <param name="max">The function to get the maximum value.</param>
/// <param name="minText">The minimum text formatter (used in the error message); otherwise, uses the resulting <paramref name="min"/> value.</param>
/// <param name="maxText">The maximum text formatter (used in the error message); otherwise, uses the resulting <paramref name="max"/> value.</param>
/// <param name="comparer">The optional <see cref="IComparer{T}"/>.</param>
public static IPropertyRule<TEntity, TProperty> ExclusiveBetween<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule, Func<PropertyContext<TEntity, TProperty>, TProperty> min, Func<PropertyContext<TEntity, TProperty>, TProperty> max, Func<TProperty, LText?>? minText = null, Func<TProperty, LText?>? maxText = null, IComparer<TProperty>? comparer = null) where TEntity : class where TProperty : struct, IComparable<TProperty>
=> Chain(rule, new BetweenRule<TEntity, TProperty>(c => min.ThrowIfNull()(c), c => max.ThrowIfNull()(c), minText, maxText, true, comparer));
}