Table of Contents

Class ReflectionExtensions

Namespace
LinqToDB.Internal.Extensions
Assembly
linq2db.dll
public static class ReflectionExtensions
Inheritance
object
ReflectionExtensions

Methods

CanConvertTo(Type, Type)

public static bool CanConvertTo(this Type fromType, Type toType)

Parameters

fromType Type
toType Type

Returns

bool

EqualsTo(MemberInfo?, MemberInfo?, Type?)

public static bool EqualsTo(this MemberInfo? member1, MemberInfo? member2, Type? declaringType = null)

Parameters

member1 MemberInfo
member2 MemberInfo
declaringType Type

Returns

bool

GetDefaultConstructorEx(Type)

public static ConstructorInfo? GetDefaultConstructorEx(this Type type)

Parameters

type Type

Returns

ConstructorInfo

GetDefaultValue(Type)

public static object? GetDefaultValue(this Type type)

Parameters

type Type

Returns

object

GetDefiningTypes(Type, MemberInfo)

public static IEnumerable<Type> GetDefiningTypes(this Type child, MemberInfo member)

Parameters

child Type
member MemberInfo

Returns

IEnumerable<Type>

GetEventEx(Type, string)

public static EventInfo? GetEventEx(this Type type, string eventName)

Parameters

type Type
eventName string

Returns

EventInfo

GetGenericArguments(Type, Type)

Returns an array of Type objects that represent the type arguments of a generic type or the type parameters of a generic type definition.

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

Parameters

type Type

A Type instance.

baseType Type

Non generic base type.

Returns

Type[]

An array of Type objects that represent the type arguments of a generic type. Returns an empty array if the current type is not a generic type.

GetGenericType(Type, Type)

public static Type? GetGenericType(this Type genericType, Type type)

Parameters

genericType Type
type Type

Returns

Type

GetGenericTypes(Type, Type)

public static IEnumerable<Type> GetGenericTypes(this Type genericType, Type type)

Parameters

genericType Type
type Type

Returns

IEnumerable<Type>

GetImplementation(Type, MemberInfo)

public static MemberInfo? GetImplementation(this Type concreteType, MemberInfo interfaceMember)

Parameters

concreteType Type
interfaceMember MemberInfo

Returns

MemberInfo

GetInstanceMemberEx(Type, string)

public static MemberInfo[] GetInstanceMemberEx(this Type type, string name)

Parameters

type Type
name string

Returns

MemberInfo[]

GetInterfaceMapEx(Type, Type)

public static InterfaceMapping GetInterfaceMapEx(this Type type, Type interfaceType)

Parameters

type Type
interfaceType Type

Returns

InterfaceMapping

GetItemType(Type?)

public static Type? GetItemType(this Type? type)

Parameters

type Type

Returns

Type

GetListItemType(Type)

Gets the Type of list item.

public static Type GetListItemType(this Type listType)

Parameters

listType Type

A Type instance.

Returns

Type

The Type instance that represents the exact runtime type of list item.

GetMemberEx(Type, MemberInfo)

Returns MemberInfo of type described by memberInfo It us useful when member's declared and reflected types are not the same.

public static MemberInfo? GetMemberEx(this Type type, MemberInfo memberInfo)

Parameters

type Type

Type to find member info

memberInfo MemberInfo

MemberInfo

Returns

MemberInfo

MemberInfo or null

Remarks

This method searches only properties, fields and methods

GetMemberType(MemberInfo)

public static Type GetMemberType(this MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

Returns

Type

GetMethodEx(Type, string)

public static MethodInfo? GetMethodEx(this Type type, string name)

Parameters

type Type
name string

Returns

MethodInfo

GetMethodEx(Type, string, int, params Type[])

Gets generic method.

public static MethodInfo? GetMethodEx(this Type type, string name, int genericParametersCount, params Type[] types)

Parameters

type Type
name string
genericParametersCount int
types Type[]

Returns

MethodInfo

GetMethodEx(Type, string, params Type[])

public static MethodInfo? GetMethodEx(this Type type, string name, params Type[] types)

Parameters

type Type
name string
types Type[]

Returns

MethodInfo

GetMethodEx(Type, Type, string, params Type[])

Gets method by name, input parameters and return type. Usefull for method overloads by return type, like op_Explicit/op_Implicit conversions.

public static MethodInfo? GetMethodEx(this Type type, Type returnType, string name, params Type[] types)

Parameters

type Type
returnType Type
name string
types Type[]

Returns

MethodInfo

GetNonPublicPropertiesEx(Type)

public static PropertyInfo[] GetNonPublicPropertiesEx(this Type type)

Parameters

type Type

Returns

PropertyInfo[]

GetPropertiesEx(Type)

public static PropertyInfo[] GetPropertiesEx(this Type type)

Parameters

type Type

Returns

PropertyInfo[]

GetPropertyInfo(MethodInfo?)

public static PropertyInfo? GetPropertyInfo(this MethodInfo? method)

Parameters

method MethodInfo

Returns

PropertyInfo

GetPublicInstanceMethodEx(Type, string, params Type[])

public static MethodInfo? GetPublicInstanceMethodEx(this Type type, string name, params Type[] types)

Parameters

type Type
name string
types Type[]

Returns

MethodInfo

GetPublicInstanceValueMembers(Type)

public static MemberInfo[] GetPublicInstanceValueMembers(this Type type)

Parameters

type Type

Returns

MemberInfo[]

GetPublicMemberEx(Type, string)

public static MemberInfo[] GetPublicMemberEx(this Type type, string name)

Parameters

type Type
name string

Returns

MemberInfo[]

GetStaticMembersEx(Type, string)

public static MemberInfo[] GetStaticMembersEx(this Type type, string name)

Parameters

type Type
name string

Returns

MemberInfo[]

IsAnonymous(Type)

public static bool IsAnonymous(this Type type)

Parameters

type Type

Returns

bool

IsEnumerableType(Type, Type)

public static bool IsEnumerableType(this Type type, Type elementType)

Parameters

type Type
elementType Type

Returns

bool

IsGenericEnumerableType(Type)

public static bool IsGenericEnumerableType(this Type type)

Parameters

type Type

Returns

bool

IsNullableGetValueOrDefault(MemberInfo)

public static bool IsNullableGetValueOrDefault(this MemberInfo member)

Parameters

member MemberInfo

Returns

bool

IsNullableHasValueMember(MemberInfo)

public static bool IsNullableHasValueMember(this MemberInfo member)

Parameters

member MemberInfo

Returns

bool

IsNullableValueMember(MemberInfo)

public static bool IsNullableValueMember(this MemberInfo member)

Parameters

member MemberInfo

Returns

bool

IsSameOrParentOf(Type, Type)

Determines whether the specified types are considered equal.

public static bool IsSameOrParentOf(this Type parent, Type child)

Parameters

parent Type

A Type instance.

child Type

A type possible derived from the parent type

Returns

bool

True, when an object instance of the type child can be used as an object of the type parent; otherwise, false.

Remarks

Note that nullable types does not have a parent-child relation to it's underlying type. For example, the 'int?' type (nullable int) and the 'int' type aren't a parent and it's child.

IsSubClassOf(Type, Type)

Determines whether the type derives from the specified check.

public static bool IsSubClassOf(this Type type, Type check)

Parameters

type Type

The type to test.

check Type

The type to compare with.

Returns

bool

true if the type derives from check; otherwise, false.

Remarks

This method also returns false if type and the check are equal.

ToUnderlying(Type)

Returns the underlying type argument of the specified type.

public static Type ToUnderlying(this Type type)

Parameters

type Type

A Type instance.

Returns

Type