Table of Contents

Class ReflectionExtensions

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

Methods

AsNullable(Type)

Wraps type into Nullable<T> class.

public static Type AsNullable(this Type type)

Parameters

type Type

Value type to wrap. Must be value type (except Nullable<T> itself).

Returns

Type

Type, wrapped by Nullable<T>.

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

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(IEnumerable?)

Gets the Type of a list item.

public static Type GetListItemType(this IEnumerable? list)

Parameters

list IEnumerable

A object instance.

Returns

Type

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

GetListItemType(Type)

Gets the Type of a 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 a 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

GetPublicInstanceMembersEx(Type)

public static MemberInfo[] GetPublicInstanceMembersEx(this Type type)

Parameters

type Type

Returns

MemberInfo[]

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[]

GetTypeCodeEx(Type)

public static TypeCode GetTypeCodeEx(this Type type)

Parameters

type Type

Returns

TypeCode

IsAnonymous(Type)

public static bool IsAnonymous(this Type type)

Parameters

type Type

Returns

bool

IsDynamicColumnPropertyEx(MemberInfo)

Determines whether member info is dynamic column property.

public static bool IsDynamicColumnPropertyEx(this MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

The member information.

Returns

bool

true if member info is dynamic column property; otherwise, false.

IsEnumerableTType(Type, Type)

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

Parameters

type Type
elementType Type

Returns

bool

IsFieldEx(MemberInfo)

public static bool IsFieldEx(this MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

Returns

bool

IsFloatType(Type)

public static bool IsFloatType(this Type type)

Parameters

type Type

Returns

bool

IsGenericEnumerableType(Type)

public static bool IsGenericEnumerableType(this Type type)

Parameters

type Type

Returns

bool

IsIntegerType(Type)

public static bool IsIntegerType(this Type type)

Parameters

type Type

Returns

bool

IsMethodEx(MemberInfo)

public static bool IsMethodEx(this MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

Returns

bool

IsNullable(Type)

Returns true, if type is Nullable<T> type.

public static bool IsNullable(this Type type)

Parameters

type Type

A Type instance.

Returns

bool

true, if type represents Nullable<T> type; otherwise, false.

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

IsPropertyEx(MemberInfo)

public static bool IsPropertyEx(this MemberInfo memberInfo)

Parameters

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

IsScalar(Type, bool)

Gets a value indicating whether a type can be used as a db primitive.

public static bool IsScalar(this Type type, bool checkArrayElementType = true)

Parameters

type Type

A Type instance.

checkArrayElementType bool

True if needed to check element type for arrays

Returns

bool

True, if the type parameter is a primitive type; otherwise, False.

Remarks

string. Stream. XmlReader. XmlDocument. are specially handled by the library and, therefore, can be treated as scalar types.

IsSqlPropertyMethodEx(MemberInfo)

Determines whether member info represent a Sql.Property method.

public static bool IsSqlPropertyMethodEx(this MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

The member information.

Returns

bool

true if member info is Sql.Property method; otherwise, false.

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.

ToNullableUnderlying(Type)

public static Type ToNullableUnderlying(this Type type)

Parameters

type Type

Returns

Type

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