Class TypeHelper
Utility methods related to Type.
public static class TypeHelper
- Inheritance
-
TypeHelper
- Inherited Members
Methods
ConvertArgument(object?, Type)
Converts an argument into its target type. Can be particularly useful when pulling attribute constructor arguments, whose types may not strictly match the parameter type.
public static object? ConvertArgument(object? arg, Type type)
Parameters
Returns
- object
The converted argument.
ConvertArguments(object?[], Type[])
Converts arguments into their target types. Can be particularly useful when pulling attribute constructor arguments, whose types may not strictly match the parameter types.
public static object?[] ConvertArguments(object?[] args, Type[] types)
Parameters
Returns
- object[]
The converted arguments.
ConvertAttributeArgumentCollection(IReadOnlyCollection<CustomAttributeTypedArgument>, Type)
Converts an argument collection from an attribute initializer into an array of the raw values.
public static Array ConvertAttributeArgumentCollection(IReadOnlyCollection<CustomAttributeTypedArgument> collection, Type elementType)
Parameters
collectionIReadOnlyCollection<CustomAttributeTypedArgument>The attribute argument collection.
elementTypeTypeThe element type of the array.
Returns
- Array
The collection of the raw attribute values.
GetType(string)
Converts an assembly qualified type name from GetTypeName(Type) back into a Type object.
public static Type? GetType(string assemblyQualifiedTypeName)
Parameters
assemblyQualifiedTypeNamestringThe assembly qualified type name.
Returns
GetType(string, string)
Converts an assembly name + type name into a Type object.
public static Type? GetType(string assemblyName, string typeName)
Parameters
Returns
GetTypeName(Type)
Gets an assembly-qualified type name suitable for serialization.
public static string GetTypeName(Type value)
Parameters
valueTypeThe type value
Returns
- string
A string in "TypeName" format (for mscorlib types) or "TypeName,AssemblyName" format (for all others)
Remarks
Dynamic types, or types which live in the GAC, are not supported.
GetTypeStrict(string)
Converts an assembly qualified type name into a Type object. If the type does not exist, throws an ArgumentException.
public static Type GetTypeStrict(string assemblyQualifiedTypeName)
Parameters
assemblyQualifiedTypeNamestringThe assembly qualified type name.