Class Validator
- Namespace
 - Cuemon
 
- Assembly
 - Cuemon.Core.dll
 
Provides a generic way to validate different types of arguments passed to members.
public sealed class Validator
  - Inheritance
 - 
      
      Validator
 
Properties
ThrowIf
Gets the singleton instance of the Validator functionality allowing for extensions methods like: Validator.ThrowIf.InvalidJsonDocument().
public static Validator ThrowIf { get; }
  Property Value
- Validator
 The singleton instance of the Validator functionality.
Methods
CheckParameter<TResult>(Func<TResult>)
Provides a convenient way to verify a desired state from the provided validator while returning a result that reflects this.
public static TResult CheckParameter<TResult>(Func<TResult> validator)
  Parameters
validatorFunc<TResult>The function delegate that must throw an Exception if a desired state for
TResultcannot be achieved.
Returns
- TResult
 The result of function delegate
validator.
Type Parameters
TResultThe type of the object to return.
Remarks
Typically used when nesting calls from a constructor perspective.
Exceptions
- ArgumentException
 validatorcannot be null.
CheckParameter<T>(T, Action)
Provides a convenient way to verify a desired state from the provided validator while returning the specified argument unaltered.
public static T CheckParameter<T>(T argument, Action validator)
  Parameters
argumentTThe value to be evaluated.
validatorActionThe delegate that must throw an Exception if the specified
argumentis not valid.
Returns
- T
 The specified
argumentunaltered.
Type Parameters
TThe type of the object to evaluate.
Remarks
Typically used when nesting calls from a constructor perspective.
Exceptions
- ArgumentException
 validatorcannot be null.
