@@ -26,8 +26,9 @@ public static void NotNull<T>(T argument, string argumentName) where T : class
26
26
public static void NotNullOrEmpty ( string argument , string argumentName )
27
27
{
28
28
if ( string . IsNullOrEmpty ( argument ) )
29
- throw new ArgumentNullException ( argument , argumentName ) ;
29
+ throw new ArgumentNullException ( argumentName , argument ) ;
30
30
}
31
+
31
32
/// <summary>
32
33
/// Ensure that the argument (ICollection) is neither null nor empty (throw an exception if it is)
33
34
/// </summary>
@@ -41,6 +42,19 @@ public static void NotNullOrEmpty<T>(ICollection<T> argument, string argumentNam
41
42
throw new ArgumentOutOfRangeException ( argumentName , argumentName + " must have items." ) ;
42
43
}
43
44
45
+ /// <summary>
46
+ /// Ensure that the argument (IEnumerable) is neither null nor empty (throw an exception if it is)
47
+ /// </summary>
48
+ /// <param name="argument"></param>
49
+ /// <param name="argumentName"></param>
50
+ public static void NotNullOrEmpty < T > ( IEnumerable < T > argument , string argumentName )
51
+ {
52
+ if ( argument == null )
53
+ throw new ArgumentNullException ( argumentName ) ;
54
+ if ( ! argument . Any ( ) )
55
+ throw new ArgumentOutOfRangeException ( argumentName , argumentName + " must have items." ) ;
56
+ }
57
+
44
58
/// <summary>
45
59
/// Ensure that the argument (an int) is >0 (throw an exception if it is <=0)
46
60
/// </summary>
@@ -115,7 +129,7 @@ public static void Nonnegative(decimal number, string argumentName)
115
129
public static void NotEmptyGuid ( Guid guid , string argumentName )
116
130
{
117
131
if ( Guid . Empty == guid )
118
- throw new ArgumentException ( argumentName , argumentName + " shoud be non-empty GUID." ) ;
132
+ throw new ArgumentException ( argumentName + " should be non-empty GUID." , argumentName ) ;
119
133
}
120
134
121
135
/// <summary>
@@ -173,7 +187,7 @@ public static void Equal(Guid expected, Guid actual, string argumentName)
173
187
/// <param name="argumentName"></param>
174
188
public static void PowerOf2 ( int argument , string argumentName )
175
189
{
176
- if ( ( argument <= 0 ) || ( ( ( uint ) argument ) & ( ( uint ) argument - 1 ) ) != 0 )
190
+ if ( argument <= 0 || ( ( uint ) argument & ( ( uint ) argument - 1 ) ) != 0 )
177
191
throw new ArgumentException ( $ "{ argumentName } : { argument } is not a power of 2") ;
178
192
}
179
193
0 commit comments