ReflectionHelper

Ecng.Reflection

Provides helper methods for reflection.

プロパティ

CacheEnabled
public static bool CacheEnabled { get; set; }
value = ReflectionHelper.CacheEnabled
ReflectionHelper.CacheEnabled = value

Is cache enabled.

ProxyTypes
public static IDictionary<Type, Type> ProxyTypes { get; }
value = ReflectionHelper.ProxyTypes

Gets the proxy types.

メソッド

ClearCache
public static void ClearCache()
ReflectionHelper.ClearCache()

Clear cache.

FilterMembers``1
public static IEnumerable<T> FilterMembers<T>(IEnumerable<T> members, bool useInheritance, bool? isSetter, Type[] additionalTypes)
result = ReflectionHelper.FilterMembers(members, useInheritance, isSetter, additionalTypes)

Filters members based on inheritance, setter indication, and additional type parameters.

members
The collection of members.
useInheritance
True to use inheritance comparison.
isSetter
Indicates if filtering by setter should be applied.
additionalTypes
Additional types to match.

戻り値: An enumerable of filtered members.

FilterMembers``1
public static IEnumerable<T> FilterMembers<T>(IEnumerable<T> members, bool? isSetter, Type[] additionalTypes)
result = ReflectionHelper.FilterMembers(members, isSetter, additionalTypes)

Filters members based on setter indication and additional type parameters.

members
The collection of members.
isSetter
Indicates if filtering by setter should be applied.
additionalTypes
Additional types to match.

戻り値: An enumerable of filtered members.

FindImplementations``1
public static IEnumerable<Type> FindImplementations<T>(Assembly assembly, bool showObsolete, bool showNonPublic, bool showNonBrowsable, Func<Type, bool> extraFilter)
result = ReflectionHelper.FindImplementations(assembly, showObsolete, showNonPublic, showNonBrowsable, extraFilter)

Find all implementation in the specified assembly.

assembly
Assembly in where types scan required.
showObsolete
Show types marked as obsolete.
showNonPublic
Show non public types.
showNonBrowsable
Show types marked as non browsable.
extraFilter
Extra filter.

戻り値: Found types.

GetAccessorOwner
public static MemberInfo GetAccessorOwner(MethodInfo method)
result = ReflectionHelper.GetAccessorOwner(method)

Gets the member that owns the specified accessor method.

method
Accessor method.

戻り値: The owner member or null if not found.

GetGenericType
public static Type GetGenericType(Type targetType, Type genericType)
result = ReflectionHelper.GetGenericType(targetType, genericType)

Gets the generic type from the target type based on the provided generic type definition.

targetType
The target type.
genericType
The generic type definition.

戻り値: The found generic type or null if not found.

GetGenericTypeArg
public static Type GetGenericTypeArg(Type targetType, Type genericType, int index)
result = ReflectionHelper.GetGenericTypeArg(targetType, genericType, index)

Gets the specific generic argument type from the target type.

targetType
The target type.
genericType
The generic type definition.
index
The index of the generic argument.

戻り値: The generic argument type.

GetIndexer
public static PropertyInfo GetIndexer(Type type, Type[] additionalTypes)
result = ReflectionHelper.GetIndexer(type, additionalTypes)

Gets the default indexer property of the specified type.

type
The type to search.
additionalTypes
Additional types to match.

戻り値: The PropertyInfo of the indexer.

GetIndexers
public static PropertyInfo[] GetIndexers(Type type, Type[] additionalTypes)
result = ReflectionHelper.GetIndexers(type, additionalTypes)

Gets all indexer properties of the specified type.

type
The type to search.
additionalTypes
Additional types to match.

戻り値: An array with the indexer properties.

GetIndexerTypes
public static IEnumerable<Type> GetIndexerTypes(PropertyInfo property)
result = ReflectionHelper.GetIndexerTypes(property)

Gets the types of the parameters of the indexer property.

property
The indexer property.

戻り値: An enumerable of parameter types.

GetInvokeMethod
public static MethodInfo GetInvokeMethod(Type delegType)
result = ReflectionHelper.GetInvokeMethod(delegType)

Gets the invoke method from the specified delegate type.

delegType
The delegate type.

戻り値: The MethodInfo representing the Invoke method.

GetItemType
public static Type GetItemType(Type collectionType)
result = ReflectionHelper.GetItemType(collectionType)

Gets the item type for a collection type.

collectionType
The collection type.

戻り値: The item type contained in the collection.

GetMembers``1
public static T[] GetMembers<T>(Type type, Type[] additionalTypes)
result = ReflectionHelper.GetMembers(type, additionalTypes)

Gets members from the type that match the additional types.

type
The target type.
additionalTypes
Additional types to match.

戻り値: An array of matched members.

GetMembers``1
public static T[] GetMembers<T>(Type type, BindingFlags flags, Type[] additionalTypes)
result = ReflectionHelper.GetMembers(type, flags, additionalTypes)

Gets members with specified binding flags that match the additional types.

type
The target type.
flags
Binding flags for lookup.
additionalTypes
Additional types to match.

