Show / Hide Table of Contents

Class Validator

Provides a generic way to validate different types of arguments passed to members.

Inheritance
Object
Validator
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public sealed class Validator

Properties

| Improve this Doc View Source

ThrowIf

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 Source

CheckParameter<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 value is not valid.

Returns
Type Description
T

The specified value unaltered.

Type Parameters
Name Description
T

The type of the object to evaluate.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is contained within at least one of the specified types.

ArgumentException

types does not satisfy the condition of being an interface.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is contained within at least one of the specified types.

ArgumentException

types does not satisfy the condition of being an interface.

| Improve this Doc View Source

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 T.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

types is null.

TypeArgumentOutOfRangeException

T is contained within at least one of the specified types.

ArgumentException

types does not satisfy the condition of being an interface.

| Improve this Doc View Source

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 T.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

types is null.

TypeArgumentOutOfRangeException

T is contained within at least one of the specified types.

ArgumentException

types does not satisfy the condition of being an interface.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is contained within at least one of the specified types.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is contained within at least one of the specified types.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is contained within at least one of the specified types.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is contained within at least one of the specified types.

| Improve this Doc View Source

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 T.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

types is null.

TypeArgumentOutOfRangeException

T is contained within at least one of the specified types.

| Improve this Doc View Source

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 T.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

types is null.

TypeArgumentOutOfRangeException

T is contained within at least one of the specified types.

| Improve this Doc View Source

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

value cannot be an email address.

| Improve this Doc View Source

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

value cannot be empty.

| Improve this Doc View Source

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

true to ignore case; false to regard case.

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

value represents an enumeration.

| Improve this Doc View Source

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

value represents an enumeration.

| Improve this Doc View Source

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

value represents an enumeration.

| Improve this Doc View Source

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

TEnum represents an enumeration.

| Improve this Doc View Source

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 x and y.

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

x and y are equal to one another.

| Improve this Doc View Source

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 x and y.

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

x and y are equal to one another.

| Improve this Doc View Source

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

x and y are equal to one another.

| Improve this Doc View Source

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

x and y are equal to one another.

| Improve this Doc View Source

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

value must be true.

| Improve this Doc View Source

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

predicate returned false.

| Improve this Doc View Source

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

x is greater than y.

| Improve this Doc View Source

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

x is greater than y.

| Improve this Doc View Source

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

x is greater than or equal to y.

| Improve this Doc View Source

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

x is greater than or equal to y.

| Improve this Doc View Source

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

value cannot be a Guid.

| Improve this Doc View Source

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

value cannot be a Guid.

| Improve this Doc View Source

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

value cannot be hexadecimal.

| Improve this Doc View Source

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 options.

String paramName

The name of the parameter that caused the exception.

TOptions options

The default parameter-less constructed instance of TOptions configured with setup delegate.

Type Parameters
Name Description
TOptions

The type of the object implementing the IValidatableParameterObject interface.

Exceptions
Type Condition
ArgumentException

setup failed to configure an instance of options in a valid state.

| Improve this Doc View Source

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 options.

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 TOptions configured with setup delegate.

Type Parameters
Name Description
TOptions

The type of the object implementing the IValidatableParameterObject interface.

Exceptions
Type Condition
ArgumentException

setup failed to configure an instance options in a valid state.

| Improve this Doc View Source

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

options cannot be null.

ArgumentException

options are not in a valid state.

| Improve this Doc View Source

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

x is lower than y.

| Improve this Doc View Source

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

x is lower than y.

| Improve this Doc View Source

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

x is lower than or equal to y.

| Improve this Doc View Source

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

x is lower than or equal to y.

| Improve this Doc View Source

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

value must consist only of base-64 digits.

| Improve this Doc View Source

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

value must consist only of binary digits.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is not contained within at least one of the specified types.

ArgumentException

types does not satisfy the condition of being an interface.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is not contained within at least one of the specified types.

ArgumentException

types does not satisfy the condition of being an interface.

| Improve this Doc View Source

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 T.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

types is null.

TypeArgumentOutOfRangeException

T is not contained within at least one of the specified types.

ArgumentException

types does not satisfy the condition of being an interface.

| Improve this Doc View Source

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 T.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

types is null.

TypeArgumentOutOfRangeException

T is not contained within at least one of the specified types.

ArgumentException

types does not satisfy the condition of being an interface.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is not contained within at least one of the specified types.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is not contained within at least one of the specified types.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is not contained within at least one of the specified types.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentNullException

value is null - or - types is null.

ArgumentOutOfRangeException

