Class Ensure
- Namespace
- Dynamicweb.Core
- Assembly
- Dynamicweb.Core.dll
Helper class that will throw exceptions when conditions are not satisfied.
public static class Ensure
- 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
string- Message 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
public static void Equal<T>(T left, T right, string message = "Values must be equal")
Parameters
left
T- First Value to Compare
right
T- Second Value to Compare
message
string- Message 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
string- Message 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
public static void Not(bool condition, string message = "")
Parameters
Exceptions
- Exception
- Thrown when
condition
is true
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
NotEqual<T>(T, T, string)
Ensures given objects are not equal
public static void NotEqual<T>(T left, T right, string message = "Values must not be equal")
Parameters
left
T- First Value to Compare
right
T- Second Value to Compare
message
string- Message 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
public static void NotNull(object value, string message = "")
Parameters
value
object- Value of the object to test for null reference
message
string- Message for the Null Reference Exception
Exceptions
- NullReferenceException
- Thrown when
value
is null
NotNullOrEmpty(string, string)
Ensures given string is not null or empty
public static void NotNullOrEmpty(string value, string message = "String cannot be null or empty")
Parameters
value
string- String value to compare
message
string- Message of the exception if value is null or empty
Exceptions
- Exception
- string value is null or empty
That(bool, string)
Ensures that the given expression is true
public static void That(bool condition, string message = "")
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