戻り値: An array of matched members.

GetMembers``1
public static T[] GetMembers<T>(Type type, BindingFlags flags, bool inheritance, Type[] additionalTypes)
result = ReflectionHelper.GetMembers(type, flags, inheritance, additionalTypes)

Gets members with an option for inheritance and additional types matching.

type
The target type.
flags
Binding flags for lookup.
inheritance
True to include inherited members.
additionalTypes
Additional types to match.

戻り値: An array of matched members.

GetMembers``1
public static T[] GetMembers<T>(Type type, BindingFlags flags, bool inheritance, string memberName, bool? isSetter, Type[] additionalTypes)
result = ReflectionHelper.GetMembers(type, flags, inheritance, memberName, isSetter, additionalTypes)

Gets members by name with options for inheritance, setter indication, and additional types matching.

type
The target type.
flags
Binding flags for lookup.
inheritance
True to include inherited members.
memberName
The member name.
isSetter
Indicates if the member is a setter.
additionalTypes
Additional types to match.

戻り値: An array of matched members.

GetMemberType
public static Type GetMemberType(MemberInfo member)
result = ReflectionHelper.GetMemberType(member)

Gets the type associated with the member.

member
The member info.

戻り値: The type of the member.

GetMember``1
public static T GetMember<T>(Type type, Type[] additionalTypes)
result = ReflectionHelper.GetMember(type, additionalTypes)

Gets a constructor member info from the specified type.

type
The target type.
additionalTypes
Additional types to match.

戻り値: The member info.

GetMember``1
public static T GetMember<T>(Type type, string memberName, Type[] additionalTypes)
result = ReflectionHelper.GetMember(type, memberName, additionalTypes)

Gets a member info by name from the specified type.

type
The target type.
memberName
The name of the member.
additionalTypes
Additional types to match.

戻り値: The member info.

GetMember``1
public static T GetMember<T>(Type type, string memberName, BindingFlags flags, bool? isSetter, Type[] additionalTypes)
result = ReflectionHelper.GetMember(type, memberName, flags, isSetter, additionalTypes)

Gets a member info by name with specified binding flags.

type
The target type.
memberName
The member name.
flags
Binding flags to use for lookup.
isSetter
Indicates if it's a setter.
additionalTypes
Additional types to match.

戻り値: The member info.

GetParameterTypes
public static ValueTuple<ParameterInfo, Type>[] GetParameterTypes(MethodBase method, bool removeRef)
result = ReflectionHelper.GetParameterTypes(method, removeRef)

Gets the parameter types for the specified method.

method
The method base.
removeRef
True to remove reference type wrappers.

戻り値: An array of tuples with parameter info and its type.

GetParameterTypes
public static ValueTuple<ParameterInfo, Type>[] GetParameterTypes(MethodBase method)
result = ReflectionHelper.GetParameterTypes(method)

Gets the parameter types for the specified method.

method
The method base.

戻り値: An array of tuples with parameter info and its type.

IsAbstract
public static bool IsAbstract(MemberInfo member)
result = ReflectionHelper.IsAbstract(member)

Determines whether the specified member is abstract.

member
The member info.

戻り値: True if the member is abstract; otherwise, false.

IsAssembly
public static bool IsAssembly(string dllName)
result = ReflectionHelper.IsAssembly(dllName)

Determines whether the specified file contains a valid assembly.

dllName
Assembly file name.

戻り値: True if the file is an assembly; otherwise, false.

IsCollection
public static bool IsCollection(Type type)
result = ReflectionHelper.IsCollection(type)

Determines whether the specified type is a collection.

type
The type to check.

戻り値: True if the type is a collection; otherwise, false.

IsIndexer
public static bool IsIndexer(PropertyInfo property)
result = ReflectionHelper.IsIndexer(property)

Determines whether the specified property is an indexer.

property
The property info.

戻り値: True if the property is an indexer; otherwise, false.

IsIndexer
public static bool IsIndexer(MemberInfo member)
result = ReflectionHelper.IsIndexer(member)

Determines whether the specified member is an indexer.

member
The member info.

戻り値: True if the member is an indexer; otherwise, false.

IsMatch
public static bool IsMatch(MethodBase methodInfo, BindingFlags bindingFlags)
result = ReflectionHelper.IsMatch(methodInfo, bindingFlags)

Determines the method is match.

methodInfo
The method info.
bindingFlags
BindingFlags

戻り値: Operations result.

IsMatch
public static bool IsMatch(FieldInfo field, BindingFlags bindingFlags)
result = ReflectionHelper.IsMatch(field, bindingFlags)

Determines the field is match.

field
The field.
bindingFlags
BindingFlags

戻り値: Operations result.

IsMatch
public static bool IsMatch(PropertyInfo propertyInfo, BindingFlags bindingFlags)
result = ReflectionHelper.IsMatch(propertyInfo, bindingFlags)

Determines the property is match.

propertyInfo
The property info.
bindingFlags
BindingFlags

戻り値: Operations result.