value is not contained within at least one of the specified types.

| Improve this Doc View Source

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 T.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

types is null.

TypeArgumentOutOfRangeException

T is not contained within at least one of the specified types.

| Improve this Doc View Source

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 T.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

types is null.

TypeArgumentOutOfRangeException

T is not contained within at least one of the specified types.

| Improve this Doc View Source

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

value must be an email address.

| Improve this Doc View Source

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

true to ignore case; false to regard case.

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

value does not represents an enumeration.

| Improve this Doc View Source

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

value does not represents an enumeration.

| Improve this Doc View Source

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

value does not represents an enumeration.

| Improve this Doc View Source

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

TEnum does not represents an enumeration.

| Improve this Doc View Source

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 x and y.

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

x and y are not equal to one another.

| Improve this Doc View Source

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 x and y.

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

x and y are not equal to one another.

| Improve this Doc View Source

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

x and y are not equal to one another.

| Improve this Doc View Source

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

x and y are not equal to one another.

| Improve this Doc View Source

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

value must be a Guid.

| Improve this Doc View Source

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

value must be a Guid.

| Improve this Doc View Source

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

value must be hexadecimal.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentException

value must be a number.

| Improve this Doc View Source

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 value.

IFormatProvider provider

An IFormatProvider that supplies culture-specific formatting information about value.

Exceptions
Type Condition
ArgumentException

value must be a number.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentException

value must be a number.

| Improve this Doc View Source

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 value.

IFormatProvider provider

An IFormatProvider that supplies culture-specific formatting information about value.

Exceptions
Type Condition
ArgumentException

value must be a number.

| Improve this Doc View Source

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

x and y are not of the same instance.

| Improve this Doc View Source

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

x and y are not of the same instance.

| Improve this Doc View Source

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

value must be a Uri.

| Improve this Doc View Source

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

value must be a Uri.

| Improve this Doc View Source

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

value cannot be null.

| Improve this Doc View Source

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 decorator.

Type Parameters
Name Description
T

The type of the inner object denoted by decorator.

Exceptions
Type Condition
ArgumentNullException

decorator cannot be null - or - IDecorator.Inner property of decorator cannot be null.

| Improve this Doc View Source

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 decorator.

Type Parameters
Name Description
T

The type of the inner object denoted by decorator.

Exceptions
Type Condition
ArgumentNullException

decorator cannot be null - or - IDecorator.Inner property of decorator cannot be null.

| Improve this Doc View Source

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

value cannot be null.

ArgumentException

value cannot be empty.

| Improve this Doc View Source

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

value cannot be null.

ArgumentException

value cannot be empty.

| Improve this Doc View Source

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

value cannot be null.

ArgumentException

value cannot be empty or consist only of white-space characters.

| Improve this Doc View Source

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

value cannot be null.

ArgumentException

value cannot be empty or consist only of white-space characters.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentException

value cannot be a number.

| Improve this Doc View Source

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 value.

IFormatProvider provider

An IFormatProvider that supplies culture-specific formatting information about value.

Exceptions
Type Condition
ArgumentException

value cannot be a number.

| Improve this Doc View Source

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 value.

Exceptions
Type Condition
ArgumentException

value cannot be a number.

| Improve this Doc View Source

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 value.

IFormatProvider provider

An IFormatProvider that supplies culture-specific formatting information about value.

Exceptions
Type Condition
ArgumentException

value cannot be a number.

| Improve this Doc View Source

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 predicate expressed as a string.

Exceptions
Type Condition
InvalidOperationException

predicate is true.

| Improve this Doc View Source

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 predicate expressed as a string.

Exceptions
Type Condition
InvalidOperationException

predicate returned true.

| Improve this Doc View Source

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

x and y are of the same instance.

| Improve this Doc View Source

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

x and y are of the same instance.

| Improve this Doc View Source

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

value contains no elements.

| Improve this Doc View Source

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

value cannot be null.

ArgumentException

value contains no elements.

| Improve this Doc View Source

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

value must be false.

| Improve this Doc View Source

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

predicate returned true.

| Improve this Doc View Source

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

value cannot be a Uri.

| Improve this Doc View Source

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

value cannot be a Uri.

| Improve this Doc View Source

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

value cannot consist only of white-space characters.

| Improve this Doc View Source

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

condition is null.

  • Improve this Doc
  • View Source
In This Article
Back to top Copyright 2008-2022 Geekle. All rights reserved. Code with passion and love; deploy with confidence. 👨‍💻️🔥❤️🚀😎
Generated by DocFX