Class TypeHelper
TypeHelper provides static methods that operate on Types.
public class TypeHelper
- Inheritance
-
TypeHelper
- Inherited Members
Constructors
TypeHelper()
public TypeHelper()
Methods
BestCommonType(Type, Type)
Returns the best fit for a common type to be used in matching actual arguments to a methods Type parameters.
public static Type BestCommonType(Type type1, Type type2)
Parameters
Returns
- Type
Either type1 or type2, depending on which is more general.
CanDeduceTypeArgsFromArgs(Type, object[], ref Type[])
Determines whether this instance can deduce type args for a generic type from the supplied arguments.
public static bool CanDeduceTypeArgsFromArgs(Type type, object[] arglist, ref Type[] typeArgsOut)
Parameters
type
TypeThe type to be examined.
arglist
object[]The arglist.
typeArgsOut
Type[]The type args to be used.
Returns
- bool
true
if this the provided args give sufficient information to determine the type args to be used; otherwise,false
.
ConvertArgumentList(object[], ParameterInfo[])
Convert an argument list to the required paramter types. Currently, only widening numeric conversions are performed.
public static void ConvertArgumentList(object[] arglist, ParameterInfo[] parameters)
Parameters
arglist
object[]An array of args to be converted
parameters
ParameterInfo[]A ParamterInfo[] whose types will be used as targets
GetDisplayName(Type)
Gets the display name for a Type as used by NUnit.
public static string GetDisplayName(Type type)
Parameters
type
TypeThe Type for which a display name is needed.
Returns
- string
The display name for the Type
GetDisplayName(Type, object[])
Gets the display name for a Type as used by NUnit.
public static string GetDisplayName(Type type, object[] arglist)
Parameters
Returns
- string
The display name for the Type
GetEnumNames(Type)
Gets the ids of the _values for an enumeration, using Enum.GetNames where available, otherwise through reflection.
public static string[] GetEnumNames(Type enumType)
Parameters
enumType
Type
Returns
- string[]
GetEnumValues(Type)
Gets the _values for an enumeration, using Enum.GetTypes where available, otherwise through reflection.
public static Array GetEnumValues(Type enumType)
Parameters
enumType
Type
Returns
IsNumeric(Type)
Determines whether the specified type is numeric.
public static bool IsNumeric(Type type)
Parameters
type
TypeThe type to be examined.
Returns
- bool
true
if the specified type is numeric; otherwise,false
.
MakeGenericType(Type, Type[])
Creates an instance of a generic Type using the supplied Type arguments
public static Type MakeGenericType(Type type, Type[] typeArgs)
Parameters
Returns
- Type
An instance of the generic type.