IsModifiable
public static bool IsModifiable(PropertyInfo pi)
result = ReflectionHelper.IsModifiable(pi)

Determines the property is modifiable.

pi
The property info.

戻り値: Operations result.

IsOutput
public static bool IsOutput(ParameterInfo param)
result = ReflectionHelper.IsOutput(param)

Determines whether the specified parameter is an output parameter.

param
The parameter info.

戻り値: True if the parameter is output; otherwise, false.

IsOverloadable
public static bool IsOverloadable(MemberInfo member)
result = ReflectionHelper.IsOverloadable(member)

Determines whether the specified member is overloadable.

member
The member info.

戻り値: True if the member is overloadable; otherwise, false.

IsParams
public static bool IsParams(ParameterInfo pi)
result = ReflectionHelper.IsParams(pi)

Determines whether the specified parameter is a params array.

pi
The parameter info.

戻り値: True if the parameter is marked as params; otherwise, false.

IsRequiredType
public static bool IsRequiredType(Type type, Type required)
result = ReflectionHelper.IsRequiredType(type, required)

Is type compatible.

type
Type.
required
Required type.

戻り値: Check result.

IsRequiredType``1
public static bool IsRequiredType<T>(Type type)
result = ReflectionHelper.IsRequiredType(type)

Is type compatible.

type
Type.

戻り値: Check result.

IsRuntimeType
public static bool IsRuntimeType(Type type)
result = ReflectionHelper.IsRuntimeType(type)

Determines whether the specified type is a runtime type.

type
The type to check.

戻り値: True if the type inherits from Type; otherwise, false.

IsStatic
public static bool IsStatic(MemberInfo member)
result = ReflectionHelper.IsStatic(member)

Determines whether the specified member is static.

member
The member info.

戻り値: True if the member is static; otherwise, false.

IsVirtual
public static bool IsVirtual(MemberInfo member)
result = ReflectionHelper.IsVirtual(member)

Determines whether the specified member is virtual.

member
The member info.

戻り値: True if the member is virtual; otherwise, false.

Make
public static MethodInfo Make(MethodInfo method, Type[] types)
result = ReflectionHelper.Make(method, types)

Constructs a generic method with the provided type arguments.

method
Generic method definition.
types
Generic argument types.

戻り値: The constructed generic method.

MakePropertyName
public static string MakePropertyName(string accessorName)
result = ReflectionHelper.MakePropertyName(accessorName)

Makes the property name from the accessor name.

accessorName
The accessor name.

戻り値: The property name.

MemberIs
public static bool MemberIs(MemberInfo member, MemberTypes[] types)
result = ReflectionHelper.MemberIs(member, types)

Determines whether the member has one of the specified member types.

member
The member info.
types
The member types to check.

戻り値: True if the member matches one of the types; otherwise, false.

OrderByDeclaration``1
public static IEnumerable<TMember> OrderByDeclaration<TMember>(IEnumerable<TMember> members)
result = ReflectionHelper.OrderByDeclaration(members)

Order the members by declaration.

members
Members.

戻り値: Ordered members.

SetValue``1
public static void SetValue<T>(Lazy<T> lazy, T value)
ReflectionHelper.SetValue(lazy, value)

Sets the value of a Lazy instance by patching its internal fields.

lazy
The lazy instance.
value
The value to set.
TryFindType
public static Type TryFindType(IEnumerable<Type> types, Func<Type, bool> isTypeCompatible, string typeName)
result = ReflectionHelper.TryFindType(types, isTypeCompatible, typeName)

Try find type.

types
Types.
isTypeCompatible
Is type compatible.
typeName
The type name.

戻り値: The found type.

VerifyAssembly
public static AssemblyName VerifyAssembly(string dllName)
result = ReflectionHelper.VerifyAssembly(dllName)

Tries to read the assembly name from the specified file.

dllName
Assembly file name.

戻り値: The assembly name or null if the file is not a valid assembly.

フィールド

AddPrefix
public const string AddPrefix
value = ReflectionHelper.AddPrefix

Adders prefix.

AllInstanceMembers
public const BindingFlags AllInstanceMembers
value = ReflectionHelper.AllInstanceMembers

Binding flags for all instance members.

AllMembers
public const BindingFlags AllMembers
value = ReflectionHelper.AllMembers

Binding flags for all members.

AllStaticMembers
public const BindingFlags AllStaticMembers
value = ReflectionHelper.AllStaticMembers

Binding flags for all static members.

GetPrefix
public const string GetPrefix
value = ReflectionHelper.GetPrefix

Getters prefix.

IndexerName
public const string IndexerName
value = ReflectionHelper.IndexerName

The name for indexer members.

Members
public const AttributeTargets Members
value = ReflectionHelper.Members

Attribute targets for fields and properties.

RemovePrefix
public const string RemovePrefix
value = ReflectionHelper.RemovePrefix

Removers prefix.

SetPrefix
public const string SetPrefix
value = ReflectionHelper.SetPrefix

Setters prefix.

Types
public const AttributeTargets Types
value = ReflectionHelper.Types

Attribute targets for classes, structs, and interfaces.