Table of Contents

Class TypeHelper

Namespace
MLEM.Data
Assembly
MLEM.Data.dll

This class contains a set of static helper methods for dealing with the string representations of Type names, including generic and non-generic types, and especially for converting between types and their AssemblyQualifiedName.

public class TypeHelper
Inheritance
TypeHelper
Inherited Members

Methods

GetGenericTypeArguments(string)

Returns the assembly-qualified names of the generic type arguments that the type with the given assemblyQualifiedName has. Note that "recursive" generic type arguments (ie. generic type arguments that themselves have generic type arguments) are not automatically resolved.

public static IEnumerable<string> GetGenericTypeArguments(string assemblyQualifiedName)

Parameters

assemblyQualifiedName string

The type's name, which can either be assembly-qualified or not.

Returns

IEnumerable<string>

The generic type arguments the the given type has, or an empty collection if it is not generic.

Remarks

JoinAssemblyQualifiedName(string, string)

Joins the given type name and assembly into their assembly-qualified name, which is the type name, a comma and a space, and the assembly name.

public static string JoinAssemblyQualifiedName(string type, string assembly)

Parameters

type string

The type name.

assembly string

The assembly name.

Returns

string

The assembly-qualified name.

RemoveAssemblyMetadata(string)

Removes the assembly metadata from the given assemblyQualifiedName, specifically the version, public key token, and further metadata after the assembly name. A non-assembly-qualified type name is returned unchanged.

public static string RemoveAssemblyMetadata(string assemblyQualifiedName)

Parameters

assemblyQualifiedName string

The type's name, which can either be assembly-qualified or not.

Returns

string

The assemblyQualifiedName with assembly metadata like the version and public key token removed.

Remarks

SplitAssemblyQualifiedName(string)

Splits the given assemblyQualifiedName into a type name and an assembly name (if present).

public static (string Type, string Assembly) SplitAssemblyQualifiedName(string assemblyQualifiedName)

Parameters

assemblyQualifiedName string

The assembly-qualified name to split. If this is a type name only, the returned assembly will be null.

Returns

(string Type, string Assembly)

A tuple containing the type name and the assembly name (if it was present in the original assembly-qualified name, otherwise null).