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
Returns
- bool
true when the given
typeextends 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
typeTypeSource type.
openGenericBaseTypeDefinitionTypeType of an open generic base type definition to check.
Returns
- bool
true when the given
typeextends 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
typeTypeSource type.
Returns
- bool
true when the given
typeextends the base type, otherwise false.
Type Parameters
TBase 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
typeTypeSource type.
memberSelectorFunc<Type, T>Member selector invoked for the given
typeor for all of its ancestors, until it returns a non-null result.
Returns
- T
Found member, if it exists, otherwise null.
Type Parameters
TMember 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
typeTypeSource 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
typeTypeSource 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
typeTypeSource 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
Returns
- Type
Base type's extension type when the given
typeextends 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
typeTypeSource type.
Returns
- Type
Base type's extension type when the given
typeextends it, otherwise null.
Type Parameters
TBase 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
Returns
- Type
Interface's implementation type when the given
typeimplements 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
typeTypeSource type.
Returns
- Type
Interface's implementation type when the given
typeimplements it, otherwise null.
Type Parameters
TType 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
typeTypeSource type.
openGenericBaseTypeDefinitionTypeOpen generic base type definition to get an extension for.
Returns
- Type
Open generic base type definition's extension type when the given
typeextends 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
typeTypeSource type.
openGenericInterfaceDefinitionTypeType 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
Returns
- bool
true when the given
typeimplements 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
typeTypeSource type.
openGenericInterfaceDefinitionTypeType of an open generic interface definition to check.
Returns
- bool
true when the given
typeimplements 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
typeTypeSource type.
Returns
- bool
true when the given
typeimplements the interface, otherwise false.
Type Parameters
TType 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
typeTypeType to check.
Returns
- bool
true when
typeis 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.