Class TypeExtensions
Extension methods for types.
Inheritance
Inherited Members
Namespace: Kephas.Reflection
Assembly: Kephas.Core.dll
Syntax
public static class TypeExtensions
Methods
| Improve this Doc View SourceAsRuntimeTypeInfo(Type)
Gets the IRuntimeTypeInfo for the provided System.Type instance.
Declaration
public static IRuntimeTypeInfo AsRuntimeTypeInfo(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type. |
Returns
Type | Description |
---|---|
IRuntimeTypeInfo | The provided System.Type's associated IRuntimeTypeInfo. |
GetBaseConstructedGenericOf(Type, Type)
A Type extension method that gets the base constructed generic of a provided type. The base can be either an interface or a class.
Declaration
public static Type GetBaseConstructedGenericOf(this Type type, Type openGenericType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to act on. |
System.Type | openGenericType | The open generic type of which constructed generic type is requested. |
Returns
Type | Description |
---|---|
System.Type | The base constructed generic. |
Examples
var type = typeof(string).GetBaseConstructedGenericOf(typeof(IEnumerable<>)); Assert.AreSame(type, typeof(IEnumerable<char>));
| Improve this Doc View SourceGetNonNullableType(Type)
Gets the type wrapped by the System.Nullable<T> or, if the type is not a nullable type, the type itself.
Declaration
public static Type GetNonNullableType(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to be checked. |
Returns
Type | Description |
---|---|
System.Type | A System.Type instance. |
GetQualifiedFullName(Type, Boolean)
Gets the qualified full name of a System.Type. Optionally, strips away the version information.
Declaration
public static string GetQualifiedFullName(this Type type, bool stripVersionInfo = true)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type instance. |
System.Boolean | stripVersionInfo |
|
Returns
Type | Description |
---|---|
System.String | The qualified full name. |
IsCollection(Type)
Gets a value indicating whether the type implements System.Collections.ICollection.
Declaration
public static bool IsCollection(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to check. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsConstructedGenericOf(Type, Type)
Indicates whether the type is a constructed generic of the provided open generic type.
Declaration
public static bool IsConstructedGenericOf(this Type type, Type openGenericType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to check. |
System.Type | openGenericType | The open generic type. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsDictionary(Type)
Gets a value indicating whether the type implements System.Collections.ICollection.
Declaration
public static bool IsDictionary(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to check. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsEnumerable(Type)
Gets a value indicating whether the type implements System.Collections.IEnumerable.
Declaration
public static bool IsEnumerable(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to check. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsNullableType(Type)
Indicates whether the type is an instance of the generic System.Nullable<T> type.
Declaration
public static bool IsNullableType(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to check. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsQueryable(Type)
Gets a value indicating whether the type implements System.Linq.IQueryable.
Declaration
public static bool IsQueryable(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to check. |
Returns
Type | Description |
---|---|
System.Boolean |
|
TryGetCollectionItemType(Type)
Tries to get the item type of the generic collection type.
Declaration
public static Type TryGetCollectionItemType(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The collection type. |
Returns
Type | Description |
---|---|
System.Type | The item type if the provided type is a collection, otherwise |
TryGetEnumerableItemType(Type)
Tries to get the item type of the generic enumerable type.
Declaration
public static Type TryGetEnumerableItemType(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The enumerable type. |
Returns
Type | Description |
---|---|
System.Type | The item type if the provided type is enumerable, otherwise |
TryGetEnumerableItemType(Type, Type)
Gets the generic item type of the enumerable type.
Declaration
public static Type TryGetEnumerableItemType(this Type type, Type enumerableGenericType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The enumerable type. |
System.Type | enumerableGenericType | Type of the enumerable generic. |
Returns
Type | Description |
---|---|
System.Type | The enumerable item type. |
TryGetQueryableItemType(Type)
Tries to get the item type of the generic queryable type.
Declaration
public static Type TryGetQueryableItemType(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The queryable type. |
Returns
Type | Description |
---|---|
System.Type | The item type if the provided type is queryable, otherwise |