Class Ensure
- Namespace
- Dynamicweb.Core
- Assembly
- Dynamicweb.Core.dll
Helper class that will throw exceptions when conditions are not satisfied.
- Inheritance
-
Ensure
- Inherited Members
Methods
Contains<T>(IEnumerable<T>, Func<T, bool>, string)
Ensures given collection contains a value that satisfied a predicate
public static void Contains<T>(IEnumerable<T> collection, Func<T, bool> predicate, string message = "")
Parameters
collection
IEnumerable<T>Collection to test
predicate
Func<T, bool>Predicate where one value in the collection must satisfy
message
stringMessage of the exception if value not found
Type Parameters
T
Collection type
Exceptions
- Exception
Thrown if collection is null, empty or doesn't contain a value that satisfies
predicate
Equal<T>(T, T, string)
Ensures given objects are equal
Parameters
left
TFirst Value to Compare
right
TSecond Value to Compare
message
stringMessage of the exception when values equal
Type Parameters
T
Type of objects to compare for equality
Remarks
Null values will cause an exception to be thrown
Exceptions
- Exception
Exception is thrown when
left
not equal toright
Items<T>(IEnumerable<T>, Func<T, bool>, string)
Ensures ALL items in the given collection satisfy a predicate
public static void Items<T>(IEnumerable<T> collection, Func<T, bool> predicate, string message = "")
Parameters
collection
IEnumerable<T>Collection to test
predicate
Func<T, bool>Predicate that ALL values in the collection must satisfy
message
stringMessage of the exception if not all values are valid
Type Parameters
T
Collection type
Exceptions
- Exception
Thrown if collection is null, empty or not all values satisfies
predicate
Not(bool, string)
Ensures given condition is false
Parameters
Exceptions
- Exception
Thrown when
condition
is true
NotEqual<T>(T, T, string)
Ensures given objects are not equal
Parameters
left
TFirst Value to Compare
right
TSecond Value to Compare
message
stringMessage of the exception when values equal
Type Parameters
T
Type of objects to compare for equality
Remarks
Null values will cause an exception to be thrown
Exceptions
- Exception
Thrown when
left
equal toright
NotNull(object?, string)
Ensures given object is not null
Parameters
value
objectValue of the object to test for null reference
message
stringMessage for the Null Reference Exception
Exceptions
- Null
Reference Exception Thrown when
value
is null
NotNullOrEmpty(string?, string)
Ensures given string is not null or empty
Parameters
value
stringString value to compare
message
stringMessage of the exception if value is null or empty
Exceptions
- Exception
string value is null or empty
Not<TException>(bool, string)
Ensures given condition is false
public static void Not<TException>(bool condition, string message = "") where TException : Exception
Parameters
Type Parameters
TException
Type of exception to throw
Remarks
TException must have a constructor that takes a single string
Exceptions
- Exception
Thrown when
condition
is true
That(bool, string)
Ensures that the given expression is true
Parameters
Exceptions
That<TException>(bool, string)
Ensures that the given expression is true
public static void That<TException>(bool condition, string message = "") where TException : Exception
Parameters
Type Parameters
TException
Type of exception to throw
Remarks
TException must have a constructor that takes a single string
Exceptions
- Exception
Thrown when
condition
is false