Table of Contents

Class TypeHelper

Namespace
Xunit.Sdk

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

arg object

The argument to be converted.

type Type

The target type for the conversion.

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

args object[]

The arguments to be converted.

types Type[]

The target types for the conversion.

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

collection IReadOnlyCollection<CustomAttributeTypedArgument>

The attribute argument collection.

elementType Type

The 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

assemblyQualifiedTypeName string

The assembly qualified type name.

Returns

Type

The instance of the Type, if available; null, otherwise.

GetType(string, string)

Converts an assembly name + type name into a Type object.

public static Type? GetType(string assemblyName, string typeName)

Parameters

assemblyName string

The assembly name.

typeName string

The type name.

Returns

Type

The instance of the Type, if available; null, otherwise.

GetTypeName(Type)

Gets an assembly-qualified type name suitable for serialization.

public static string GetTypeName(Type value)

Parameters

value Type

The 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

assemblyQualifiedTypeName string

The assembly qualified type name.

Returns

Type

The instance of the Type.