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
collectionIEnumerable<T>Collection to test
predicateFunc<T, bool>Predicate where one value in the collection must satisfy
messagestringMessage of the exception if value not found
Type Parameters
TCollection 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
leftTFirst Value to Compare
rightTSecond Value to Compare
messagestringMessage of the exception when values equal
Type Parameters
TType of objects to compare for equality
Remarks
Null values will cause an exception to be thrown
Exceptions
- Exception
Exception is thrown when
leftnot 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
collectionIEnumerable<T>Collection to test
predicateFunc<T, bool>Predicate that ALL values in the collection must satisfy
messagestringMessage of the exception if not all values are valid
Type Parameters
TCollection 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
conditionis 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
leftTFirst Value to Compare
rightTSecond Value to Compare
messagestringMessage of the exception when values equal
Type Parameters
TType of objects to compare for equality
Remarks
Null values will cause an exception to be thrown
Exceptions
- Exception
Thrown when
leftequal toright
NotNull(object?, string)
Ensures given object is not null
public static void NotNull(object? value, string message = "")
Parameters
valueobjectValue of the object to test for null reference
messagestringMessage for the Null Reference Exception
Exceptions
- NullReferenceException
Thrown when
valueis 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
valuestringString value to compare
messagestringMessage 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
TExceptionType of exception to throw
Remarks
TException must have a constructor that takes a single string
Exceptions
- Exception
Thrown when
conditionis true
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
TExceptionType of exception to throw
Remarks
TException must have a constructor that takes a single string
Exceptions
- Exception
Thrown when
conditionis false