Table of Contents

Class TypeExtensions

Namespace
Existential
Assembly
Existential.Net.dll

Contains extension methods for System.Type that will include any generic parameters in the Type name.

Although the System.Type class allows the generic parameters of the Type to be enumerated, it doesn't include them in the name of the class. The extension methods in this class allow names to be retrieved from the Type in a format that lists its generic parameters between angle brackets.

public static class TypeExtensions
Inheritance
System.Object
TypeExtensions
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()

Methods

GetGenericAwareFullTypeName(Type)

Gets the full name of the type, including any generic type parameters.

public static string GetGenericAwareFullTypeName(this Type inType)

Parameters

inType System.Type

The type for which to get the full name.

Returns

System.String

The full name of the type, including any generic type parameters.

Examples

For example, if you call typeof(List<int>).FullName, you would get System.Collections.Generic.List1, which does not include the int type parameter. However, if you use this extension method on the same type, like typeof(List<int>).GetGenericAwareFullTypeName(), you would get System.Collections.Generic.List<Int32>, which includes the int type parameter.

Exceptions

System.ArgumentNullException

An System.ArgumentNullException will be thrown if the Type inType this method is called on is null.

GetGenericAwareFullTypeName<T>(T)

Gets the full name of the type of the provided instance, including any generic type parameters.

public static string GetGenericAwareFullTypeName<T>(this T inInstance)

Parameters

inInstance T

The instance for which to get the type name.

Returns

System.String

The full name of the type, including any generic type parameters.

Type Parameters

T

The type of the instance (will be inferred).

Examples

For example, if you call typeof(List<int>).FullName, you would get System.Collections.Generic.List1, which does not include the int type parameter. However, if you call GetGenericAwareFullTypeName() on an instance of List<int> you would get System.Collections.Generic.List<Int32>, which includes the int type parameter.

Exceptions

System.ArgumentNullException

An System.ArgumentNullException will be thrown if the instance inInstance this method is called on is null.

GetGenericAwareTypeName(Type)

Gets the name of the type, including any generic type parameters.

public static string GetGenericAwareTypeName(this Type inType)

Parameters

inType System.Type

The type for which to get the name.

Returns

System.String

The name of the type, including any generic type parameters.

Examples

For example, if you call typeof(List<int>).Name, you would get List1, which does not include the int type parameter. However, if you use this extension method on the same type, like typeof(List<int>).GetGenericAwareTypeName(), you would get List<Int32>, which includes the int type parameter.

Exceptions

System.ArgumentNullException

An System.ArgumentNullException will be thrown if the Type inType this method is called on is null.

GetGenericAwareTypeName<T>(T)

Gets the name of the type of the provided instance, including any generic type parameters.

public static string GetGenericAwareTypeName<T>(this T inInstance)

Parameters

inInstance T

The instance for which to get the type name.

Returns

System.String

The name of the type, including any generic type parameters.

Type Parameters

T

The type of the instance (will be inferred).

Examples

For example, if you call typeof(List<int>).FullName, you would get List1, which does not include the int type parameter. However, if you call GetGenericAwareFullTypeName() on an instance of List<int> you would get List<Int32>, which includes the int type parameter.

Exceptions

System.ArgumentNullException

An System.ArgumentNullException will be thrown if the instance inInstance this method is called on is null.

IsInstanceOfType<T>(T, Type)

Determines whether this type is of the expected type.

[Obsolete("Prefer the C# \"is\" operator. This method will be removed in a future version of Existential.")]
public static bool IsInstanceOfType<T>(this T inInstance, Type inExpectedType)

Parameters

inInstance T

The instance to compare with the expected type.

inExpectedType System.Type

The expected type.

Returns

System.Boolean

True if the instance is of the expected type; otherwise false.

Type Parameters

T

The type of the instance.

Exceptions

System.ArgumentNullException

An System.ArgumentNullException will be thrown if the instance inInstance this method is called on is null.