|
|
|
@ -14,60 +14,6 @@ namespace SixLabors |
|
|
|
[DebuggerStepThrough] |
|
|
|
internal static class Guard |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Verifies, that the method parameter with specified object value is not null
|
|
|
|
/// and throws an exception if it is found to be so.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="target">The target object, which cannot be null.</param>
|
|
|
|
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null</exception>
|
|
|
|
/// <typeparam name="T">The type of the object to verify</typeparam>
|
|
|
|
public static void NotNull<T>(T target, string parameterName) |
|
|
|
where T : class |
|
|
|
{ |
|
|
|
if (target is null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(parameterName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies, that the string method parameter with specified object value and message
|
|
|
|
/// is not null, not empty and does not contain only blanks and throws an exception
|
|
|
|
/// if the object is null.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="target">The target string, which should be checked against being null or empty.</param>
|
|
|
|
/// <param name="parameterName">Name of the parameter.</param>
|
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
|
|
|
|
/// <exception cref="ArgumentException"><paramref name="target"/> is empty or contains only blanks.</exception>
|
|
|
|
public static void NotNullOrEmpty(string target, string parameterName) |
|
|
|
{ |
|
|
|
NotNull(target, parameterName); |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(target)) |
|
|
|
{ |
|
|
|
throw new ArgumentException("Value cannot be null, empty, or cannot contain only whitespace.", parameterName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies, that the enumeration is not null and not empty.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The type of objects in the <paramref name="target"/></typeparam>
|
|
|
|
/// <param name="target">The target enumeration, which should be checked against being null or empty.</param>
|
|
|
|
/// <param name="parameterName">Name of the parameter.</param>
|
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
|
|
|
|
/// <exception cref="ArgumentException"><paramref name="target"/> is empty.</exception>
|
|
|
|
public static void NotNullOrEmpty<T>(IEnumerable<T> target, string parameterName) |
|
|
|
{ |
|
|
|
NotNull(target, parameterName); |
|
|
|
|
|
|
|
if (!target.Any()) |
|
|
|
{ |
|
|
|
throw new ArgumentException("Value cannot be empty.", parameterName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies that the specified value is less than a maximum value
|
|
|
|
/// and throws an exception if it is not.
|
|
|
|
@ -80,7 +26,7 @@ namespace SixLabors |
|
|
|
/// <paramref name="value"/> is greater than the maximum value.
|
|
|
|
/// </exception>
|
|
|
|
public static void MustBeLessThan<TValue>(TValue value, TValue max, string parameterName) |
|
|
|
where TValue : IComparable<TValue> |
|
|
|
where TValue : IComparable<TValue> |
|
|
|
{ |
|
|
|
if (value.CompareTo(max) >= 0) |
|
|
|
{ |
|
|
|
@ -100,7 +46,7 @@ namespace SixLabors |
|
|
|
/// <paramref name="value"/> is greater than the maximum value.
|
|
|
|
/// </exception>
|
|
|
|
public static void MustBeLessThanOrEqualTo<TValue>(TValue value, TValue max, string parameterName) |
|
|
|
where TValue : IComparable<TValue> |
|
|
|
where TValue : IComparable<TValue> |
|
|
|
{ |
|
|
|
if (value.CompareTo(max) > 0) |
|
|
|
{ |
|
|
|
|