Show / Hide Table of Contents

Class TypeExtensions

Extension methods for types.

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()
Namespace: Kephas.Reflection
Assembly: Kephas.Core.dll
Syntax
public static class TypeExtensions

Methods

| Improve this Doc View Source

AsRuntimeTypeInfo(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.

| Improve this Doc View Source

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 Source

GetNonNullableType(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.

| Improve this Doc View Source

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

true to strip away the version information (optional).

Returns
Type Description
System.String

The qualified full name.

| Improve this Doc View Source

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

true if the type is a collection; otherwise, false.

| Improve this Doc View Source

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

true if the type is a constructed generic of the provided open generic type, false otherwise.

| Improve this Doc View Source

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

true if the type is a collection; otherwise, false.

| Improve this Doc View Source

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

true if the type is enumerable; otherwise, false.

| Improve this Doc View Source

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

true if the type is nullable; otherwise, false.

| Improve this Doc View Source

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

true if the type is enumerable; otherwise, false.

| Improve this Doc View Source

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 null.

| Improve this Doc View Source

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 null.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 null.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX