@@ -4,23 +4,23 @@ internal static class CheckExtensions
44{
55 internal static T Check < T > ( this T value , Predicate < T > checkPredicate , string argumentName , string errorMessage )
66 {
7- if ( checkPredicate != null && ! checkPredicate ( value ) )
7+ if ( checkPredicate is not null && ! checkPredicate ( value ) )
88 throw new ArgumentException ( errorMessage , argumentName ) ;
99
1010 return value ;
1111 }
1212
1313 internal static T CheckNotNull < T > ( this T value , string argumentName , string errorMessage = null )
1414 {
15- if ( value == null )
15+ if ( value is null )
1616 throw CreateArgumentNullException ( argumentName , errorMessage ) ;
1717
1818 return value ;
1919 }
2020
2121 internal static string CheckNotNullOrWhitespace ( this string value , string argumentName , string errorMessage = null )
2222 {
23- if ( value == null )
23+ if ( value is null )
2424 throw CreateArgumentNullException ( argumentName , errorMessage ) ;
2525 if ( string . IsNullOrWhiteSpace ( value ) )
2626 throw new ArgumentException ( ConcatMessage ( "Should not be empty string or whitespace." , errorMessage ) , argumentName ) ;
@@ -30,7 +30,7 @@ internal static string CheckNotNullOrWhitespace(this string value, string argume
3030
3131 internal static string CheckNotNullOrEmpty ( this string value , string argumentName , string errorMessage = null )
3232 {
33- if ( value == null )
33+ if ( value is null )
3434 throw CreateArgumentNullException ( argumentName , errorMessage ) ;
3535 if ( value . Length == 0 )
3636 throw new ArgumentException ( ConcatMessage ( "Should not be empty string." , errorMessage ) , argumentName ) ;
@@ -40,9 +40,14 @@ internal static string CheckNotNullOrEmpty(this string value, string argumentNam
4040
4141 internal static IEnumerable < T > CheckNotNullOrEmpty < T > ( this IEnumerable < T > collection , string argumentName , string errorMessage = null )
4242 {
43- if ( collection == null )
43+ if ( collection is null )
4444 throw CreateArgumentNullException ( argumentName , errorMessage ) ;
45- if ( ! collection . Any ( ) )
45+
46+ bool isEmpty = collection is IReadOnlyCollection < T > collectionCasted
47+ ? collectionCasted . Count == 0
48+ : ! collection . Any ( ) ;
49+
50+ if ( isEmpty )
4651 throw new ArgumentException ( ConcatMessage ( "Collection should contain at least one element." , errorMessage ) , argumentName ) ;
4752
4853 return collection ;
0 commit comments