Class Ensure
Represents methods that can be used to ensure that parameter values meet expected conditions.
public static class Ensure
- Inheritance
-
Ensure
- Inherited Members
Methods
HasValue<T>(T?, string)
Ensures that the value of a parameter is not null.
public static T? HasValue<T>(T? value, string paramName) where T : struct
Parameters
value
T?The value of the parameter.
paramName
stringThe name of the parameter.
Returns
- T?
The value of the parameter.
Type Parameters
T
Type type of the value.
IsBetween<T>(T, T, T, string)
Ensures that the value of a parameter is between a minimum and a maximum value.
public static T IsBetween<T>(T value, T min, T max, string paramName) where T : IComparable<T>
Parameters
value
TThe value of the parameter.
min
TThe minimum value.
max
TThe maximum value.
paramName
stringThe name of the parameter.
Returns
- T
The value of the parameter.
Type Parameters
T
Type type of the value.
IsEqualTo<T>(T, T, string)
Ensures that the value of a parameter is equal to a comparand.
public static T IsEqualTo<T>(T value, T comparand, string paramName)
Parameters
value
TThe value of the parameter.
comparand
TThe comparand.
paramName
stringThe name of the parameter.
Returns
- T
The value of the parameter.
Type Parameters
T
Type type of the value.
IsGreaterThanOrEqualToZero(int, string)
Ensures that the value of a parameter is greater than or equal to zero.
public static int IsGreaterThanOrEqualToZero(int value, string paramName)
Parameters
Returns
- int
The value of the parameter.
IsGreaterThanOrEqualToZero(long, string)
Ensures that the value of a parameter is greater than or equal to zero.
public static long IsGreaterThanOrEqualToZero(long value, string paramName)
Parameters
Returns
- long
The value of the parameter.
IsGreaterThanOrEqualToZero(TimeSpan, string)
Ensures that the value of a parameter is greater than or equal to zero.
public static TimeSpan IsGreaterThanOrEqualToZero(TimeSpan value, string paramName)
Parameters
Returns
- TimeSpan
The value of the parameter.
IsGreaterThanOrEqualTo<T>(T, T, string)
Ensures that the value of a parameter is greater than or equal to a comparand.
public static T IsGreaterThanOrEqualTo<T>(T value, T comparand, string paramName) where T : IComparable<T>
Parameters
value
TThe value of the parameter.
comparand
TThe comparand.
paramName
stringThe name of the parameter.
Returns
- T
The value of the parameter.
Type Parameters
T
Type type of the value.
IsGreaterThanZero(double, string)
Ensures that the value of a parameter is greater than zero.
public static double IsGreaterThanZero(double value, string paramName)
Parameters
Returns
- double
The value of the parameter.
IsGreaterThanZero(int, string)
Ensures that the value of a parameter is greater than zero.
public static int IsGreaterThanZero(int value, string paramName)
Parameters
Returns
- int
The value of the parameter.
IsGreaterThanZero(long, string)
Ensures that the value of a parameter is greater than zero.
public static long IsGreaterThanZero(long value, string paramName)
Parameters
Returns
- long
The value of the parameter.
IsGreaterThanZero(TimeSpan, string)
Ensures that the value of a parameter is greater than zero.
public static TimeSpan IsGreaterThanZero(TimeSpan value, string paramName)
Parameters
Returns
- TimeSpan
The value of the parameter.
IsGreaterThan<T>(T, T, string)
Ensures that the value of a parameter is greater than a comparand.
public static T IsGreaterThan<T>(T value, T comparand, string paramName) where T : IComparable<T>
Parameters
value
TThe value of the parameter.
comparand
TThe comparand.
paramName
stringThe name of the parameter.
Returns
- T
The value of the parameter.
Type Parameters
T
Type type of the value.
IsInfiniteOrGreaterThanOrEqualToZero(TimeSpan, string)
Ensures that the value of a parameter is infinite or greater than or equal to zero.
public static TimeSpan IsInfiniteOrGreaterThanOrEqualToZero(TimeSpan value, string paramName)
Parameters
Returns
- TimeSpan
The value of the parameter.
IsInfiniteOrGreaterThanZero(TimeSpan, string)
Ensures that the value of a parameter is infinite or greater than zero.
public static TimeSpan IsInfiniteOrGreaterThanZero(TimeSpan value, string paramName)
Parameters
Returns
- TimeSpan
The value of the parameter.
IsNotNullAndDoesNotContainAnyNulls<T>(IEnumerable<T>, string)
Ensures that the value of a parameter is not null and does not contain any nulls.
public static IEnumerable<T> IsNotNullAndDoesNotContainAnyNulls<T>(IEnumerable<T> values, string paramName) where T : class
Parameters
values
IEnumerable<T>The value of the parameter.
paramName
stringThe name of the parameter.
Returns
- IEnumerable<T>
The value of the parameter.
Type Parameters
T
Type of the value.
IsNotNullOrEmpty(string, string)
Ensures that the value of a parameter is not null or empty.
public static string IsNotNullOrEmpty(string value, string paramName)
Parameters
Returns
- string
The value of the parameter.
IsNotNullOrEmpty<T>(IEnumerable<T>, string)
Ensures that the value of a parameter is not null or empty.
public static IEnumerable<T> IsNotNullOrEmpty<T>(IEnumerable<T> value, string paramName)
Parameters
value
IEnumerable<T>The value of the parameter.
paramName
stringThe name of the parameter.
Returns
- IEnumerable<T>
The value of the parameter.
Type Parameters
T
The type of the elements.
IsNotNull<T>(T, string)
Ensures that the value of a parameter is not null.
public static T IsNotNull<T>(T value, string paramName) where T : class
Parameters
value
TThe value of the parameter.
paramName
stringThe name of the parameter.
Returns
- T
The value of the parameter.
Type Parameters
T
Type type of the value.
IsNullOrBetween<T>(T?, T, T, string)
Ensures that the value of a parameter is null or is between a minimum and a maximum value.
public static T? IsNullOrBetween<T>(T? value, T min, T max, string paramName) where T : struct, IComparable<T>
Parameters
value
T?The value of the parameter.
min
TThe minimum value.
max
TThe maximum value.
paramName
stringThe name of the parameter.
Returns
- T?
The value of the parameter.
Type Parameters
T
Type type of the value.
IsNullOrGreaterThanOrEqualToZero(int?, string)
Ensures that the value of a parameter is null or greater than or equal to zero.
public static int? IsNullOrGreaterThanOrEqualToZero(int? value, string paramName)
Parameters
Returns
- int?
The value of the parameter.
IsNullOrGreaterThanOrEqualToZero(long?, string)
Ensures that the value of a parameter is null or greater than or equal to zero.
public static long? IsNullOrGreaterThanOrEqualToZero(long? value, string paramName)
Parameters
Returns
- long?
The value of the parameter.
IsNullOrGreaterThanZero(int?, string)
Ensures that the value of a parameter is null or greater than zero.
public static int? IsNullOrGreaterThanZero(int? value, string paramName)
Parameters
Returns
- int?
The value of the parameter.
IsNullOrGreaterThanZero(long?, string)
Ensures that the value of a parameter is null or greater than zero.
public static long? IsNullOrGreaterThanZero(long? value, string paramName)
Parameters
Returns
- long?
The value of the parameter.
IsNullOrGreaterThanZero(TimeSpan?, string)
Ensures that the value of a parameter is null or greater than zero.
public static TimeSpan? IsNullOrGreaterThanZero(TimeSpan? value, string paramName)
Parameters
Returns
- TimeSpan?
The value of the parameter.
IsNullOrInfiniteOrGreaterThanOrEqualToZero(TimeSpan?, string)
Ensures that the value of a parameter is null, or infinite, or greater than or equal to zero.
public static TimeSpan? IsNullOrInfiniteOrGreaterThanOrEqualToZero(TimeSpan? value, string paramName)
Parameters
Returns
- TimeSpan?
The value of the parameter.
IsNullOrNotEmpty(string, string)
Ensures that the value of a parameter is null or not empty.
public static string IsNullOrNotEmpty(string value, string paramName)
Parameters
Returns
- string
The value of the parameter.
IsNullOrValidTimeout(TimeSpan?, string)
Ensures that the value of a parameter is null or a valid timeout.
public static TimeSpan? IsNullOrValidTimeout(TimeSpan? value, string paramName)
Parameters
Returns
- TimeSpan?
The value of the parameter.
IsNull<T>(T, string)
Ensures that the value of a parameter is null.
public static T IsNull<T>(T value, string paramName) where T : class
Parameters
value
TThe value of the parameter.
paramName
stringThe name of the parameter.
Returns
- T
The value of the parameter.
Type Parameters
T
Type type of the value.
IsValidTimeout(TimeSpan, string)
Ensures that the value of a parameter is a valid timeout.
public static TimeSpan IsValidTimeout(TimeSpan value, string paramName)
Parameters
Returns
- TimeSpan
The value of the parameter.
That(bool, string)
Ensures that an assertion is true.
public static void That(bool assertion, string message)
Parameters
assertion
boolThe assertion.
message
stringThe message to use with the exception that is thrown if the assertion is false.
That(bool, string, string)
Ensures that an assertion is true.
public static void That(bool assertion, string message, string paramName)
Parameters
assertion
boolThe assertion.
message
stringThe message to use with the exception that is thrown if the assertion is false.
paramName
stringThe parameter name.
That<T>(T, Func<T, bool>, string, string)
Ensures that the value of a parameter meets an assertion.
public static T That<T>(T value, Func<T, bool> assertion, string paramName, string message)
Parameters
value
TThe value of the parameter.
assertion
Func<T, bool>The assertion.
paramName
stringThe name of the parameter.
message
stringThe message to use with the exception that is thrown if the assertion is false.
Returns
- T
The value of the parameter.
Type Parameters
T
Type type of the value.