Table of Contents

Class TypeExtensions

Namespace
LfrlAnvil.Extensions
Assembly
LfrlAnvil.Core.dll

Contains Type extension methods.

public static class TypeExtensions
Inheritance
TypeExtensions
Inherited Members

Methods

Extends(Type, Type)

Checks whether or not the specified base type is extended by the given type.

[Pure]
public static bool Extends(this Type type, Type baseType)

Parameters

type Type

Source type.

baseType Type

Base type to check.

Returns

bool

true when the given type extends the base type, otherwise false.

ExtendsOpenGeneric(Type, Type)

Checks whether or not the specified open generic base type definition is extended by the given type.

[Pure]
public static bool ExtendsOpenGeneric(this Type type, Type openGenericBaseTypeDefinition)

Parameters

type Type

Source type.

openGenericBaseTypeDefinition Type

Type of an open generic base type definition to check.

Returns

bool

true when the given type extends the base type, otherwise false.

Extends<T>(Type)

Checks whether or not the specified base type is extended by the given type.

[Pure]
public static bool Extends<T>(this Type type)

Parameters

type Type

Source type.

Returns

bool

true when the given type extends the base type, otherwise false.

Type Parameters

T

Base type to check.

FindMember<T>(Type, Func<Type, T?>)

Attempts to find the first non-null member returned by the specified memberSelector in the given type or in all of its ancestors.

[Pure]
public static T? FindMember<T>(this Type type, Func<Type, T?> memberSelector) where T : class

Parameters

type Type

Source type.

memberSelector Func<Type, T>

Member selector invoked for the given type or for all of its ancestors, until it returns a non-null result.

Returns

T

Found member, if it exists, otherwise null.

Type Parameters

T

Member type.

GetAllExtendedGenericDefinitions(Type)

Finds all extensions of all open generic base type definitions in the given type.

[Pure]
public static IEnumerable<Type> GetAllExtendedGenericDefinitions(this Type type)

Parameters

type Type

Source type.

Returns

IEnumerable<Type>

Collection of all extensions of all open generic base type definitions in the given type.

GetAllImplementedGenericDefinitions(Type)

Finds all implementations of all open generic interface definitions in the given type.

[Pure]
public static IEnumerable<Type> GetAllImplementedGenericDefinitions(this Type type)

Parameters

type Type

Source type.

Returns

IEnumerable<Type>

Collection of all implementations of all open generic interface definitions in the given type.

GetDebugString(Type)

Creates a string representation of the provided type.

[Pure]
public static string GetDebugString(this Type type)

Parameters

type Type

Source type.

Returns

string

String representation of the provided type.

GetExtension(Type, Type)

Attempts to find an extension of the specified base type in the given type.

[Pure]
public static Type? GetExtension(this Type type, Type baseType)

Parameters

type Type

Source type.

baseType Type

Base type to get an extension for.

Returns

Type

Base type's extension type when the given type extends it, otherwise null.

GetExtension<T>(Type)

Attempts to find an extension of the specified base type in the given type.

[Pure]
public static Type? GetExtension<T>(this Type type)

Parameters

type Type

Source type.

Returns

Type

Base type's extension type when the given type extends it, otherwise null.

Type Parameters

T

Base type to get an extension for.

GetImplementation(Type, Type)

Attempts to find an implementation of the specified interface in the given type.

[Pure]
public static Type? GetImplementation(this Type type, Type interfaceType)

Parameters

type Type

Source type.

interfaceType Type

Type of an interface to get an implementation for.

Returns

Type

Interface's implementation type when the given type implements it, otherwise null.

GetImplementation<T>(Type)

Attempts to find an implementation of the specified interface in the given type.

[Pure]
public static Type? GetImplementation<T>(this Type type) where T : class

Parameters

type Type

Source type.

Returns

Type

Interface's implementation type when the given type implements it, otherwise null.

Type Parameters

T

Type of an interface to get an implementation for.

GetOpenGenericExtension(Type, Type)

Attempts to find an extension of the specified open generic base type definition in the given type.

[Pure]
public static Type? GetOpenGenericExtension(this Type type, Type openGenericBaseTypeDefinition)

Parameters

type Type

Source type.

openGenericBaseTypeDefinition Type

Open generic base type definition to get an extension for.

Returns

Type

Open generic base type definition's extension type when the given type extends it, otherwise null.

GetOpenGenericImplementations(Type, Type)

Finds all implementations of the specified open generic interface definition in the given type.

[Pure]
public static IEnumerable<Type> GetOpenGenericImplementations(this Type type, Type openGenericInterfaceDefinition)

Parameters

type Type

Source type.

openGenericInterfaceDefinition Type

Type of an open generic interface definition to get implementations for.

Returns

IEnumerable<Type>

Collection of all implementations of the specified open generic interface definition in the given type.

Implements(Type, Type)

Checks whether or not the specified interface is implemented by the given type.

[Pure]
public static bool Implements(this Type type, Type interfaceType)

Parameters

type Type

Source type.

interfaceType Type

Type of an interface to check.

Returns

bool

true when the given type implements the interface, otherwise false.

ImplementsOpenGeneric(Type, Type)

Checks whether or not the specified open generic interface definition is implemented by the given type.

[Pure]
public static bool ImplementsOpenGeneric(this Type type, Type openGenericInterfaceDefinition)

Parameters

type Type

Source type.

openGenericInterfaceDefinition Type

Type of an open generic interface definition to check.

Returns

bool

true when the given type implements the interface, otherwise false.

Implements<T>(Type)

Checks whether or not the specified interface is implemented by the given type.

[Pure]
public static bool Implements<T>(this Type type) where T : class

Parameters

type Type

Source type.

Returns

bool

true when the given type implements the interface, otherwise false.

Type Parameters

T

Type of an interface to check.

IsConstructable(Type)

Checks whether or not the given type is constructable.

[Pure]
public static bool IsConstructable(this Type type)

Parameters

type Type

Type to check.

Returns

bool

true when type is constructable, otherwise false.

Remarks

Type is considered to be constructable when it is not abstract and it is not a generic type definition and it does not contain any generic parameters.