@@ -23,28 +23,25 @@ internal static partial class DebugGuard
23
23
/// <typeparam name="TValue">The type of the value.</typeparam>
24
24
/// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
25
25
[ Conditional ( "DEBUG" ) ]
26
- public static void NotNull < TValue > ( [ NotNull ] TValue ? value , string parameterName )
26
+ public static void NotNull < TValue > ( [ NotNull ] TValue ? value , [ CallerArgumentExpression ( "value" ) ] string ? parameterName = null )
27
27
where TValue : class =>
28
- ArgumentNullException . ThrowIfNull ( value , parameterName ) ;
28
+ ArgumentNullException . ThrowIfNull ( value , parameterName ) ;
29
29
30
30
/// <summary>
31
31
/// Ensures that the target value is not null, empty, or whitespace.
32
32
/// </summary>
33
33
/// <param name="value">The target string, which should be checked against being null or empty.</param>
34
- /// <param name="parameterName ">Name of the parameter.</param>
34
+ /// <param name="paramName ">Name of the parameter.</param>
35
35
/// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
36
36
/// <exception cref="ArgumentException"><paramref name="value"/> is empty or contains only blanks.</exception>
37
37
[ Conditional ( "DEBUG" ) ]
38
- public static void NotNullOrWhiteSpace ( string value , string parameterName )
38
+ public static void NotNullOrWhiteSpace ( [ NotNull ] string ? value , [ CallerArgumentExpression ( "value" ) ] string ? paramName = null )
39
39
{
40
- if ( value is null )
41
- {
42
- ThrowArgumentNullException ( parameterName ) ;
43
- }
40
+ ArgumentNullException . ThrowIfNull ( value ) ;
44
41
45
42
if ( string . IsNullOrWhiteSpace ( value ) )
46
43
{
47
- ThrowArgumentException ( "Must not be empty or whitespace." , parameterName ) ;
44
+ ThrowArgumentException ( "Must not be empty or whitespace." , paramName ! ) ;
48
45
}
49
46
}
50
47
@@ -151,7 +148,9 @@ public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TVal
151
148
{
152
149
if ( value . CompareTo ( min ) < 0 || value . CompareTo ( max ) > 0 )
153
150
{
154
- ThrowArgumentOutOfRangeException ( parameterName , $ "Value { value } must be greater than or equal to { min } and less than or equal to { max } .") ;
151
+ ThrowArgumentOutOfRangeException (
152
+ parameterName ,
153
+ $ "Value { value } must be greater than or equal to { min } and less than or equal to { max } .") ;
155
154
}
156
155
}
157
156
@@ -278,8 +277,4 @@ private static void ThrowArgumentException(string message, string parameterName)
278
277
[ MethodImpl ( MethodImplOptions . NoInlining ) ]
279
278
private static void ThrowArgumentOutOfRangeException ( string parameterName , string message ) =>
280
279
throw new ArgumentOutOfRangeException ( parameterName , message ) ;
281
-
282
- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
283
- private static void ThrowArgumentNullException ( string parameterName ) =>
284
- throw new ArgumentNullException ( parameterName ) ;
285
280
}
0 commit comments