ThrowIfContainsType Method
Definition
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, 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.
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.