|
|
|
@ -29,5 +29,137 @@ namespace ImageSharp |
|
|
|
throw new ArgumentNullException(parameterName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies that the specified value is less than a maximum value
|
|
|
|
/// and throws an exception if it is not.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">The target value, which should be validated.</param>
|
|
|
|
/// <param name="max">The maximum value.</param>
|
|
|
|
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
|
|
/// <typeparam name="TValue">The type of the value.</typeparam>
|
|
|
|
/// <exception cref="ArgumentException">
|
|
|
|
/// <paramref name="value"/> is greater than the maximum value.
|
|
|
|
/// </exception>
|
|
|
|
[Conditional("DEBUG")] |
|
|
|
public static void MustBeLessThan<TValue>(TValue value, TValue max, string parameterName) |
|
|
|
where TValue : IComparable<TValue> |
|
|
|
{ |
|
|
|
if (value.CompareTo(max) >= 0) |
|
|
|
{ |
|
|
|
throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than {max}."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies that the specified value is less than or equal to a maximum value
|
|
|
|
/// and throws an exception if it is not.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">The target value, which should be validated.</param>
|
|
|
|
/// <param name="max">The maximum value.</param>
|
|
|
|
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
|
|
/// <typeparam name="TValue">The type of the value.</typeparam>
|
|
|
|
/// <exception cref="ArgumentException">
|
|
|
|
/// <paramref name="value"/> is greater than the maximum value.
|
|
|
|
/// </exception>
|
|
|
|
[Conditional("DEBUG")] |
|
|
|
public static void MustBeLessThanOrEqualTo<TValue>(TValue value, TValue max, string parameterName) |
|
|
|
where TValue : IComparable<TValue> |
|
|
|
{ |
|
|
|
if (value.CompareTo(max) > 0) |
|
|
|
{ |
|
|
|
throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than or equal to {max}."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies that the specified value is greater than a minimum value
|
|
|
|
/// and throws an exception if it is not.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">The target value, which should be validated.</param>
|
|
|
|
/// <param name="min">The minimum value.</param>
|
|
|
|
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
|
|
/// <typeparam name="TValue">The type of the value.</typeparam>
|
|
|
|
/// <exception cref="ArgumentException">
|
|
|
|
/// <paramref name="value"/> is less than the minimum value.
|
|
|
|
/// </exception>
|
|
|
|
[Conditional("DEBUG")] |
|
|
|
public static void MustBeGreaterThan<TValue>(TValue value, TValue min, string parameterName) |
|
|
|
where TValue : IComparable<TValue> |
|
|
|
{ |
|
|
|
if (value.CompareTo(min) <= 0) |
|
|
|
{ |
|
|
|
throw new ArgumentOutOfRangeException( |
|
|
|
parameterName, |
|
|
|
$"Value must be greater than {min}."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies that the specified value is greater than or equal to a minimum value
|
|
|
|
/// and throws an exception if it is not.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">The target value, which should be validated.</param>
|
|
|
|
/// <param name="min">The minimum value.</param>
|
|
|
|
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
|
|
/// <typeparam name="TValue">The type of the value.</typeparam>
|
|
|
|
/// <exception cref="ArgumentException">
|
|
|
|
/// <paramref name="value"/> is less than the minimum value.
|
|
|
|
/// </exception>
|
|
|
|
[Conditional("DEBUG")] |
|
|
|
public static void MustBeGreaterThanOrEqualTo<TValue>(TValue value, TValue min, string parameterName) |
|
|
|
where TValue : IComparable<TValue> |
|
|
|
{ |
|
|
|
if (value.CompareTo(min) < 0) |
|
|
|
{ |
|
|
|
throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min}."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies, that the method parameter with specified target value is true
|
|
|
|
/// and throws an exception if it is found to be so.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="target">
|
|
|
|
/// The target value, which cannot be false.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="parameterName">
|
|
|
|
/// The name of the parameter that is to be checked.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="message">
|
|
|
|
/// The error message, if any to add to the exception.
|
|
|
|
/// </param>
|
|
|
|
/// <exception cref="ArgumentException">
|
|
|
|
/// <paramref name="target"/> is false
|
|
|
|
/// </exception>
|
|
|
|
[Conditional("DEBUG")] |
|
|
|
public static void IsTrue(bool target, string parameterName, string message) |
|
|
|
{ |
|
|
|
if (!target) |
|
|
|
{ |
|
|
|
throw new ArgumentException(message, parameterName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies, that the method parameter with specified target value is false
|
|
|
|
/// and throws an exception if it is found to be so.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="target">The target value, which cannot be true.</param>
|
|
|
|
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
|
|
|
|
/// <param name="message">The error message, if any to add to the exception.</param>
|
|
|
|
/// <exception cref="ArgumentException">
|
|
|
|
/// <paramref name="target"/> is true
|
|
|
|
/// </exception>
|
|
|
|
[Conditional("DEBUG")] |
|
|
|
public static void IsFalse(bool target, string parameterName, string message) |
|
|
|
{ |
|
|
|
if (target) |
|
|
|
{ |
|
|
|
throw new ArgumentException(message, parameterName); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |