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
TypeValue 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
Returns
EqualsTo(MemberInfo?, MemberInfo?, Type?)
public static bool EqualsTo(this MemberInfo? member1, MemberInfo? member2, Type? declaringType = null)
Parameters
member1
MemberInfomember2
MemberInfodeclaringType
Type
Returns
GetDefaultConstructorEx(Type)
public static ConstructorInfo? GetDefaultConstructorEx(this Type type)
Parameters
type
Type
Returns
GetDefaultValue(Type)
public static object? GetDefaultValue(this Type type)
Parameters
type
Type
Returns
GetDefiningTypes(Type, MemberInfo)
public static IEnumerable<Type> GetDefiningTypes(this Type child, MemberInfo member)
Parameters
child
Typemember
MemberInfo
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
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
type
Type
Returns
GetListItemType(IEnumerable?)
Gets the Type of a list item.
public static Type GetListItemType(this IEnumerable? list)
Parameters
list
IEnumerableA 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
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
TypeType to find member info
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
GetMethodEx(Type, string)
public static MethodInfo? GetMethodEx(this Type type, string name)
Parameters
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, params Type[])
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
type
Type
Returns
GetPropertiesEx(Type)
public static PropertyInfo[] GetPropertiesEx(this Type type)
Parameters
type
Type
Returns
GetPropertyInfo(MethodInfo?)
public static PropertyInfo? GetPropertyInfo(this MethodInfo? method)
Parameters
method
MethodInfo
Returns
GetPublicInstanceMembersEx(Type)
public static MemberInfo[] GetPublicInstanceMembersEx(this Type type)
Parameters
type
Type
Returns
GetPublicInstanceMethodEx(Type, string, 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
type
Type
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
GetTypeCodeEx(Type)
public static TypeCode GetTypeCodeEx(this Type type)
Parameters
type
Type
Returns
IsAnonymous(Type)
public static bool IsAnonymous(this Type type)
Parameters
type
Type
Returns
IsDynamicColumnPropertyEx(MemberInfo)
Determines whether member info is dynamic column property.
public static bool IsDynamicColumnPropertyEx(this MemberInfo memberInfo)
Parameters
memberInfo
MemberInfoThe 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
Returns
IsFieldEx(MemberInfo)
public static bool IsFieldEx(this MemberInfo memberInfo)
Parameters
memberInfo
MemberInfo
Returns
IsFloatType(Type)
public static bool IsFloatType(this Type type)
Parameters
type
Type
Returns
IsGenericEnumerableType(Type)
public static bool IsGenericEnumerableType(this Type type)
Parameters
type
Type
Returns
IsIntegerType(Type)
public static bool IsIntegerType(this Type type)
Parameters
type
Type
Returns
IsMethodEx(MemberInfo)
public static bool IsMethodEx(this MemberInfo memberInfo)
Parameters
memberInfo
MemberInfo
Returns
IsNullable(Type)
Returns true, if type is Nullable<T> type.
public static bool IsNullable(this Type type)
Parameters
Returns
- bool
true
, iftype
represents Nullable<T> type; otherwise,false
.
IsNullableGetValueOrDefault(MemberInfo)
public static bool IsNullableGetValueOrDefault(this MemberInfo member)
Parameters
member
MemberInfo
Returns
IsNullableHasValueMember(MemberInfo)
public static bool IsNullableHasValueMember(this MemberInfo member)
Parameters
member
MemberInfo
Returns
IsNullableValueMember(MemberInfo)
public static bool IsNullableValueMember(this MemberInfo member)
Parameters
member
MemberInfo
Returns
IsPropertyEx(MemberInfo)
public static bool IsPropertyEx(this MemberInfo memberInfo)
Parameters
memberInfo
MemberInfo
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
child
can 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.
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
TypeA Type instance.
checkArrayElementType
boolTrue 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
MemberInfoThe 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
Returns
- bool
true if the
type
derives fromcheck
; 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
ToUnderlying(Type)
Returns the underlying type argument of the specified type.
public static Type ToUnderlying(this Type type)