|
4 | 4 | // Copyright (c) Six Labors. |
5 | 5 | // Licensed under the Six Labors Split License. |
6 | 6 |
|
7 | | -using System; |
8 | 7 | using System.Runtime.CompilerServices; |
9 | 8 |
|
10 | 9 | namespace SixLabors |
| 10 | + |
| 11 | +/// <summary> |
| 12 | +/// Provides methods to protect against invalid parameters. |
| 13 | +/// </summary> |
| 14 | +internal static partial class Guard |
11 | 15 | { |
12 | | - /// <summary> |
13 | | - /// Provides methods to protect against invalid parameters. |
14 | | - /// </summary> |
15 | | - internal static partial class Guard |
16 | | - { |
17 | 16 | <# |
18 | 17 | var types = new[] { "byte", "sbyte", "short", "ushort", "char", "int", "uint", "float", "long", "ulong", "double", "decimal" }; |
19 | 18 |
|
20 | 19 | for (var i = 0; i < types.Length; i++) |
21 | 20 | { |
22 | | - if (i > 0) WriteLine(""); |
| 21 | +if (i > 0) WriteLine(""); |
23 | 22 |
|
24 | | - var T = types[i]; |
| 23 | +var T = types[i]; |
25 | 24 | #> |
26 | | - /// <summary> |
27 | | - /// Ensures that the specified value is less than a maximum value. |
28 | | - /// </summary> |
29 | | - /// <param name="value">The target value, which should be validated.</param> |
30 | | - /// <param name="max">The maximum value.</param> |
31 | | - /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
32 | | - /// <exception cref="ArgumentException"> |
33 | | - /// <paramref name="value"/> is greater than the maximum value. |
34 | | - /// </exception> |
35 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
36 | | - public static void MustBeLessThan(<#=T#> value, <#=T#> max, string parameterName) |
| 25 | + /// <summary> |
| 26 | + /// Ensures that the specified value is less than a maximum value. |
| 27 | + /// </summary> |
| 28 | + /// <param name="value">The target value, which should be validated.</param> |
| 29 | + /// <param name="max">The maximum value.</param> |
| 30 | + /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
| 31 | + /// <exception cref="ArgumentException"> |
| 32 | + /// <paramref name="value"/> is greater than the maximum value. |
| 33 | + /// </exception> |
| 34 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 35 | + public static void MustBeLessThan(<#=T#> value, <#=T#> max, string parameterName) |
| 36 | + { |
| 37 | + if (value < max) |
37 | 38 | { |
38 | | - if (value < max) |
39 | | - { |
40 | | - return; |
41 | | - } |
42 | | - |
43 | | - ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); |
| 39 | + return; |
44 | 40 | } |
45 | 41 |
|
46 | | - /// <summary> |
47 | | - /// Verifies that the specified value is less than or equal to a maximum value |
48 | | - /// and throws an exception if it is not. |
49 | | - /// </summary> |
50 | | - /// <param name="value">The target value, which should be validated.</param> |
51 | | - /// <param name="max">The maximum value.</param> |
52 | | - /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
53 | | - /// <exception cref="ArgumentException"> |
54 | | - /// <paramref name="value"/> is greater than the maximum value. |
55 | | - /// </exception> |
56 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
57 | | - public static void MustBeLessThanOrEqualTo(<#=T#> value, <#=T#> max, string parameterName) |
58 | | - { |
59 | | - if (value <= max) |
60 | | - { |
61 | | - return; |
62 | | - } |
| 42 | + ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); |
| 43 | + } |
63 | 44 |
|
64 | | - ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); |
| 45 | + /// <summary> |
| 46 | + /// Verifies that the specified value is less than or equal to a maximum value |
| 47 | + /// and throws an exception if it is not. |
| 48 | + /// </summary> |
| 49 | + /// <param name="value">The target value, which should be validated.</param> |
| 50 | + /// <param name="max">The maximum value.</param> |
| 51 | + /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
| 52 | + /// <exception cref="ArgumentException"> |
| 53 | + /// <paramref name="value"/> is greater than the maximum value. |
| 54 | + /// </exception> |
| 55 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 56 | + public static void MustBeLessThanOrEqualTo(<#=T#> value, <#=T#> max, string parameterName) |
| 57 | + { |
| 58 | + if (value <= max) |
| 59 | + { |
| 60 | + return; |
65 | 61 | } |
66 | 62 |
|
67 | | - /// <summary> |
68 | | - /// Verifies that the specified value is greater than a minimum value |
69 | | - /// and throws an exception if it is not. |
70 | | - /// </summary> |
71 | | - /// <param name="value">The target value, which should be validated.</param> |
72 | | - /// <param name="min">The minimum value.</param> |
73 | | - /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
74 | | - /// <exception cref="ArgumentException"> |
75 | | - /// <paramref name="value"/> is less than the minimum value. |
76 | | - /// </exception> |
77 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
78 | | - public static void MustBeGreaterThan(<#=T#> value, <#=T#> min, string parameterName) |
79 | | - { |
80 | | - if (value > min) |
81 | | - { |
82 | | - return; |
83 | | - } |
| 63 | + ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); |
| 64 | + } |
84 | 65 |
|
85 | | - ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); |
| 66 | + /// <summary> |
| 67 | + /// Verifies that the specified value is greater than a minimum value |
| 68 | + /// and throws an exception if it is not. |
| 69 | + /// </summary> |
| 70 | + /// <param name="value">The target value, which should be validated.</param> |
| 71 | + /// <param name="min">The minimum value.</param> |
| 72 | + /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
| 73 | + /// <exception cref="ArgumentException"> |
| 74 | + /// <paramref name="value"/> is less than the minimum value. |
| 75 | + /// </exception> |
| 76 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 77 | + public static void MustBeGreaterThan(<#=T#> value, <#=T#> min, string parameterName) |
| 78 | + { |
| 79 | + if (value > min) |
| 80 | + { |
| 81 | + return; |
86 | 82 | } |
87 | 83 |
|
88 | | - /// <summary> |
89 | | - /// Verifies that the specified value is greater than or equal to a minimum value |
90 | | - /// and throws an exception if it is not. |
91 | | - /// </summary> |
92 | | - /// <param name="value">The target value, which should be validated.</param> |
93 | | - /// <param name="min">The minimum value.</param> |
94 | | - /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
95 | | - /// <exception cref="ArgumentException"> |
96 | | - /// <paramref name="value"/> is less than the minimum value. |
97 | | - /// </exception> |
98 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
99 | | - public static void MustBeGreaterThanOrEqualTo(<#=T#> value, <#=T#> min, string parameterName) |
100 | | - { |
101 | | - if (value >= min) |
102 | | - { |
103 | | - return; |
104 | | - } |
| 84 | + ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); |
| 85 | + } |
105 | 86 |
|
106 | | - ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); |
| 87 | + /// <summary> |
| 88 | + /// Verifies that the specified value is greater than or equal to a minimum value |
| 89 | + /// and throws an exception if it is not. |
| 90 | + /// </summary> |
| 91 | + /// <param name="value">The target value, which should be validated.</param> |
| 92 | + /// <param name="min">The minimum value.</param> |
| 93 | + /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
| 94 | + /// <exception cref="ArgumentException"> |
| 95 | + /// <paramref name="value"/> is less than the minimum value. |
| 96 | + /// </exception> |
| 97 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 98 | + public static void MustBeGreaterThanOrEqualTo(<#=T#> value, <#=T#> min, string parameterName) |
| 99 | + { |
| 100 | + if (value >= min) |
| 101 | + { |
| 102 | + return; |
107 | 103 | } |
108 | 104 |
|
109 | | - /// <summary> |
110 | | - /// Verifies that the specified value is greater than or equal to a minimum value and less than |
111 | | - /// or equal to a maximum value and throws an exception if it is not. |
112 | | - /// </summary> |
113 | | - /// <param name="value">The target value, which should be validated.</param> |
114 | | - /// <param name="min">The minimum value.</param> |
115 | | - /// <param name="max">The maximum value.</param> |
116 | | - /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
117 | | - /// <exception cref="ArgumentException"> |
118 | | - /// <paramref name="value"/> is less than the minimum value of greater than the maximum value. |
119 | | - /// </exception> |
120 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
121 | | - public static void MustBeBetweenOrEqualTo(<#=T#> value, <#=T#> min, <#=T#> max, string parameterName) |
122 | | - { |
123 | | - if (value >= min && value <= max) |
124 | | - { |
125 | | - return; |
126 | | - } |
| 105 | + ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); |
| 106 | + } |
127 | 107 |
|
128 | | - ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); |
| 108 | + /// <summary> |
| 109 | + /// Verifies that the specified value is greater than or equal to a minimum value and less than |
| 110 | + /// or equal to a maximum value and throws an exception if it is not. |
| 111 | + /// </summary> |
| 112 | + /// <param name="value">The target value, which should be validated.</param> |
| 113 | + /// <param name="min">The minimum value.</param> |
| 114 | + /// <param name="max">The maximum value.</param> |
| 115 | + /// <param name="parameterName">The name of the parameter that is to be checked.</param> |
| 116 | + /// <exception cref="ArgumentException"> |
| 117 | + /// <paramref name="value"/> is less than the minimum value of greater than the maximum value. |
| 118 | + /// </exception> |
| 119 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 120 | + public static void MustBeBetweenOrEqualTo(<#=T#> value, <#=T#> min, <#=T#> max, string parameterName) |
| 121 | + { |
| 122 | + if (value >= min && value <= max) |
| 123 | + { |
| 124 | + return; |
129 | 125 | } |
| 126 | + |
| 127 | + ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); |
| 128 | + } |
130 | 129 | <# |
131 | 130 | } |
132 | 131 | #> |
133 | | - } |
134 | 132 | } |
0 commit comments