Class Validator
Provides a generic way to validate different types of arguments passed to members.
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public sealed class Validator
Properties
| Improve this Doc View SourceThrowIf
Gets the singleton instance of the Validator functionality allowing for extensions methods like: Validator.ThrowIf.InvalidJsonDocument()
.
Declaration
public static Validator ThrowIf { get; }
Property Value
Type | Description |
---|---|
Validator | The singleton instance of the Validator functionality. |
Methods
| Improve this Doc View SourceCheckParameter<T>(T, Action)
Provides a convenient way to validate a parameter while returning the specified value
unaltered.
Declaration
public static T CheckParameter<T>(T value, Action validator)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be evaluated. |
Action | validator | The delegate that must throw an Exception if the specified |
Returns
Type | Description |
---|---|
T | The specified |
Type Parameters
Name | Description |
---|---|
T | The type of the object to evaluate. |
ThrowIfContainsInterface(Type, String, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsInterface(Type value, string paramName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Type | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments (that must be an interface) to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ArgumentException |
|
ThrowIfContainsInterface(Type, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsInterface(Type value, string paramName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Type | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Type[] | types | A variable number of Type arguments (that must be an interface) to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ArgumentException |
|
ThrowIfContainsInterface<T>(String, String, Type[])
Validates and throws an TypeArgumentOutOfRangeException if the specified T
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsInterface<T>(string typeParamName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments (that must be an interface) to match with the type of |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TypeArgumentOutOfRangeException |
|
ArgumentException |
|
ThrowIfContainsInterface<T>(String, Type[])
Validates and throws an TypeArgumentOutOfRangeException if the specified T
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsInterface<T>(string typeParamName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
Type[] | types | A variable number of Type arguments (that must be an interface) to match with the type of |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TypeArgumentOutOfRangeException |
|
ArgumentException |
|
ThrowIfContainsType(Object, String, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsType(object value, string paramName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Object | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ThrowIfContainsType(Object, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsType(object value, string paramName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Object | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Type[] | types | A variable number of Type arguments to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ThrowIfContainsType(Type, String, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsType(Type value, string paramName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Type | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ThrowIfContainsType(Type, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsType(Type value, string paramName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Type | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Type[] | types | A variable number of Type arguments to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ThrowIfContainsType<T>(String, String, Type[])
Validates and throws an TypeArgumentOutOfRangeException if the specified T
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsType<T>(string typeParamName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments to match with the type of |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TypeArgumentOutOfRangeException |
|
ThrowIfContainsType<T>(String, Type[])
Validates and throws an TypeArgumentOutOfRangeException if the specified T
is contained within at least one of the specified types
.
Declaration
public static void ThrowIfContainsType<T>(string typeParamName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
Type[] | types | A variable number of Type arguments to match with the type of |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TypeArgumentOutOfRangeException |
|
ThrowIfEmailAddress(String, String, String)
Validates and throws an ArgumentException if the specified value
has the format of an email address.
Declaration
public static void ThrowIfEmailAddress(string value, string paramName, string message = "Value cannot be an email address.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfEmpty(String, String, String)
Validates and throws an ArgumentException if the specified value
is empty.
Declaration
public static void ThrowIfEmpty(string value, string paramName, string message = "Value cannot be empty.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfEnum<TEnum>(String, Boolean, String, String)
Validates and throws an ArgumentException if the specified value
represents an enumeration.
Declaration
public static void ThrowIfEnum<TEnum>(string value, bool ignoreCase, string paramName, string message = "Value represents an enumeration.")
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
Boolean | ignoreCase |
|
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfEnum<TEnum>(String, String)
Validates and throws an ArgumentException if the specified value
represents an enumeration.
Declaration
public static void ThrowIfEnum<TEnum>(string value, string paramName)
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfEnumType(Type, String, String)
Validates and throws an ArgumentException if the specified value
represents an enumeration.
Declaration
public static void ThrowIfEnumType(Type value, string paramName, string message = "Value represents an enumeration.")
Parameters
Type | Name | Description |
---|---|---|
Type | value | The type to check is an enumeration. |
String | paramName | The name of the type parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfEnumType<TEnum>(String, String)
Validates and throws an TypeArgumentException if the specified TEnum
represents an enumeration.
Declaration
public static void ThrowIfEnumType<TEnum>(string typeParamName, string message = "Value represents an enumeration.")
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
TEnum | The type to check is an enumeration. |
Exceptions
Type | Condition |
---|---|
TypeArgumentException |
|
ThrowIfEqual<T>(T, T, IEqualityComparer<T>, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are equal to the y
object.
Declaration
public static void ThrowIfEqual<T>(T x, T y, IEqualityComparer<T> comparer, string paramName)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
IEqualityComparer<T> | comparer | The IEqualityComparer<T> implementation to use when comparing |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfEqual<T>(T, T, IEqualityComparer<T>, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are equal to the y
object.
Declaration
public static void ThrowIfEqual<T>(T x, T y, IEqualityComparer<T> comparer, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
IEqualityComparer<T> | comparer | The IEqualityComparer<T> implementation to use when comparing |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfEqual<T>(T, T, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are equal to the y
object.
Declaration
public static void ThrowIfEqual<T>(T x, T y, string paramName)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfEqual<T>(T, T, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are equal to the y
object.
Declaration
public static void ThrowIfEqual<T>(T x, T y, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfFalse(Boolean, String, String)
Validates and throws an ArgumentException if the specified value
is false
.
Declaration
public static void ThrowIfFalse(bool value, string paramName, string message = "Value must be true.")
Parameters
Type | Name | Description |
---|---|---|
Boolean | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfFalse(Func<Boolean>, String, String)
Validates and throws an ArgumentException if the specified predicate
returns false
.
Declaration
public static void ThrowIfFalse(Func<bool> predicate, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
Func<Boolean> | predicate | The function delegate that determines if an ArgumentException is thrown. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfGreaterThan<T>(T, T, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
is greater than y
.
Declaration
public static void ThrowIfGreaterThan<T>(T x, T y, string paramName)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfGreaterThan<T>(T, T, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
is greater than y
.
Declaration
public static void ThrowIfGreaterThan<T>(T x, T y, string paramName, string message)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfGreaterThanOrEqual<T>(T, T, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
is greater than or equal to y
.
Declaration
public static void ThrowIfGreaterThanOrEqual<T>(T x, T y, string paramName)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfGreaterThanOrEqual<T>(T, T, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
is greater than or equal to y
.
Declaration
public static void ThrowIfGreaterThanOrEqual<T>(T x, T y, string paramName, string message)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfGuid(String, GuidFormats, String, String)
Validates and throws an ArgumentException if the specified value
has the format of a Guid.
Declaration
public static void ThrowIfGuid(string value, GuidFormats format, string paramName, string message = "Value cannot be a Guid.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
GuidFormats | format | A bitmask comprised of one or more GuidFormats that specify how the GUID parsing is conducted. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfGuid(String, String)
Validates and throws an ArgumentException if the specified value
has the format of a Guid.
Declaration
public static void ThrowIfGuid(string value, string paramName)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Remarks
This implementation only evaluates for GUID formats of: D | B | P, eg. 32 digits separated by hyphens; 32 digits separated by hyphens, enclosed in brackets and 32 digits separated by hyphens, enclosed in parentheses.
The reason not to include N, eg. 32 digits is the possible unintended GUID result of a MD5 string representation.
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfHex(String, String, String)
Validates and throws an ArgumentException if the specified value
is hexadecimal.
Declaration
public static void ThrowIfHex(string value, string paramName, string message = "Specified argument cannot be hexadecimal.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfInvalidConfigurator<TOptions>(Action<TOptions>, String, out TOptions)
Validates and throws an ArgumentException if the specified setup
results in an instance of invalid options
.
Declaration
public static void ThrowIfInvalidConfigurator<TOptions>(Action<TOptions> setup, string paramName, out TOptions options)
where TOptions : class, IValidatableParameterObject, new()
Parameters
Type | Name | Description |
---|---|---|
Action<TOptions> | setup | The delegate that will configure the public read-write properties of |
String | paramName | The name of the parameter that caused the exception. |
TOptions | options | The default parameter-less constructed instance of |
Type Parameters
Name | Description |
---|---|
TOptions | The type of the object implementing the IValidatableParameterObject interface. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfInvalidConfigurator<TOptions>(Action<TOptions>, String, String, out TOptions)
Validates and throws an ArgumentException if the specified setup
results in an instance of invalid options
.
Declaration
public static void ThrowIfInvalidConfigurator<TOptions>(Action<TOptions> setup, string paramName, string message, out TOptions options)
where TOptions : class, IValidatableParameterObject, new()
Parameters
Type | Name | Description |
---|---|---|
Action<TOptions> | setup | The delegate that will configure the public read-write properties of |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
TOptions | options | The default parameter-less constructed instance of |
Type Parameters
Name | Description |
---|---|
TOptions | The type of the object implementing the IValidatableParameterObject interface. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfInvalidOptions<TOptions>(TOptions, String, String)
Validates and throws an ArgumentException if the specified options
are not in a valid state.
Declaration
public static void ThrowIfInvalidOptions<TOptions>(TOptions options, string paramName, string message = "{0} are not in a valid state.")
where TOptions : class, IValidatableParameterObject, new()
Parameters
Type | Name | Description |
---|---|---|
TOptions | options | The configured options to validate. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
TOptions | The type of the object implementing the IValidatableParameterObject interface. |
Remarks
message
will have the name of the TOptions
if possible; otherwise Options.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
ThrowIfLowerThan<T>(T, T, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
is lower than y
.
Declaration
public static void ThrowIfLowerThan<T>(T x, T y, string paramName)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfLowerThan<T>(T, T, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
is lower than y
.
Declaration
public static void ThrowIfLowerThan<T>(T x, T y, string paramName, string message)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfLowerThanOrEqual<T>(T, T, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
is lower than or equal to y
.
Declaration
public static void ThrowIfLowerThanOrEqual<T>(T x, T y, string paramName)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfLowerThanOrEqual<T>(T, T, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
is lower than or equal to y
.
Declaration
public static void ThrowIfLowerThanOrEqual<T>(T x, T y, string paramName, string message)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfNotBase64String(String, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified value
consist of anything besides a base-64 structure.
Declaration
public static void ThrowIfNotBase64String(string value, string paramName, string message = "Value must consist only of base-64 digits.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfNotBinaryDigits(String, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified value
consist of anything besides binary digits.
Declaration
public static void ThrowIfNotBinaryDigits(string value, string paramName, string message = "Value must consist only of binary digits.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfNotContainsInterface(Type, String, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsInterface(Type value, string paramName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Type | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments (that must be an interface) to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ArgumentException |
|
ThrowIfNotContainsInterface(Type, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsInterface(Type value, string paramName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Type | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Type[] | types | A variable number of Type arguments (that must be an interface) to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ArgumentException |
|
ThrowIfNotContainsInterface<T>(String, String, Type[])
Validates and throws an TypeArgumentOutOfRangeException if the specified T
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsInterface<T>(string typeParamName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments (that must be an interface) to match with the type of |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TypeArgumentOutOfRangeException |
|
ArgumentException |
|
ThrowIfNotContainsInterface<T>(String, Type[])
Validates and throws an TypeArgumentOutOfRangeException if the specified T
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsInterface<T>(string typeParamName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
Type[] | types | A variable number of Type arguments (that must be an interface) to match with the type of |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TypeArgumentOutOfRangeException |
|
ArgumentException |
|
ThrowIfNotContainsType(Object, String, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsType(object value, string paramName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Object | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ThrowIfNotContainsType(Object, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsType(object value, string paramName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Object | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Type[] | types | A variable number of Type arguments to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ThrowIfNotContainsType(Type, String, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsType(Type value, string paramName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Type | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ThrowIfNotContainsType(Type, String, Type[])
Validates and throws an ArgumentOutOfRangeException if the specified value
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsType(Type value, string paramName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
Type | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Type[] | types | A variable number of Type arguments to match with the type of |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
ThrowIfNotContainsType<T>(String, String, Type[])
Validates and throws an TypeArgumentOutOfRangeException if the specified T
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsType<T>(string typeParamName, string message, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
String | message | A message that describes the error. |
Type[] | types | A variable number of Type arguments to match with the type of |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TypeArgumentOutOfRangeException |
|
ThrowIfNotContainsType<T>(String, Type[])
Validates and throws an TypeArgumentOutOfRangeException if the specified T
is not contained within at least one of the specified types
.
Declaration
public static void ThrowIfNotContainsType<T>(string typeParamName, params Type[] types)
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
Type[] | types | A variable number of Type arguments to match with the type of |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TypeArgumentOutOfRangeException |
|
ThrowIfNotEmailAddress(String, String, String)
Validates and throws an ArgumentException if the specified value
does not have the format of an email address.
Declaration
public static void ThrowIfNotEmailAddress(string value, string paramName, string message = "Value must be an email address.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotEnum<TEnum>(String, Boolean, String, String)
Validates and throws an ArgumentException if the specified value
does not represents an enumeration.
Declaration
public static void ThrowIfNotEnum<TEnum>(string value, bool ignoreCase, string paramName, string message = "Value does not represents an enumeration.")
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
Boolean | ignoreCase |
|
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotEnum<TEnum>(String, String)
Validates and throws an ArgumentException if the specified value
does not represents an enumeration.
Declaration
public static void ThrowIfNotEnum<TEnum>(string value, string paramName)
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotEnumType(Type, String, String)
Validates and throws an ArgumentException if the specified value
does not represents an enumeration.
Declaration
public static void ThrowIfNotEnumType(Type value, string paramName, string message = "Value does not represents an enumeration.")
Parameters
Type | Name | Description |
---|---|---|
Type | value | The type to check is not an enumeration. |
String | paramName | The name of the type parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotEnumType<TEnum>(String, String)
Validates and throws an TypeArgumentException if the specified TEnum
does not represents an enumeration.
Declaration
public static void ThrowIfNotEnumType<TEnum>(string typeParamName, string message = "Value does not represents an enumeration.")
Parameters
Type | Name | Description |
---|---|---|
String | typeParamName | The name of the type parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
TEnum | The type to check is not an enumeration. |
Exceptions
Type | Condition |
---|---|
TypeArgumentException |
|
ThrowIfNotEqual<T>(T, T, IEqualityComparer<T>, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are not equal to the y
object.
Declaration
public static void ThrowIfNotEqual<T>(T x, T y, IEqualityComparer<T> comparer, string paramName)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
IEqualityComparer<T> | comparer | The IEqualityComparer<T> implementation to use when comparing |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfNotEqual<T>(T, T, IEqualityComparer<T>, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are not equal to the y
object.
Declaration
public static void ThrowIfNotEqual<T>(T x, T y, IEqualityComparer<T> comparer, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
IEqualityComparer<T> | comparer | The IEqualityComparer<T> implementation to use when comparing |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfNotEqual<T>(T, T, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are not equal to the y
object.
Declaration
public static void ThrowIfNotEqual<T>(T x, T y, string paramName)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfNotEqual<T>(T, T, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are not equal to the y
object.
Declaration
public static void ThrowIfNotEqual<T>(T x, T y, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfNotGuid(String, GuidFormats, String, String)
Validates and throws an ArgumentException if the specified value
does not have the format of a Guid.
Declaration
public static void ThrowIfNotGuid(string value, GuidFormats format, string paramName, string message = "Value must be a Guid.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
GuidFormats | format | A bitmask comprised of one or more GuidFormats that specify how the GUID parsing is conducted. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotGuid(String, String)
Validates and throws an ArgumentException if the specified value
does not have the format of a Guid.
Declaration
public static void ThrowIfNotGuid(string value, string paramName)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Remarks
This implementation only evaluates for GUID formats of: D | B | P, eg. 32 digits separated by hyphens; 32 digits separated by hyphens, enclosed in brackets and 32 digits separated by hyphens, enclosed in parentheses.
The reason not to include N, eg. 32 digits is the possible unintended GUID result of a MD5 string representation.
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotHex(String, String, String)
Validates and throws an ArgumentException if the specified value
is not hexadecimal.
Declaration
public static void ThrowIfNotHex(string value, string paramName, string message = "Value must be hexadecimal.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotNumber(String, String, NumberStyles)
Validates and throws an ArgumentException if the specified value
is not a number.
Declaration
public static void ThrowIfNotNumber(string value, string paramName, NumberStyles styles = NumberStyles.Number)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
NumberStyles | styles | A bitwise combination of NumberStyles values that indicates the permitted format of |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotNumber(String, String, NumberStyles, IFormatProvider)
Validates and throws an ArgumentException if the specified value
is not a number.
Declaration
public static void ThrowIfNotNumber(string value, string paramName, NumberStyles styles, IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
NumberStyles | styles | A bitwise combination of NumberStyles values that indicates the permitted format of |
IFormatProvider | provider | An IFormatProvider that supplies culture-specific formatting information about |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotNumber(String, String, String, NumberStyles)
Validates and throws an ArgumentException if the specified value
is not a number.
Declaration
public static void ThrowIfNotNumber(string value, string paramName, string message, NumberStyles styles = NumberStyles.Number)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
NumberStyles | styles | A bitwise combination of NumberStyles values that indicates the permitted format of |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotNumber(String, String, String, NumberStyles, IFormatProvider)
Validates and throws an ArgumentException if the specified value
is not a number.
Declaration
public static void ThrowIfNotNumber(string value, string paramName, string message, NumberStyles styles, IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
NumberStyles | styles | A bitwise combination of NumberStyles values that indicates the permitted format of |
IFormatProvider | provider | An IFormatProvider that supplies culture-specific formatting information about |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotSame<T>(T, T, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are not of the same instance as the y
object.
Declaration
public static void ThrowIfNotSame<T>(T x, T y, string paramName)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfNotSame<T>(T, T, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are not of the same instance as the y
object.
Declaration
public static void ThrowIfNotSame<T>(T x, T y, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfNotUri(String, String)
Validates and throws an ArgumentException if the specified value
does not have the format of a Uri.
Declaration
public static void ThrowIfNotUri(string value, string paramName)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNotUri(String, UriKind, String, String)
Validates and throws an ArgumentException if the specified value
does not have the format of a Uri.
Declaration
public static void ThrowIfNotUri(string value, UriKind uriKind, string paramName, string message = "Value must be a URI.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
UriKind | uriKind | The type of the URI. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNull(Object, String, String)
Validates and throws an ArgumentNullException if the specified value
is null.
Declaration
public static void ThrowIfNull(object value, string paramName = null, string message = "Value cannot be null.")
Parameters
Type | Name | Description |
---|---|---|
Object | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ThrowIfNull<T>(IDecorator<T>, String, out T)
Validates and throws an ArgumentNullException if the specified decorator
is null.
Declaration
public static void ThrowIfNull<T>(IDecorator<T> decorator, string paramName, out T inner)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<T> | decorator | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
T | inner | The inner object of |
Type Parameters
Name | Description |
---|---|
T | The type of the inner object denoted by |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ThrowIfNull<T>(IDecorator<T>, String, String, out T)
Validates and throws an ArgumentNullException if the specified decorator
is null.
Declaration
public static void ThrowIfNull<T>(IDecorator<T> decorator, string paramName, string message, out T inner)
Parameters
Type | Name | Description |
---|---|---|
IDecorator<T> | decorator | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
T | inner | The inner object of |
Type Parameters
Name | Description |
---|---|
T | The type of the inner object denoted by |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ThrowIfNullOrEmpty(String, String)
Validates and throws either an ArgumentNullException or ArgumentException if the specified value
is respectively null or empty.
Declaration
public static void ThrowIfNullOrEmpty(string value, string paramName = null)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
ThrowIfNullOrEmpty(String, String, String)
Validates and throws either an ArgumentNullException or ArgumentException if the specified value
is respectively null or empty.
Declaration
public static void ThrowIfNullOrEmpty(string value, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
ThrowIfNullOrWhitespace(String, String)
Validates and throws either an ArgumentNullException or ArgumentException if the specified value
is respectively null, empty or consist only of white-space characters.
Declaration
public static void ThrowIfNullOrWhitespace(string value, string paramName = null)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
ThrowIfNullOrWhitespace(String, String, String)
Validates and throws either an ArgumentNullException or ArgumentException if the specified value
is respectively null, empty or consist only of white-space characters.
Declaration
public static void ThrowIfNullOrWhitespace(string value, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
ThrowIfNumber(String, String, NumberStyles)
Validates and throws an ArgumentException if the specified value
is a number.
Declaration
public static void ThrowIfNumber(string value, string paramName, NumberStyles styles = NumberStyles.Number)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
NumberStyles | styles | A bitwise combination of NumberStyles values that indicates the permitted format of |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNumber(String, String, NumberStyles, IFormatProvider)
Validates and throws an ArgumentException if the specified value
is a number.
Declaration
public static void ThrowIfNumber(string value, string paramName, NumberStyles styles, IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
NumberStyles | styles | A bitwise combination of NumberStyles values that indicates the permitted format of |
IFormatProvider | provider | An IFormatProvider that supplies culture-specific formatting information about |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNumber(String, String, String, NumberStyles)
Validates and throws an ArgumentException if the specified value
is a number.
Declaration
public static void ThrowIfNumber(string value, string paramName, string message, NumberStyles styles = NumberStyles.Number)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
NumberStyles | styles | A bitwise combination of NumberStyles values that indicates the permitted format of |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfNumber(String, String, String, NumberStyles, IFormatProvider)
Validates and throws an ArgumentException if the specified value
is a number.
Declaration
public static void ThrowIfNumber(string value, string paramName, string message, NumberStyles styles, IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
NumberStyles | styles | A bitwise combination of NumberStyles values that indicates the permitted format of |
IFormatProvider | provider | An IFormatProvider that supplies culture-specific formatting information about |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfObjectInDistress(Boolean, String, String)
Validates and throws an InvalidOperationException if the specified predicate
is true
.
Declaration
public static void ThrowIfObjectInDistress(bool predicate, string message = "Operation is not valid due to the current state of the object.", string expression = null)
Parameters
Type | Name | Description |
---|---|---|
Boolean | predicate | The value that determines if an InvalidOperationException is thrown. |
String | message | A message that describes the error. |
String | expression | The |
Exceptions
Type | Condition |
---|---|
InvalidOperationException |
|
ThrowIfObjectInDistress(Func<Boolean>, String, String)
Validates and throws an InvalidOperationException if the specified predicate
returns true
.
Declaration
public static void ThrowIfObjectInDistress(Func<bool> predicate, string message = "Operation is not valid due to the current state of the object.", string expression = null)
Parameters
Type | Name | Description |
---|---|---|
Func<Boolean> | predicate | The function delegate that determines if an InvalidOperationException is thrown. |
String | message | A message that describes the error. |
String | expression | The |
Exceptions
Type | Condition |
---|---|
InvalidOperationException |
|
ThrowIfSame<T>(T, T, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are of the same instance as the y
object.
Declaration
public static void ThrowIfSame<T>(T x, T y, string paramName)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfSame<T>(T, T, String, String)
Validates and throws an ArgumentOutOfRangeException if the specified x
object are of the same instance as the y
object.
Declaration
public static void ThrowIfSame<T>(T x, T y, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
T | x | The first object to compare. |
T | y | The second object to compare. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T | The type of objects to compare. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
ThrowIfSequenceEmpty<T>(IEnumerable<T>, String, String)
Validates and throws an ArgumentException if the specified value
has no elements.
Declaration
public static void ThrowIfSequenceEmpty<T>(IEnumerable<T> value, string paramName, string message = "Value contains no elements.")
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfSequenceNullOrEmpty<T>(IEnumerable<T>, String, String)
Validates and throws either an ArgumentNullException or ArgumentException if the specified value
is respectively null or has no elements.
Declaration
public static void ThrowIfSequenceNullOrEmpty<T>(IEnumerable<T> value, string paramName, string message = "Value is either null or contains no elements.")
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
ThrowIfTrue(Boolean, String, String)
Validates and throws an ArgumentException if the specified value
is true
.
Declaration
public static void ThrowIfTrue(bool value, string paramName, string message = "Value must be false.")
Parameters
Type | Name | Description |
---|---|---|
Boolean | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfTrue(Func<Boolean>, String, String)
Validates and throws an ArgumentException if the specified predicate
returns true
.
Declaration
public static void ThrowIfTrue(Func<bool> predicate, string paramName, string message)
Parameters
Type | Name | Description |
---|---|---|
Func<Boolean> | predicate | The function delegate that determines if an ArgumentException is thrown. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfUri(String, String)
Validates and throws an ArgumentException if the specified value
has the format of a Uri.
Declaration
public static void ThrowIfUri(string value, string paramName)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfUri(String, UriKind, String, String)
Validates and throws an ArgumentException if the specified value
has the format of a Uri.
Declaration
public static void ThrowIfUri(string value, UriKind uriKind, string paramName, string message = "Value cannot be a URI.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
UriKind | uriKind | The type of the URI. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowIfWhiteSpace(String, String, String)
Validates and throws an ArgumentException if the specified value
consist only of white-space characters.
Declaration
public static void ThrowIfWhiteSpace(string value, string paramName, string message = "Value cannot consist only of white-space characters.")
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to be evaluated. |
String | paramName | The name of the parameter that caused the exception. |
String | message | A message that describes the error. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ThrowWhenCondition(Action<ExceptionCondition<ArgumentException>>)
Validates and throws an ArgumentException (or a derived counterpart) from the specified delegate condition
.
Declaration
public void ThrowWhenCondition(Action<ExceptionCondition<ArgumentException>> condition)
Parameters
Type | Name | Description |
---|---|---|
Action<ExceptionCondition<ArgumentException>> | condition | The delegate that evaluates, creates and ultimately throws an ArgumentException (or a derived counterpart) from within a given scenario. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|