Class ReflectionExtensions
- Namespace
- LinqToDB.Internal.Extensions
- Assembly
- linq2db.dll
public static class ReflectionExtensions
- Inheritance
-
objectReflectionExtensions
Methods
CanConvertTo(Type, Type)
public static bool CanConvertTo(this Type fromType, Type toType)
Parameters
Returns
EqualsTo(MemberInfo?, MemberInfo?, Type?)
public static bool EqualsTo(this MemberInfo? member1, MemberInfo? member2, Type? declaringType = null)
Parameters
member1MemberInfomember2MemberInfodeclaringTypeType
Returns
GetConstructorCoercing(Type, params Type[])
Gets public instance constructor by parameter types using DefaultBinder rules, which also match parameters
that need a value conversion (e.g. byte to int, T to Nullable<T>).
The caller must convert arguments to the returned constructor's parameter types before building an expression.
public static ConstructorInfo? GetConstructorCoercing(this Type type, params Type[] types)
Parameters
Returns
GetConstructorEx(Type, BindingFlags, params Type[])
Gets constructor by binding flags and parameter types. Parameter types follow the rules of GetMethodEx(Type, string, BindingFlags, params Type[]).
public static ConstructorInfo? GetConstructorEx(this Type type, BindingFlags bindingFlags, params Type[] types)
Parameters
typeTypebindingFlagsBindingFlagstypesType[]
Returns
GetConstructorEx(Type, params Type[])
Gets public instance constructor by parameter types. Parameter types follow the rules of GetMethodEx(Type, string, BindingFlags, params Type[]).
public static ConstructorInfo? GetConstructorEx(this Type type, params Type[] types)
Parameters
Returns
GetDefaultConstructorEx(Type)
public static ConstructorInfo? GetDefaultConstructorEx(this Type type)
Parameters
typeType
Returns
GetDefaultValue(Type)
public static object? GetDefaultValue(this Type type)
Parameters
typeType
Returns
- object
GetDefiningTypes(Type, MemberInfo)
public static IEnumerable<Type> GetDefiningTypes(this Type child, MemberInfo member)
Parameters
childTypememberMemberInfo
Returns
GetEventEx(Type, string)
public static EventInfo? GetEventEx(this Type type, string eventName)
Parameters
Returns
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
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
Returns
GetGenericTypes(Type, Type)
public static IEnumerable<Type> GetGenericTypes(this Type genericType, Type type)
Parameters
Returns
GetImplementation(Type, MemberInfo)
public static MemberInfo? GetImplementation(this Type concreteType, MemberInfo interfaceMember)
Parameters
concreteTypeTypeinterfaceMemberMemberInfo
Returns
GetInstanceMemberEx(Type, string)
public static MemberInfo[] GetInstanceMemberEx(this Type type, string name)
Parameters
Returns
GetInterfaceMapEx(Type, Type)
public static InterfaceMapping GetInterfaceMapEx(this Type type, Type interfaceType)
Parameters
Returns
GetItemType(Type?)
public static Type? GetItemType(this Type? type)
Parameters
typeType
Returns
GetListItemType(Type)
Gets the Type of list item.
public static Type GetListItemType(this Type listType)
Parameters
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
typeTypeType to find member info
memberInfoMemberInfo
Returns
- MemberInfo
MemberInfo or null
Remarks
This method searches only properties, fields and methods.
A method is matched like GetMethodCoercing(Type, string, params Type[]): a base or interface overload whose parameters the arguments convert to
(Derived.M(int) → Base.M(long)) is found, so its mapping attributes and Expressions registrations apply.
GetMemberType(MemberInfo)
public static Type GetMemberType(this MemberInfo memberInfo)
Parameters
memberInfoMemberInfo
Returns
GetMethodCoercing(Type, string, params Type[])
Gets method by name and parameter types using DefaultBinder rules, which also match parameters
that need a value conversion (e.g. byte to int, T to Nullable<T>).
The caller must convert arguments to the returned method's parameter types before building an expression.
public static MethodInfo? GetMethodCoercing(this Type type, string name, params Type[] types)
Parameters
Returns
GetMethodEx(Type, string)
public static MethodInfo? GetMethodEx(this Type type, string name)
Parameters
Returns
GetMethodEx(Type, string, int, BindingFlags, params Type[])
Gets method by name, generic parameters count, binding flags and parameter types.
genericParametersCount = 0 matches only non-generic methods.
Parameter types follow the rules of GetMethodEx(Type, string, BindingFlags, params Type[]); a parameter whose type contains generic parameters
(T, T[], IEnumerable<T>) matches any requested type and counts as identical.
Unlike GetMethodEx(Type, string, int, params Type[]), which returns the first exact match of a generic method,
an identical match wins over a reference-assignable one, and a candidate is skipped when another one declared on the same or a more derived type
is more specific (each parameter type is the same as or assignable to its own) or hides it with the same parameter types.
Remaining ties throw AmbiguousMatchException.
public static MethodInfo? GetMethodEx(this Type type, string name, int genericParametersCount, BindingFlags bindingFlags, params Type[] types)
Parameters
typeTypenamestringgenericParametersCountintbindingFlagsBindingFlagstypesType[]
Returns
GetMethodEx(Type, string, int, params Type[])
Gets generic method.
public static MethodInfo? GetMethodEx(this Type type, string name, int genericParametersCount, params Type[] types)
Parameters
Returns
GetMethodEx(Type, string, BindingFlags, params Type[])
Gets method by name, binding flags and parameter types.
Only matches a method that Expression can call with arguments of types
without conversion: each parameter type is identical to the requested type, or both are reference types and the parameter type is assignable from it
(boxing, numeric widening and Nullable<T> wrapping are rejected).
public static MethodInfo? GetMethodEx(this Type type, string name, BindingFlags bindingFlags, params Type[] types)
Parameters
typeTypenamestringbindingFlagsBindingFlagstypesType[]
Returns
GetMethodEx(Type, string, params Type[])
Gets public or non-public, instance or static method by name and parameter types.
Only matches a method that Expression can call with arguments of types
without conversion: each parameter type is identical to the requested type, or both are reference types and the parameter type is assignable from it
(boxing, numeric widening and Nullable<T> wrapping are rejected).
public static MethodInfo? GetMethodEx(this Type type, string name, params Type[] types)
Parameters
Returns
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
Returns
GetNonPublicPropertiesEx(Type)
public static PropertyInfo[] GetNonPublicPropertiesEx(this Type type)
Parameters
typeType
Returns
GetPropertiesEx(Type)
public static PropertyInfo[] GetPropertiesEx(this Type type)
Parameters
typeType
Returns
GetPropertyInfo(MethodInfo?)
public static PropertyInfo? GetPropertyInfo(this MethodInfo? method)
Parameters
methodMethodInfo
Returns
GetPublicInstanceMethodEx(Type, string, params Type[])
Gets public instance method by name and parameter types. Parameter types follow the rules of GetMethodEx(Type, string, BindingFlags, params Type[]).
public static MethodInfo? GetPublicInstanceMethodEx(this Type type, string name, params Type[] types)
Parameters
Returns
GetPublicInstanceValueMembers(Type)
public static MemberInfo[] GetPublicInstanceValueMembers(this Type type)
Parameters
typeType
Returns
GetPublicMemberEx(Type, string)
public static MemberInfo[] GetPublicMemberEx(this Type type, string name)
Parameters
Returns
GetStaticMembersEx(Type, string)
public static MemberInfo[] GetStaticMembersEx(this Type type, string name)
Parameters
Returns
IsAnonymous(Type)
public static bool IsAnonymous(this Type type)
Parameters
typeType
Returns
IsEnumerableType(Type, Type)
public static bool IsEnumerableType(this Type type, Type elementType)
Parameters
Returns
IsGenericEnumerableType(Type)
public static bool IsGenericEnumerableType(this Type type)
Parameters
typeType
Returns
IsNullableGetValueOrDefault(MemberInfo)
public static bool IsNullableGetValueOrDefault(this MemberInfo member)
Parameters
memberMemberInfo
Returns
IsNullableHasValueMember(MemberInfo)
public static bool IsNullableHasValueMember(this MemberInfo member)
Parameters
memberMemberInfo
Returns
IsNullableValueMember(MemberInfo)
public static bool IsNullableValueMember(this MemberInfo member)
Parameters
memberMemberInfo
Returns
IsSameOrParentOf(Type, Type)
Determines whether the specified types are considered equal.
public static bool IsSameOrParentOf(this Type parent, Type child)
Parameters
Returns
- bool
True, when an object instance of the type
childcan be used as an object of the typeparent; 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
Returns
- bool
true if the
typederives fromcheck; 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)