@@ -12,7 +12,9 @@ namespace SixLabors
1212 /// Provides methods to protect against invalid parameters.
1313 /// </summary>
1414 [ DebuggerStepThrough ]
15+ #pragma warning disable CS0436 // Type conflicts with imported type
1516 [ ExcludeFromCodeCoverage ]
17+ #pragma warning restore CS0436 // Type conflicts with imported type
1618 internal static partial class Guard
1719 {
1820 /// <summary>
@@ -28,7 +30,7 @@ public static void NotNull<TValue>(TValue value, string parameterName)
2830 {
2931 if ( value is null )
3032 {
31- ThrowArgumentNullException ( parameterName ) ;
33+ ThrowHelper . ThrowArgumentNullExceptionForNotNull ( parameterName ) ;
3234 }
3335 }
3436
@@ -42,14 +44,9 @@ public static void NotNull<TValue>(TValue value, string parameterName)
4244 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4345 public static void NotNullOrWhiteSpace ( string value , string parameterName )
4446 {
45- if ( value is null )
46- {
47- ThrowArgumentNullException ( parameterName ) ;
48- }
49-
5047 if ( string . IsNullOrWhiteSpace ( value ) )
5148 {
52- ThrowArgumentException ( "Must not be empty or whitespace." , parameterName ) ;
49+ ThrowHelper . ThrowArgumentExceptionForNotNullOrWhitespace ( value , parameterName ) ;
5350 }
5451 }
5552
@@ -69,7 +66,7 @@ public static void MustBeLessThan<TValue>(TValue value, TValue max, string param
6966 {
7067 if ( value . CompareTo ( max ) >= 0 )
7168 {
72- ThrowArgumentOutOfRangeException ( parameterName , $ "Value { value } must be less than { max } ." ) ;
69+ ThrowHelper . ThrowArgumentOutOfRangeExceptionForMustBeLessThan ( value , max , parameterName ) ;
7370 }
7471 }
7572
@@ -90,7 +87,7 @@ public static void MustBeLessThanOrEqualTo<TValue>(TValue value, TValue max, str
9087 {
9188 if ( value . CompareTo ( max ) > 0 )
9289 {
93- ThrowArgumentOutOfRangeException ( parameterName , $ "Value { value } must be less than or equal to { max } ." ) ;
90+ ThrowHelper . ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo ( value , max , parameterName ) ;
9491 }
9592 }
9693
@@ -111,9 +108,7 @@ public static void MustBeGreaterThan<TValue>(TValue value, TValue min, string pa
111108 {
112109 if ( value . CompareTo ( min ) <= 0 )
113110 {
114- ThrowArgumentOutOfRangeException (
115- parameterName ,
116- $ "Value { value } must be greater than { min } .") ;
111+ ThrowHelper . ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan ( value , min , parameterName ) ;
117112 }
118113 }
119114
@@ -134,7 +129,7 @@ public static void MustBeGreaterThanOrEqualTo<TValue>(TValue value, TValue min,
134129 {
135130 if ( value . CompareTo ( min ) < 0 )
136131 {
137- ThrowArgumentOutOfRangeException ( parameterName , $ "Value { value } must be greater than or equal to { min } ." ) ;
132+ ThrowHelper . ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo ( value , min , parameterName ) ;
138133 }
139134 }
140135
@@ -156,7 +151,7 @@ public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TVal
156151 {
157152 if ( value . CompareTo ( min ) < 0 || value . CompareTo ( max ) > 0 )
158153 {
159- ThrowArgumentOutOfRangeException ( parameterName , $ "Value { value } must be greater than or equal to { min } and less than or equal to { max } ." ) ;
154+ ThrowHelper . ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo ( value , min , max , parameterName ) ;
160155 }
161156 }
162157
@@ -175,7 +170,7 @@ public static void IsTrue(bool target, string parameterName, string message)
175170 {
176171 if ( ! target )
177172 {
178- ThrowArgumentException ( message , parameterName ) ;
173+ ThrowHelper . ThrowArgumentException ( message , parameterName ) ;
179174 }
180175 }
181176
@@ -194,7 +189,7 @@ public static void IsFalse(bool target, string parameterName, string message)
194189 {
195190 if ( target )
196191 {
197- ThrowArgumentException ( message , parameterName ) ;
192+ ThrowHelper . ThrowArgumentException ( message , parameterName ) ;
198193 }
199194 }
200195
@@ -213,7 +208,7 @@ public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> source, int minLength,
213208 {
214209 if ( source . Length < minLength )
215210 {
216- ThrowArgumentException ( $ "Span-s must be at least of length { minLength } !" , parameterName ) ;
211+ ThrowHelper . ThrowArgumentOutOfRangeExceptionForMustBeSizedAtLeast ( minLength , parameterName ) ;
217212 }
218213 }
219214
@@ -232,7 +227,7 @@ public static void MustBeSizedAtLeast<T>(Span<T> source, int minLength, string p
232227 {
233228 if ( source . Length < minLength )
234229 {
235- ThrowArgumentException ( $ "The size must be at least { minLength } ." , parameterName ) ;
230+ ThrowHelper . ThrowArgumentOutOfRangeExceptionForMustBeSizedAtLeast ( minLength , parameterName ) ;
236231 }
237232 }
238233
@@ -252,7 +247,7 @@ public static void DestinationShouldNotBeTooShort<TSource, TDest>(
252247 {
253248 if ( destination . Length < source . Length )
254249 {
255- ThrowArgumentException ( $ "Destination span is too short!", destinationParamName ) ;
250+ ThrowHelper . ThrowArgumentException ( "Destination span is too short!" , destinationParamName ) ;
256251 }
257252 }
258253
@@ -272,20 +267,8 @@ public static void DestinationShouldNotBeTooShort<TSource, TDest>(
272267 {
273268 if ( destination . Length < source . Length )
274269 {
275- ThrowArgumentException ( $ "Destination span is too short!", destinationParamName ) ;
270+ ThrowHelper . ThrowArgumentException ( "Destination span is too short!" , destinationParamName ) ;
276271 }
277272 }
278-
279- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
280- private static void ThrowArgumentException ( string message , string parameterName ) =>
281- throw new ArgumentException ( message , parameterName ) ;
282-
283- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
284- private static void ThrowArgumentOutOfRangeException ( string parameterName , string message ) =>
285- throw new ArgumentOutOfRangeException ( parameterName , message ) ;
286-
287- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
288- private static void ThrowArgumentNullException ( string parameterName ) =>
289- throw new ArgumentNullException ( parameterName ) ;
290273 }
291274}
0 commit comments