ThrowIfContainsAny(string, char[], StringComparison, string, string)
Validates and throws an ArgumentOutOfRangeException if any of the characters occurs within the argument.
public static void ThrowIfContainsAny(string argument, char[] characters, StringComparison comparison = StringComparison.OrdinalIgnoreCase, string message = "One or more character matches were found.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
characterschar[]The sequence of char to search within
argument.comparisonStringComparisonOne of the enumeration values that specifies the rules to use in the comparison.
messagestringThe message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentOutOfRangeException
 argumentcontains one or more of the specifiedcharacters.
ThrowIfContainsInterface(Type, Type[], string, string)
Validates and throws an ArgumentOutOfRangeException if the specified argument is contained within at least one of the specified types.
public static void ThrowIfContainsInterface(Type argument, Type[] types, string message = "Specified argument is contained within at least one of the specified types.", string paramName = null)
  Parameters
argumentTypeThe value to be evaluated.
typesType[]A Type array that contains zero or more types (that each must be an interface) to match with the type of
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Remarks
Use ToArrayOf<T>(params T[]) to substitute earlier signature of params Type[] types.
Exceptions
- ArgumentNullException
 argumentis null - or -typesis null.- ArgumentOutOfRangeException
 argumentis contained within at least one of the specifiedtypes.- ArgumentException
 typesdoes not satisfy the condition of being an interface.
ThrowIfContainsInterface<T>(string, string, params Type[])
Validates and throws an TypeArgumentOutOfRangeException if the specified T is contained within at least one of the specified types.
public static void ThrowIfContainsInterface<T>(string typeParamName, string message, params Type[] types)
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
messagestringA message that describes the error.
typesType[]A variable number of Type arguments (that must be an interface) to match with the type of
T.
Type Parameters
T
Exceptions
- ArgumentNullException
 typesis null.- TypeArgumentOutOfRangeException
 Tis contained within at least one of the specifiedtypes.- ArgumentException
 typesdoes not satisfy the condition of being an interface.
ThrowIfContainsInterface<T>(string, params Type[])
Validates and throws a TypeArgumentOutOfRangeException if the specified T is contained within at least one of the specified types.
public static void ThrowIfContainsInterface<T>(string typeParamName, params Type[] types)
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
typesType[]A variable number of Type arguments (that must be an interface) to match with the type of
T.
Type Parameters
T
Exceptions
- ArgumentNullException
 typesis null.- TypeArgumentOutOfRangeException
 Tis contained within at least one of the specifiedtypes.- ArgumentException
 typesdoes not satisfy the condition of being an interface.
ThrowIfContainsReservedKeyword(string, IEnumerable<string>, IEqualityComparer<string>, string, string)
Validates and throws a ArgumentReservedKeywordException if the specified argument is found in the sequence of reservedKeywords.
public static void ThrowIfContainsReservedKeyword(string argument, IEnumerable<string> reservedKeywords, IEqualityComparer<string> comparer, string message = null, string paramName = null)
  Parameters
argumentstringThe keyword to compare with
reservedKeywords.reservedKeywordsIEnumerable<string>The reserved keywords to compare with
argument.comparerIEqualityComparer<string>The IEqualityComparer<T> implementation to use when comparing
reservedKeywordswithargument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentReservedKeywordException
 The specified
argumentis contained withinreservedKeywords.
ThrowIfContainsReservedKeyword(string, IEnumerable<string>, string, string)
Validates and throws a ArgumentReservedKeywordException if the specified argument is found in the sequence of reservedKeywords.
public static void ThrowIfContainsReservedKeyword(string argument, IEnumerable<string> reservedKeywords, string message = null, string paramName = null)
  Parameters
argumentstringThe keyword to compare with
reservedKeywords.reservedKeywordsIEnumerable<string>The reserved keywords to compare with
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentReservedKeywordException
 The specified
argumentis contained withinreservedKeywords.
ThrowIfContainsType(object, Type[], string, string)
Validates and throws an ArgumentOutOfRangeException if the specified argument is contained within at least one of the specified types.
public static void ThrowIfContainsType(object argument, Type[] types, string message = "Specified argument is contained within at least one of the specified types.", string paramName = null)
  Parameters
argumentobjectThe value to be evaluated.
typesType[]A Type array that contains zero or more types to match with the type of
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Remarks
Use ToArrayOf<T>(params T[]) to substitute earlier signature of params Type[] types.
Exceptions
- ArgumentNullException
 argumentis null - or -typesis null.- ArgumentOutOfRangeException
 argumentis contained within at least one of the specifiedtypes.
ThrowIfContainsType(Type, Type[], string, string)
Validates and throws an ArgumentOutOfRangeException if the specified argument is contained within at least one of the specified types.
public static void ThrowIfContainsType(Type argument, Type[] types, string message = "Specified argument is contained within at least one of the specified types.", string paramName = null)
  Parameters
argumentTypeThe value to be evaluated.
typesType[]A Type array that contains zero or more types to match with the type of
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Remarks
Use ToArrayOf<T>(params T[]) to substitute earlier signature of params Type[] types.
Exceptions
- ArgumentNullException
 argumentis null - or -typesis null.- ArgumentOutOfRangeException
 argumentis contained within at least one of the specifiedtypes.
ThrowIfContainsType<T>(string, string, params Type[])
Validates and throws a TypeArgumentOutOfRangeException if the specified T is contained within at least one of the specified types.
public static void ThrowIfContainsType<T>(string typeParamName, string message, params Type[] types)
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
messagestringA message that describes the error.
typesType[]A variable number of Type arguments to match with the type of
T.
Type Parameters
T
Exceptions
- ArgumentNullException
 typesis null.- TypeArgumentOutOfRangeException
 Tis contained within at least one of the specifiedtypes.
ThrowIfContainsType<T>(string, params Type[])
Validates and throws a TypeArgumentOutOfRangeException if the specified T is contained within at least one of the specified types.
public static void ThrowIfContainsType<T>(string typeParamName, params Type[] types)
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
typesType[]A variable number of Type arguments to match with the type of
T.
Type Parameters
T
Exceptions
- ArgumentNullException
 typesis null.- TypeArgumentOutOfRangeException
 Tis contained within at least one of the specifiedtypes.
ThrowIfDifferent(string, string, string, string)
Validates and throws an ArgumentOutOfRangeException if there is a difference between second and first.
public static void ThrowIfDifferent(string first, string second, string paramName, string message = null)
  Parameters
firststringThe value that specifies valid characters.
secondstringThe value to compare with
first.paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
Exceptions
- ArgumentOutOfRangeException
 There is a difference between
secondandfirst.
ThrowIfDisposed(bool, object, string)
Validates and throws an ObjectDisposedException if the specified condition is true.
public static void ThrowIfDisposed(bool condition, object instance, string message = "Cannot access a disposed object.")
  Parameters
conditionboolThe condition to evaluate.
instanceobjectThe object whose type's full name should be included in any resulting ObjectDisposedException.
messagestringA message that describes the error.
Remarks
This guard should be called when performing an operation on a disposed object - not when validating arguments passed to a member.
Exceptions
- ObjectDisposedException
 The
conditionistrue.
ThrowIfDisposed(bool, Type, string)
Validates and throws an ObjectDisposedException if the specified condition is true.
public static void ThrowIfDisposed(bool condition, Type type, string message = "Cannot access a disposed object.")
  Parameters
conditionboolThe condition to evaluate.
typeTypeThe type whose full name should be included in any resulting ObjectDisposedException.
messagestringA message that describes the error.
Remarks
This guard should be called when performing an operation on a disposed object - not when validating arguments passed to a member.
Exceptions
- ObjectDisposedException
 The
conditionistrue.
ThrowIfEmailAddress(string, string, string)
Validates and throws an ArgumentException if the specified argument has the format of an email address.
public static void ThrowIfEmailAddress(string argument, string message = "Value cannot be an email address.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentcannot be an email address.
ThrowIfEmpty(string, string, string)
Validates and throws an ArgumentException if the specified argument is empty.
public static void ThrowIfEmpty(string argument, string message = "Value cannot be empty.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Remarks
This method will not throw an exception if argument is null.
Exceptions
- ArgumentException
 argumentcannot be empty.
ThrowIfEnumType(Type, string, string)
Validates and throws an ArgumentException if the specified argument represents an enumeration.
public static void ThrowIfEnumType(Type argument, string message = "Value represents an enumeration.", string paramName = null)
  Parameters
argumentTypeThe type to check is an enumeration.
messagestringA message that describes the error.
paramNamestringThe name of the type parameter that caused the exception.
Remarks
This method will not throw an exception if argument is null.
Exceptions
- ArgumentException
 argumentrepresents an enumeration.
ThrowIfEnumType<TEnum>(string, string)
Validates and throws a TypeArgumentException if the specified TEnum represents an enumeration.
public static void ThrowIfEnumType<TEnum>(string typeParamName, string message = "Value represents an enumeration.")
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
messagestringA message that describes the error.
Type Parameters
TEnumThe type to check is an enumeration.
Exceptions
- TypeArgumentException
 TEnumrepresents an enumeration.
ThrowIfEnum<TEnum>(string, bool, string, string)
Validates and throws an ArgumentException if the specified argument represents an enumeration.
public static void ThrowIfEnum<TEnum>(string argument, bool ignoreCase = true, string message = "Value represents an enumeration.", string paramName = null) where TEnum : struct, IConvertible
  Parameters
argumentstringThe value to be evaluated.
ignoreCasebooltrueto ignore case;falseto regard case.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Type Parameters
TEnumThe type of the enumeration.
Exceptions
- ArgumentException
 argumentrepresents an enumeration.
ThrowIfEqual<T>(T, T, string, IEqualityComparer<T>, string)
Validates and throws an ArgumentOutOfRangeException if the specified x object are equal to the y object.
public static void ThrowIfEqual<T>(T x, T y, string paramName, IEqualityComparer<T> comparer = null, string message = null)
  Parameters
xTThe first object to compare.
yTThe second object to compare.
paramNamestringThe name of the parameter that caused the exception.
comparerIEqualityComparer<T>The IEqualityComparer<T> implementation to use when comparing
xandy.messagestringA message that describes the error.
Type Parameters
TThe type of objects to compare.
Exceptions
- ArgumentOutOfRangeException
 xandyare equal to one another.
ThrowIfFalse(bool, string, string, string)
Validates and throws an ArgumentException if the specified condition is false.
public static void ThrowIfFalse(bool condition, string paramName, string message = "Value is not in a valid state.", string expression = null)
  Parameters
conditionboolThe value to be evaluated.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
expressionstringThe
conditionexpressed as a string.
Exceptions
- ArgumentException
 conditionisfalse.
ThrowIfFalse(Func<bool>, string, string, string)
Validates and throws an ArgumentException if the specified predicate returns false.
public static void ThrowIfFalse(Func<bool> predicate, string paramName, string message = "Value is not in a valid state.", string expression = null)
  Parameters
predicateFunc<bool>The function delegate that determines if an ArgumentException is thrown.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
expressionstringThe
predicateexpressed as a string.
Exceptions
- ArgumentException
 predicatereturnedfalse.
ThrowIfGreaterThanOrEqual<T>(T, T, string, string)
Validates and throws an ArgumentOutOfRangeException if the specified x is greater than or equal to y.
public static void ThrowIfGreaterThanOrEqual<T>(T x, T y, string paramName, string message = null) where T : struct, IConvertible
  Parameters
xTThe first object to compare.
yTThe second object to compare.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
Type Parameters
TThe type of objects to compare.
Exceptions
- ArgumentOutOfRangeException
 xis greater than or equal toy.
ThrowIfGreaterThan<T>(T, T, string, string)
Validates and throws an ArgumentOutOfRangeException if the specified x is greater than y.
public static void ThrowIfGreaterThan<T>(T x, T y, string paramName, string message = null) where T : struct, IConvertible
  Parameters
xTThe first object to compare.
yTThe second object to compare.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
Type Parameters
TThe type of objects to compare.
Exceptions
- ArgumentOutOfRangeException
 xis greater thany.
ThrowIfGuid(string, GuidFormats, string, string)
Validates and throws an ArgumentException if the specified argument has the format of a Guid.
public static void ThrowIfGuid(string argument, GuidFormats format = GuidFormats.D | GuidFormats.B | GuidFormats.P, string message = "Value cannot be a Guid.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
formatGuidFormatsA bitmask comprised of one or more GuidFormats that specify how the GUID parsing is conducted.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentcannot be a Guid.
ThrowIfHex(string, string, string)
Validates and throws an ArgumentException if the specified argument is hexadecimal.
public static void ThrowIfHex(string argument, string message = "Specified argument cannot be hexadecimal.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentcannot be hexadecimal.
ThrowIfInvalidConfigurator<TOptions>(Action<TOptions>, out TOptions, string, string)
Validates and throws an ArgumentException if the specified argument results in an instance of invalid options.
public static void ThrowIfInvalidConfigurator<TOptions>(Action<TOptions> argument, out TOptions options, string message = "Delegate must configure the public read-write properties to be in a valid state.", string paramName = null) where TOptions : class, IParameterObject, new()
  Parameters
argumentAction<TOptions>The delegate that will configure the public read-write properties of
options.optionsTOptionsThe default parameter-less constructed instance of
TOptionsconfigured withargumentdelegate.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Type Parameters
TOptionsThe type of the object that potentially is implementing the IValidatableParameterObject interface.
Exceptions
- ArgumentException
 argumentfailed to configure an instanceoptionsin a valid state.
ThrowIfInvalidOptions<TOptions>(TOptions, string, string)
Validates and throws an ArgumentException if the specified argument are not in a valid state.
public static void ThrowIfInvalidOptions<TOptions>(TOptions argument, string message = "{0} are not in a valid state.", string paramName = null) where TOptions : class, IParameterObject, new()
  Parameters
argumentTOptionsThe configured options to validate.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Type Parameters
TOptionsThe type of the object that potentially is implementing the IValidatableParameterObject interface.
Remarks
message will have the name of the TOptions if possible; otherwise Options.
Exceptions
- ArgumentNullException
 argumentcannot be null.- ArgumentException
 argumentare not in a valid state.
ThrowIfInvalidState(bool, string, string)
Validates and throws an InvalidOperationException if the specified condition is true.
public static void ThrowIfInvalidState(bool condition, string message = "Operation is not valid due to the current state of the object.", string expression = null)
  Parameters
conditionboolThe value that determines if an InvalidOperationException is thrown.
messagestringA message that describes the error.
expressionstringThe
conditionexpressed as a string.
Remarks
This guard should be called when validating the state of an object - not when validating arguments passed to a member.
Exceptions
- InvalidOperationException
 conditionistrue.
ThrowIfLowerThanOrEqual<T>(T, T, string, string)
Validates and throws an ArgumentOutOfRangeException if the specified x is lower than or equal to y.
public static void ThrowIfLowerThanOrEqual<T>(T x, T y, string paramName, string message = null) where T : struct, IConvertible
  Parameters
xTThe first object to compare.
yTThe second object to compare.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
Type Parameters
TThe type of objects to compare.
Exceptions
- ArgumentOutOfRangeException
 xis lower than or equal toy.
ThrowIfLowerThan<T>(T, T, string, string)
Validates and throws an ArgumentOutOfRangeException if the specified x is lower than y.
public static void ThrowIfLowerThan<T>(T x, T y, string paramName, string message = null) where T : struct, IConvertible
  Parameters
xTThe first object to compare.
yTThe second object to compare.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
Type Parameters
TThe type of objects to compare.
Exceptions
- ArgumentOutOfRangeException
 xis lower thany.
ThrowIfNotBase64String(string, string, string)
Validates and throws an ArgumentOutOfRangeException if the specified argument consist of anything besides a base-64 structure.
public static void ThrowIfNotBase64String(string argument, string message = "Value must consist only of base-64 digits.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentOutOfRangeException
 argumentmust consist only of base-64 digits.
ThrowIfNotBinaryDigits(string, string, string)
Validates and throws an ArgumentOutOfRangeException if the specified argument consist of anything besides binary digits.
public static void ThrowIfNotBinaryDigits(string argument, string message = "Value must consist only of binary digits.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentOutOfRangeException
 argumentmust consist only of binary digits.
ThrowIfNotContainsAny(string, char[], StringComparison, string, string)
Validates and throws an ArgumentOutOfRangeException if any of the characters does not occur within the argument.
public static void ThrowIfNotContainsAny(string argument, char[] characters, StringComparison comparison = StringComparison.OrdinalIgnoreCase, string message = "No matching characters were found.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
characterschar[]The sequence of char to search within
argument.comparisonStringComparisonOne of the enumeration values that specifies the rules to use in the comparison.
messagestringThe message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentOutOfRangeException
 argumentdoes not contain any of the specifiedcharacters.
ThrowIfNotContainsInterface(Type, Type[], string, string)
Validates and throws an ArgumentOutOfRangeException if the specified argument is not contained within at least one of the specified types.
public static void ThrowIfNotContainsInterface(Type argument, Type[] types, string message = "Specified argument is not contained within at least one of the specified types.", string paramName = null)
  Parameters
argumentTypeThe value to be evaluated.
typesType[]A Type array that contains zero or more types (that each must be an interface) to match with the type of
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Remarks
Use ToArrayOf<T>(params T[]) to substitute earlier signature of params Type[] types.
Exceptions
- ArgumentNullException
 argumentis null - or -typesis null.- ArgumentOutOfRangeException
 argumentis not contained within at least one of the specifiedtypes.- ArgumentException
 typesdoes not satisfy the condition of being an interface.
ThrowIfNotContainsInterface<T>(string, string, params Type[])
Validates and throws a TypeArgumentOutOfRangeException if the specified T is not contained within at least one of the specified types.
public static void ThrowIfNotContainsInterface<T>(string typeParamName, string message, params Type[] types)
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
messagestringA message that describes the error.
typesType[]A variable number of Type arguments (that must be an interface) to match with the type of
T.
Type Parameters
T
Exceptions
- ArgumentNullException
 typesis null.- TypeArgumentOutOfRangeException
 Tis not contained within at least one of the specifiedtypes.- ArgumentException
 typesdoes not satisfy the condition of being an interface.
ThrowIfNotContainsInterface<T>(string, params Type[])
Validates and throws a TypeArgumentOutOfRangeException if the specified T is not contained within at least one of the specified types.
public static void ThrowIfNotContainsInterface<T>(string typeParamName, params Type[] types)
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
typesType[]A variable number of Type arguments (that must be an interface) to match with the type of
T.
Type Parameters
T
Exceptions
- ArgumentNullException
 typesis null.- TypeArgumentOutOfRangeException
 Tis not contained within at least one of the specifiedtypes.- ArgumentException
 typesdoes not satisfy the condition of being an interface.
ThrowIfNotContainsType(object, Type[], string, string)
Validates and throws an ArgumentOutOfRangeException if the specified argument is not contained within at least one of the specified types.
public static void ThrowIfNotContainsType(object argument, Type[] types, string message = "Specified argument is not contained within at least one of the specified types.", string paramName = null)
  Parameters
argumentobjectThe value to be evaluated.
typesType[]A Type array that contains zero or more types to match with the type of
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Remarks
Use ToArrayOf<T>(params T[]) to substitute earlier signature of params Type[] types.
Exceptions
- ArgumentNullException
 argumentis null - or -typesis null.- ArgumentOutOfRangeException
 argumentis not contained within at least one of the specifiedtypes.
ThrowIfNotContainsType(Type, Type[], string, string)
Validates and throws an ArgumentOutOfRangeException if the specified argument is not contained within at least one of the specified types.
public static void ThrowIfNotContainsType(Type argument, Type[] types, string message = "Specified argument is not contained within at least one of the specified types.", string paramName = null)
  Parameters
argumentTypeThe value to be evaluated.
typesType[]A Type array that contains zero or more types to match with the type of
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Remarks
Use ToArrayOf<T>(params T[]) to substitute earlier signature of params Type[] types.
Exceptions
- ArgumentNullException
 argumentis null - or -typesis null.- ArgumentOutOfRangeException
 argumentis not contained within at least one of the specifiedtypes.
ThrowIfNotContainsType<T>(string, string, params Type[])
Validates and throws a TypeArgumentOutOfRangeException if the specified T is not contained within at least one of the specified types.
public static void ThrowIfNotContainsType<T>(string typeParamName, string message, params Type[] types)
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
messagestringA message that describes the error.
typesType[]A variable number of Type arguments to match with the type of
T.
Type Parameters
T
Exceptions
- ArgumentNullException
 typesis null.- TypeArgumentOutOfRangeException
 Tis not contained within at least one of the specifiedtypes.
ThrowIfNotContainsType<T>(string, params Type[])
Validates and throws a TypeArgumentOutOfRangeException if the specified T is not contained within at least one of the specified types.
public static void ThrowIfNotContainsType<T>(string typeParamName, params Type[] types)
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
typesType[]A variable number of Type arguments to match with the type of
T.
Type Parameters
T
Exceptions
- ArgumentNullException
 typesis null.- TypeArgumentOutOfRangeException
 Tis not contained within at least one of the specifiedtypes.
ThrowIfNotDifferent(string, string, string, string)
Validates and throws an ArgumentOutOfRangeException if there is no difference between second and first.
public static void ThrowIfNotDifferent(string first, string second, string paramName, string message = null)
  Parameters
firststringThe value that specifies valid characters.
secondstringThe value to compare with
first.paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
Exceptions
- ArgumentOutOfRangeException
 There is no difference between
secondandfirst.
ThrowIfNotEmailAddress(string, string, string)
Validates and throws an ArgumentException if the specified argument does not have the format of an email address.
public static void ThrowIfNotEmailAddress(string argument, string message = "Value must be an email address.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentmust be an email address.
ThrowIfNotEnumType(Type, string, string)
Validates and throws an ArgumentException if the specified argument does not represents an enumeration.
public static void ThrowIfNotEnumType(Type argument, string message = "Value does not represents an enumeration.", string paramName = null)
  Parameters
argumentTypeThe type to check is not an enumeration.
messagestringA message that describes the error.
paramNamestringThe name of the type parameter that caused the exception.
Exceptions
- ArgumentException
 argumentdoes not represents an enumeration.
ThrowIfNotEnumType<TEnum>(string, string)
Validates and throws a TypeArgumentException if the specified TEnum does not represents an enumeration.
public static void ThrowIfNotEnumType<TEnum>(string typeParamName, string message = "Value does not represents an enumeration.")
  Parameters
typeParamNamestringThe name of the type parameter that caused the exception.
messagestringA message that describes the error.
Type Parameters
TEnumThe type to check is not an enumeration.
Exceptions
- TypeArgumentException
 TEnumdoes not represents an enumeration.
ThrowIfNotEnum<TEnum>(string, bool, string, string)
Validates and throws an ArgumentException if the specified argument does not represents an enumeration.
public static void ThrowIfNotEnum<TEnum>(string argument, bool ignoreCase = true, string message = "Value does not represents an enumeration.", string paramName = null) where TEnum : struct, IConvertible
  Parameters
argumentstringThe value to be evaluated.
ignoreCasebooltrueto ignore case;falseto regard case.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Type Parameters
TEnumThe type of the enumeration.
Exceptions
- ArgumentException
 argumentdoes not represents an enumeration.
ThrowIfNotEqual<T>(T, T, string, IEqualityComparer<T>, string)
Validates and throws an ArgumentOutOfRangeException if the specified x object are not equal to the y object.
public static void ThrowIfNotEqual<T>(T x, T y, string paramName, IEqualityComparer<T> comparer = null, string message = null)
  Parameters
xTThe first object to compare.
yTThe second object to compare.
paramNamestringThe name of the parameter that caused the exception.
comparerIEqualityComparer<T>The IEqualityComparer<T> implementation to use when comparing
xandy.messagestringA message that describes the error.
Type Parameters
TThe type of objects to compare.
Exceptions
- ArgumentOutOfRangeException
 xandyare not equal to one another.
ThrowIfNotGuid(string, GuidFormats, string, string)
Validates and throws an ArgumentException if the specified argument does not have the format of a Guid.
public static void ThrowIfNotGuid(string argument, GuidFormats format = GuidFormats.D | GuidFormats.B | GuidFormats.P, string message = "Value must be a Guid.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
formatGuidFormatsA bitmask comprised of one or more GuidFormats that specify how the GUID parsing is conducted.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentmust be a Guid.
ThrowIfNotHex(string, string, string)
Validates and throws an ArgumentException if the specified argument is not hexadecimal.
public static void ThrowIfNotHex(string argument, string message = "Value must be hexadecimal.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentmust be hexadecimal.
ThrowIfNotNumber(string, NumberStyles, IFormatProvider, string, string)
Validates and throws an ArgumentException if the specified argument is not a number.
public static void ThrowIfNotNumber(string argument, NumberStyles styles = NumberStyles.Number, IFormatProvider provider = null, string message = "Value must be a number.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
stylesNumberStylesA bitwise combination of NumberStyles values that indicates the permitted format of
argument.providerIFormatProviderAn IFormatProvider that supplies culture-specific formatting information about
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentmust be a number.
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.
public static void ThrowIfNotSame<T>(T x, T y, string paramName, string message = null)
  Parameters
xTThe first object to compare.
yTThe second object to compare.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
Type Parameters
TThe type of objects to compare.
Exceptions
- ArgumentOutOfRangeException
 xandyare not of the same instance.
ThrowIfNotUri(string, UriKind, string, string)
Validates and throws an ArgumentException if the specified argument does not have the format of a Uri.
public static void ThrowIfNotUri(string argument, UriKind uriKind = UriKind.Absolute, string message = "Value must be a URI.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
uriKindUriKindThe type of the URI.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentmust be a Uri.- ArgumentOutOfRangeException
 uriKindwas set to an indeterminate value of RelativeOrAbsolute.
ThrowIfNull(object, string, string)
Validates and throws an ArgumentNullException if the specified argument is null.
public static void ThrowIfNull(object argument, string message = "Value cannot be null.", string paramName = null)
  Parameters
argumentobjectThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentNullException
 argumentcannot be null.
ThrowIfNullOrEmpty(string, string, string)
Validates and throws either an ArgumentNullException or ArgumentException if the specified argument is respectively null or empty.
public static void ThrowIfNullOrEmpty(string argument, string message = null, string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error to your liking.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentNullException
 argumentcannot be null.- ArgumentException
 argumentcannot be empty.
ThrowIfNullOrWhitespace(string, string, string)
Validates and throws either an ArgumentNullException or ArgumentException if the specified argument is respectively null, empty or consist only of white-space characters.
public static void ThrowIfNullOrWhitespace(string argument, string message = null, string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentNullException
 argumentcannot be null.- ArgumentException
 argumentcannot be empty or consist only of white-space characters.
ThrowIfNull<T>(IDecorator<T>, out T, string, string)
Validates and throws an ArgumentNullException if the specified argument is null.
public static void ThrowIfNull<T>(IDecorator<T> argument, out T inner, string message = "Value cannot be null.", string paramName = null)
  Parameters
argumentIDecorator<T>The value to be evaluated.
innerTThe inner object of
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Type Parameters
TThe type of the inner object denoted by
argument.
Exceptions
- ArgumentNullException
 argumentcannot be null - or - IDecorator.Inner property ofargumentcannot be null.
ThrowIfNumber(string, NumberStyles, IFormatProvider, string, string)
Validates and throws an ArgumentException if the specified argument is a number.
public static void ThrowIfNumber(string argument, NumberStyles styles = NumberStyles.Number, IFormatProvider provider = null, string message = "Value cannot be a number.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
stylesNumberStylesA bitwise combination of NumberStyles values that indicates the permitted format of
argument.providerIFormatProviderAn IFormatProvider that supplies culture-specific formatting information about
argument.messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentcannot be a number.
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.
public static void ThrowIfSame<T>(T x, T y, string paramName, string message = null)
  Parameters
xTThe first object to compare.
yTThe second object to compare.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
Type Parameters
TThe type of objects to compare.
Exceptions
- ArgumentOutOfRangeException
 xandyare of the same instance.
ThrowIfSequenceEmpty<T>(IEnumerable<T>, string, string)
Validates and throws an ArgumentException if the specified argument has no elements.
public static void ThrowIfSequenceEmpty<T>(IEnumerable<T> argument, string message = "Value contains no elements.", string paramName = null)
  Parameters
argumentIEnumerable<T>The value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Type Parameters
T
Remarks
This method will not throw an exception if argument is null.
Exceptions
- ArgumentException
 argumentcontains no elements.
ThrowIfSequenceNullOrEmpty<T>(IEnumerable<T>, string, string)
Validates and throws either an ArgumentNullException or ArgumentException if the specified argument is respectively null or has no elements.
public static void ThrowIfSequenceNullOrEmpty<T>(IEnumerable<T> argument, string message = "Value is either null or contains no elements.", string paramName = null)
  Parameters
argumentIEnumerable<T>The value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Type Parameters
T
Exceptions
- ArgumentNullException
 argumentcannot be null.- ArgumentException
 argumentcontains no elements.
ThrowIfTrue(bool, string, string, string)
Validates and throws an ArgumentException if the specified condition is true.
public static void ThrowIfTrue(bool condition, string paramName, string message = "Value is not in a valid state.", string expression = null)
  Parameters
conditionboolThe value to be evaluated.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
expressionstringThe
conditionexpressed as a string.
Exceptions
- ArgumentException
 conditionistrue.
ThrowIfTrue(Func<bool>, string, string, string)
Validates and throws an ArgumentException if the specified predicate returns true.
public static void ThrowIfTrue(Func<bool> predicate, string paramName, string message = "Value is not in a valid state.", string expression = null)
  Parameters
predicateFunc<bool>The function delegate that determines if an ArgumentException is thrown.
paramNamestringThe name of the parameter that caused the exception.
messagestringA message that describes the error.
expressionstringThe
predicateexpressed as a string.
Exceptions
- ArgumentException
 predicatereturnedtrue.
ThrowIfUri(string, UriKind, string, string)
Validates and throws an ArgumentException if the specified argument has the format of a Uri.
public static void ThrowIfUri(string argument, UriKind uriKind = UriKind.Absolute, string message = "Value cannot be a URI.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
uriKindUriKindThe type of the URI.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Exceptions
- ArgumentException
 argumentcannot be a Uri.- ArgumentOutOfRangeException
 uriKindwas set to an indeterminate value of RelativeOrAbsolute.
ThrowIfWhiteSpace(string, string, string)
Validates and throws an ArgumentException if the specified argument consist only of white-space characters.
public static void ThrowIfWhiteSpace(string argument, string message = "Value cannot consist only of white-space characters.", string paramName = null)
  Parameters
argumentstringThe value to be evaluated.
messagestringA message that describes the error.
paramNamestringThe name of the parameter that caused the exception.
Remarks
This method will not throw an exception if argument is null.
Exceptions
- ArgumentException
 argumentcannot consist only of white-space characters.
ThrowWhen(Action<ExceptionCondition<ArgumentException>>)
Validates and throws an ArgumentException (or a derived counterpart) from the specified delegate condition.
public static void ThrowWhen(Action<ExceptionCondition<ArgumentException>> condition)
  Parameters
conditionAction<ExceptionCondition<ArgumentException>>The delegate that evaluates, creates and ultimately throws an ArgumentException (or a derived counterpart) from within a given scenario.
Exceptions
- ArgumentNullException
 conditionis null.