@@ -23,28 +23,25 @@ internal static partial class DebugGuard
2323 /// <typeparam name="TValue">The type of the value.</typeparam>
2424 /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
2525 [ 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 )
2727 where TValue : class =>
28- ArgumentNullException . ThrowIfNull ( value , parameterName ) ;
28+ ArgumentNullException . ThrowIfNull ( value , parameterName ) ;
2929
3030 /// <summary>
3131 /// Ensures that the target value is not null, empty, or whitespace.
3232 /// </summary>
3333 /// <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>
3535 /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
3636 /// <exception cref="ArgumentException"><paramref name="value"/> is empty or contains only blanks.</exception>
3737 [ Conditional ( "DEBUG" ) ]
38- public static void NotNullOrWhiteSpace ( string value , string parameterName )
38+ public static void NotNullOrWhiteSpace ( [ NotNull ] string ? value , [ CallerArgumentExpression ( "value" ) ] string ? paramName = null )
3939 {
40- if ( value is null )
41- {
42- ThrowArgumentNullException ( parameterName ) ;
43- }
40+ ArgumentNullException . ThrowIfNull ( value ) ;
4441
4542 if ( string . IsNullOrWhiteSpace ( value ) )
4643 {
47- ThrowArgumentException ( "Must not be empty or whitespace." , parameterName ) ;
44+ ThrowArgumentException ( "Must not be empty or whitespace." , paramName ! ) ;
4845 }
4946 }
5047
@@ -151,7 +148,9 @@ public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TVal
151148 {
152149 if ( value . CompareTo ( min ) < 0 || value . CompareTo ( max ) > 0 )
153150 {
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 } .") ;
155154 }
156155 }
157156
@@ -278,8 +277,4 @@ private static void ThrowArgumentException(string message, string parameterName)
278277 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
279278 private static void ThrowArgumentOutOfRangeException ( string parameterName , string message ) =>
280279 throw new ArgumentOutOfRangeException ( parameterName , message ) ;
281-
282- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
283- private static void ThrowArgumentNullException ( string parameterName ) =>
284- throw new ArgumentNullException ( parameterName ) ;
285280}
0 commit comments