Repository navigation
Expand file tree
/
Copy pathValidationExtensions.DecimalRule.cs
More file actions
94 lines (85 loc) · 9.3 KB
/
Copy pathValidationExtensions.DecimalRule.cs
File metadata and controls
94 lines (85 loc) · 9.3 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
namespace CoreEx.Validation;
public static partial class ValidationExtensions
{
/// <summary>
/// Chains a <paramref name="precision"/>, <paramref name="scale"/> and <paramref name="allowNegatives"/> numeric value (<see cref="NumericRule{TEntity, TProperty}"/>) validation.
/// </summary>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="precision">The maximum number of significant digits (including <paramref name="scale"/>).</param>
/// <param name="scale">The maximum number of decimal places.</param>
/// <param name="allowNegatives">Indicates whether to allow negative values.</param>
/// <remarks>For example, to validate a number with the pattern '999.99', then <paramref name="precision"/> would be 5 and <paramref name="scale"/> would be 2.</remarks>
public static IPropertyRule<TEntity, decimal> Decimal<TEntity>(this IPropertyRule<TEntity, decimal> rule, int? precision, int? scale = null, bool allowNegatives = true) where TEntity : class
=> Chain(rule, new DecimalRule<TEntity, decimal>(_ => precision, _ => scale, _ => allowNegatives));
/// <summary>
/// Chains a <paramref name="precision"/>, <paramref name="scale"/> and <paramref name="allowNegatives"/> numeric value (<see cref="NumericRule{TEntity, TProperty}"/>) validation.
/// </summary>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="precision">The maximum number of significant digits (including <paramref name="scale"/>).</param>
/// <param name="scale">The maximum number of decimal places.</param>
/// <param name="allowNegatives">Indicates whether to allow negative values.</param>
/// <remarks>For example, to validate a number with the pattern '999.99', then <paramref name="precision"/> would be 5 and <paramref name="scale"/> would be 2.</remarks>
public static IPropertyRule<TEntity, decimal> Decimal<TEntity>(this IPropertyRule<TEntity, decimal> rule, Func<PropertyContext<TEntity, decimal>, int?>? precision, Func<PropertyContext<TEntity, decimal>, int?>? scale = null, Func<PropertyContext<TEntity, decimal>, bool>? allowNegatives = null) where TEntity : class
=> Chain(rule, new DecimalRule<TEntity, decimal>(precision, scale, allowNegatives));
/// <summary>
/// Chains a <paramref name="precision"/>, <paramref name="scale"/> and <paramref name="allowNegatives"/> numeric value (<see cref="NumericRule{TEntity, TProperty}"/>) validation.
/// </summary>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="precision">The maximum number of significant digits (including <paramref name="scale"/>).</param>
/// <param name="scale">The maximum number of decimal places.</param>
/// <param name="allowNegatives">Indicates whether to allow negative values.</param>
/// <remarks>For example, to validate a number with the pattern '999.99', then <paramref name="precision"/> would be 5 and <paramref name="scale"/> would be 2.</remarks>
public static IPropertyRule<TEntity, TProperty> PrecisionScale<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, int? precision, int? scale = null, bool allowNegatives = true) where TEntity : class where TProperty : IFloatingPoint<TProperty>
=> Chain(rule, new DecimalRule<TEntity, TProperty>(_ => precision, _ => scale, _ => allowNegatives));
/// <summary>
/// Chains a <paramref name="precision"/>, <paramref name="scale"/> and <paramref name="allowNegatives"/> numeric value (<see cref="NumericRule{TEntity, TProperty}"/>) validation.
/// </summary>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="precision">The maximum number of significant digits (including <paramref name="scale"/>).</param>
/// <param name="scale">The maximum number of decimal places.</param>
/// <param name="allowNegatives">Indicates whether to allow negative values.</param>
/// <remarks>For example, to validate a number with the pattern '999.99', then <paramref name="precision"/> would be 5 and <paramref name="scale"/> would be 2.</remarks>
public static IPropertyRule<TEntity, TProperty> PrecisionScale<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty> rule, Func<PropertyContext<TEntity, TProperty>, int?>? precision, Func<PropertyContext<TEntity, TProperty>, int?>? scale = null, Func<PropertyContext<TEntity, TProperty>, bool>? allowNegatives = null) where TEntity : class where TProperty : IFloatingPoint<TProperty>
=> Chain(rule, new DecimalRule<TEntity, TProperty>(precision, scale, allowNegatives));
/* Nullable/Struct */
/// <summary>
/// Chains a <paramref name="precision"/>, <paramref name="scale"/> and <paramref name="allowNegatives"/> numeric value (<see cref="NumericRule{TEntity, TProperty}"/>) validation.
/// </summary>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="precision">The maximum number of significant digits (including <paramref name="scale"/>).</param>
/// <param name="scale">The maximum number of decimal places.</param>
/// <param name="allowNegatives">Indicates whether to allow negative values.</param>
/// <remarks>For example, to validate a number with the pattern '999.99', then <paramref name="precision"/> would be 5 and <paramref name="scale"/> would be 2.</remarks>
public static IPropertyRule<TEntity, decimal> Decimal<TEntity>(this IPropertyRule<TEntity, decimal?> rule, int? precision, int? scale = null, bool allowNegatives = true) where TEntity : class
=> Chain(rule, new DecimalRule<TEntity, decimal>(_ => precision, _ => scale, _ => allowNegatives));
/// <summary>
/// Chains a <paramref name="precision"/>, <paramref name="scale"/> and <paramref name="allowNegatives"/> numeric value (<see cref="NumericRule{TEntity, TProperty}"/>) validation.
/// </summary>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="precision">The maximum number of significant digits (including <paramref name="scale"/>).</param>
/// <param name="scale">The maximum number of decimal places.</param>
/// <param name="allowNegatives">Indicates whether to allow negative values.</param>
/// <remarks>For example, to validate a number with the pattern '999.99', then <paramref name="precision"/> would be 5 and <paramref name="scale"/> would be 2.</remarks>
public static IPropertyRule<TEntity, decimal> Decimal<TEntity>(this IPropertyRule<TEntity, decimal?> rule, Func<PropertyContext<TEntity, decimal>, int?>? precision, Func<PropertyContext<TEntity, decimal>, int?>? scale = null, Func<PropertyContext<TEntity, decimal>, bool>? allowNegatives = null) where TEntity : class
=> Chain(rule, new DecimalRule<TEntity, decimal>(precision, scale, allowNegatives));
/// <summary>
/// Chains a <paramref name="precision"/>, <paramref name="scale"/> and <paramref name="allowNegatives"/> numeric value (<see cref="NumericRule{TEntity, TProperty}"/>) validation.
/// </summary>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="precision">The maximum number of significant digits (including <paramref name="scale"/>).</param>
/// <param name="scale">The maximum number of decimal places.</param>
/// <param name="allowNegatives">Indicates whether to allow negative values.</param>
/// <remarks>For example, to validate a number with the pattern '999.99', then <paramref name="precision"/> would be 5 and <paramref name="scale"/> would be 2.</remarks>
public static IPropertyRule<TEntity, TProperty> PrecisionScale<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule, int? precision, int? scale = null, bool allowNegatives = true) where TEntity : class where TProperty : struct, IFloatingPoint<TProperty>
=> Chain(rule, new DecimalRule<TEntity, TProperty>(_ => precision, _ => scale, _ => allowNegatives));
/// <summary>
/// Chains a <paramref name="precision"/>, <paramref name="scale"/> and <paramref name="allowNegatives"/> numeric value (<see cref="NumericRule{TEntity, TProperty}"/>) validation.
/// </summary>
/// <param name="rule">The <see cref="IPropertyRule{TEntity, TProperty}"/> being extended.</param>
/// <param name="precision">The maximum number of significant digits (including <paramref name="scale"/>).</param>
/// <param name="scale">The maximum number of decimal places.</param>
/// <param name="allowNegatives">Indicates whether to allow negative values.</param>
/// <remarks>For example, to validate a number with the pattern '999.99', then <paramref name="precision"/> would be 5 and <paramref name="scale"/> would be 2.</remarks>
public static IPropertyRule<TEntity, TProperty> PrecisionScale<TEntity, TProperty>(this IPropertyRule<TEntity, TProperty?> rule, Func<PropertyContext<TEntity, TProperty>, int?>? precision, Func<PropertyContext<TEntity, TProperty>, int?>? scale = null, Func<PropertyContext<TEntity, TProperty>, bool>? allowNegatives = null) where TEntity : class where TProperty : struct, IFloatingPoint<TProperty>
=> Chain(rule, new DecimalRule<TEntity, TProperty>(precision, scale, allowNegatives));
}