44using System ;
55using System . Collections . Generic ;
66using System . Diagnostics ;
7- using System . Linq ;
87
98namespace SixLabors . ImageSharp
109{
@@ -15,78 +14,62 @@ namespace SixLabors.ImageSharp
1514 internal static class Guard
1615 {
1716 /// <summary>
18- /// Verifies, that the method parameter with specified object value is not null
19- /// and throws an exception if it is found to be so.
17+ /// Ensures that the value is not null.
2018 /// </summary>
21- /// <param name="target ">The target object, which cannot be null.</param>
19+ /// <param name="value ">The target object, which cannot be null.</param>
2220 /// <param name="parameterName">The name of the parameter that is to be checked.</param>
23- /// <param name="message">The error message, if any to add to the exception.</param>
24- /// <exception cref="ArgumentNullException"><paramref name="target"/> is null</exception>
25- public static void NotNull ( object target , string parameterName , string message = "" )
21+ /// <exception cref="ArgumentNullException"><paramref name="value"/> is null</exception>
22+ public static void NotNull ( object value , string parameterName )
2623 {
27- if ( target == null )
24+ if ( value == null )
2825 {
29- if ( ! string . IsNullOrWhiteSpace ( message ) )
30- {
31- throw new ArgumentNullException ( parameterName , message ) ;
32- }
33-
3426 throw new ArgumentNullException ( parameterName ) ;
3527 }
3628 }
3729
3830 /// <summary>
39- /// Verifies, that the string method parameter with specified object value and message
40- /// is not null, not empty and does not contain only blanks and throws an exception
41- /// if the object is null.
31+ /// Ensures that the target value is not null, empty, or whitespace.
4232 /// </summary>
43- /// <param name="target ">The target string, which should be checked against being null or empty.</param>
33+ /// <param name="value ">The target string, which should be checked against being null or empty.</param>
4434 /// <param name="parameterName">Name of the parameter.</param>
45- /// <param name="message">The error message, if any to add to the exception.</param>
46- /// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
47- /// <exception cref="ArgumentException"><paramref name="target"/> is empty or contains only blanks.</exception>
48- public static void NotNullOrEmpty ( string target , string parameterName , string message = "" )
35+ /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
36+ /// <exception cref="ArgumentException"><paramref name="value"/> is empty or contains only blanks.</exception>
37+ public static void NotNullOrWhiteSpace ( string value , string parameterName )
4938 {
50- NotNull ( target , parameterName , message ) ;
51-
52- if ( string . IsNullOrWhiteSpace ( target ) )
39+ if ( value == null )
5340 {
54- if ( ! string . IsNullOrWhiteSpace ( message ) )
55- {
56- throw new ArgumentException ( message , parameterName ) ;
57- }
41+ throw new ArgumentNullException ( parameterName ) ;
42+ }
5843
59- throw new ArgumentException ( "Value cannot be null or empty and cannot contain only blanks." , parameterName ) ;
44+ if ( string . IsNullOrWhiteSpace ( value ) )
45+ {
46+ throw new ArgumentException ( "Must not be empty or whitespace." , parameterName ) ;
6047 }
6148 }
6249
6350 /// <summary>
64- /// Verifies, that the enumeration is not null and not empty.
51+ /// Ensures that the enumeration is not null or empty.
6552 /// </summary>
66- /// <typeparam name="T">The type of objects in the <paramref name="target "/></typeparam>
67- /// <param name="target ">The target enumeration, which should be checked against being null or empty.</param>
53+ /// <typeparam name="T">The type of objects in the <paramref name="value "/></typeparam>
54+ /// <param name="value ">The target enumeration, which should be checked against being null or empty.</param>
6855 /// <param name="parameterName">Name of the parameter.</param>
69- /// <param name="message">The error message, if any to add to the exception.</param>
70- /// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
71- /// <exception cref="ArgumentException"><paramref name="target"/> is empty.</exception>
72- public static void NotNullOrEmpty < T > ( IEnumerable < T > target , string parameterName , string message = "" )
56+ /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
57+ /// <exception cref="ArgumentException"><paramref name="value"/> is empty.</exception>
58+ public static void NotNullOrEmpty < T > ( ICollection < T > value , string parameterName )
7359 {
74- NotNull ( target , parameterName , message ) ;
75-
76- if ( ! target . Any ( ) )
60+ if ( value == null )
7761 {
78- if ( ! string . IsNullOrWhiteSpace ( message ) )
79- {
80- throw new ArgumentException ( message , parameterName ) ;
81- }
62+ throw new ArgumentNullException ( parameterName ) ;
63+ }
8264
83- throw new ArgumentException ( "Value cannot be empty." , parameterName ) ;
65+ if ( value . Count == 0 )
66+ {
67+ throw new ArgumentException ( "Must not be empty." , parameterName ) ;
8468 }
8569 }
8670
8771 /// <summary>
88- /// Verifies that the specified value is less than a maximum value
89- /// and throws an exception if it is not.
72+ /// Ensures that the specified value is less than a maximum value.
9073 /// </summary>
9174 /// <param name="value">The target value, which should be validated.</param>
9275 /// <param name="max">The maximum value.</param>
@@ -191,15 +174,9 @@ public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TVal
191174 /// Verifies, that the method parameter with specified target value is true
192175 /// and throws an exception if it is found to be so.
193176 /// </summary>
194- /// <param name="target">
195- /// The target value, which cannot be false.
196- /// </param>
197- /// <param name="parameterName">
198- /// The name of the parameter that is to be checked.
199- /// </param>
200- /// <param name="message">
201- /// The error message, if any to add to the exception.
202- /// </param>
177+ /// <param name="target">The target value, which cannot be false.</param>
178+ /// <param name="parameterName">The name of the parameter that is to be checked.</param>
179+ /// <param name="message">The error message, if any to add to the exception.</param>
203180 /// <exception cref="ArgumentException">
204181 /// <paramref name="target"/> is false
205182 /// </exception>
0 commit comments