ThrowIfNotContainsType Method
Definition
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(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<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.
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.