Class TypeHelper
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
assemblyQualifiedNamestringThe 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
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
assemblyQualifiedNamestringThe type's name, which can either be assembly-qualified or not.
Returns
- string
The
assemblyQualifiedNamewith 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
assemblyQualifiedNamestringThe assembly-qualified name to split. If this is a type name only, the returned assembly will be null.