ReflectionHelper
Provides helper methods for reflection.
Propriedades
public static bool CacheEnabled { get; set; }
value = ReflectionHelper.CacheEnabled
ReflectionHelper.CacheEnabled = value
Is cache enabled.
public static IDictionary<Type, Type> ProxyTypes { get; }
value = ReflectionHelper.ProxyTypes
Gets the proxy types.
Métodos
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.
Retorna: An enumerable of filtered members.
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.
Retorna: An enumerable of filtered members.
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.
Retorna: Found types.
public static MemberInfo GetAccessorOwner(MethodInfo method)
result = ReflectionHelper.GetAccessorOwner(method)
Gets the member that owns the specified accessor method.
- method
- Accessor method.
Retorna: The owner member or null if not found.
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.
Retorna: The found generic type or null if not found.
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.
Retorna: The generic argument type.
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.
Retorna: The PropertyInfo of the indexer.
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.
Retorna: An array with the indexer properties.
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.
Retorna: An enumerable of parameter types.
public static MethodInfo GetInvokeMethod(Type delegType)
result = ReflectionHelper.GetInvokeMethod(delegType)
Gets the invoke method from the specified delegate type.
- delegType
- The delegate type.
Retorna: The MethodInfo representing the Invoke method.
public static Type GetItemType(Type collectionType)
result = ReflectionHelper.GetItemType(collectionType)
Gets the item type for a collection type.
- collectionType
- The collection type.
Retorna: The item type contained in the collection.
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.
Retorna: An array of matched members.
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.
Retorna: An array of matched members.
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.
Retorna: An array of matched members.
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.
Retorna: An array of matched members.
public static Type GetMemberType(MemberInfo member)
result = ReflectionHelper.GetMemberType(member)
Gets the type associated with the member.
- member
- The member info.
Retorna: The type of the member.
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.
Retorna: The member info.
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.
Retorna: The member info.
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.
Retorna: The member info.
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.
Retorna: An array of tuples with parameter info and its type.
public static ValueTuple<ParameterInfo, Type>[] GetParameterTypes(MethodBase method)
result = ReflectionHelper.GetParameterTypes(method)
Gets the parameter types for the specified method.
- method
- The method base.
Retorna: An array of tuples with parameter info and its type.
public static bool IsAbstract(MemberInfo member)
result = ReflectionHelper.IsAbstract(member)
Determines whether the specified member is abstract.
- member
- The member info.
Retorna: True if the member is abstract; otherwise, false.
public static bool IsAssembly(string dllName)
result = ReflectionHelper.IsAssembly(dllName)
Determines whether the specified file contains a valid assembly.
- dllName
- Assembly file name.
Retorna: True if the file is an assembly; otherwise, false.
public static bool IsCollection(Type type)
result = ReflectionHelper.IsCollection(type)
Determines whether the specified type is a collection.
- type
- The type to check.
Retorna: True if the type is a collection; otherwise, false.
public static bool IsIndexer(PropertyInfo property)
result = ReflectionHelper.IsIndexer(property)
Determines whether the specified property is an indexer.
- property
- The property info.
Retorna: True if the property is an indexer; otherwise, false.
public static bool IsIndexer(MemberInfo member)
result = ReflectionHelper.IsIndexer(member)
Determines whether the specified member is an indexer.
- member
- The member info.
Retorna: True if the member is an indexer; otherwise, false.
public static bool IsMatch(MethodBase methodInfo, BindingFlags bindingFlags)
result = ReflectionHelper.IsMatch(methodInfo, bindingFlags)
Determines the method is match.
- methodInfo
- The method info.
- bindingFlags
- BindingFlags
Retorna: Operations result.
public static bool IsMatch(FieldInfo field, BindingFlags bindingFlags)
result = ReflectionHelper.IsMatch(field, bindingFlags)
Determines the field is match.
- field
- The field.
- bindingFlags
- BindingFlags
Retorna: Operations result.
public static bool IsMatch(PropertyInfo propertyInfo, BindingFlags bindingFlags)
result = ReflectionHelper.IsMatch(propertyInfo, bindingFlags)
Determines the property is match.
- propertyInfo
- The property info.
- bindingFlags
- BindingFlags
Retorna: Operations result.
public static bool IsModifiable(PropertyInfo pi)
result = ReflectionHelper.IsModifiable(pi)
Determines the property is modifiable.
- pi
- The property info.
Retorna: Operations result.
public static bool IsOutput(ParameterInfo param)
result = ReflectionHelper.IsOutput(param)
Determines whether the specified parameter is an output parameter.
- param
- The parameter info.
Retorna: True if the parameter is output; otherwise, false.
public static bool IsOverloadable(MemberInfo member)
result = ReflectionHelper.IsOverloadable(member)
Determines whether the specified member is overloadable.
- member
- The member info.
Retorna: True if the member is overloadable; otherwise, false.
public static bool IsParams(ParameterInfo pi)
result = ReflectionHelper.IsParams(pi)
Determines whether the specified parameter is a params array.
- pi
- The parameter info.
Retorna: True if the parameter is marked as params; otherwise, false.
public static bool IsRequiredType(Type type, Type required)
result = ReflectionHelper.IsRequiredType(type, required)
Is type compatible.
- type
- Type.
- required
- Required type.
Retorna: Check result.
public static bool IsRequiredType<T>(Type type)
result = ReflectionHelper.IsRequiredType(type)
Is type compatible.
- type
- Type.
Retorna: Check result.
public static bool IsRuntimeType(Type type)
result = ReflectionHelper.IsRuntimeType(type)
Determines whether the specified type is a runtime type.
- type
- The type to check.
Retorna: True if the type inherits from Type; otherwise, false.
public static bool IsStatic(MemberInfo member)
result = ReflectionHelper.IsStatic(member)
Determines whether the specified member is static.
- member
- The member info.
Retorna: True if the member is static; otherwise, false.
public static bool IsVirtual(MemberInfo member)
result = ReflectionHelper.IsVirtual(member)
Determines whether the specified member is virtual.
- member
- The member info.
Retorna: True if the member is virtual; otherwise, false.
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.
Retorna: The constructed generic method.
public static string MakePropertyName(string accessorName)
result = ReflectionHelper.MakePropertyName(accessorName)
Makes the property name from the accessor name.
- accessorName
- The accessor name.
Retorna: The property name.
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.
Retorna: True if the member matches one of the types; otherwise, false.
public static IEnumerable<TMember> OrderByDeclaration<TMember>(IEnumerable<TMember> members)
result = ReflectionHelper.OrderByDeclaration(members)
Order the members by declaration.
- members
- Members.
Retorna: Ordered members.
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.
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.
Retorna: The found type.
public static AssemblyName VerifyAssembly(string dllName)
result = ReflectionHelper.VerifyAssembly(dllName)
Tries to read the assembly name from the specified file.
- dllName
- Assembly file name.
Retorna: The assembly name or null if the file is not a valid assembly.
Campos
public const BindingFlags AllInstanceMembers
value = ReflectionHelper.AllInstanceMembers
Binding flags for all instance members.
public const BindingFlags AllMembers
value = ReflectionHelper.AllMembers
Binding flags for all members.
public const BindingFlags AllStaticMembers
value = ReflectionHelper.AllStaticMembers
Binding flags for all static members.
public const string IndexerName
value = ReflectionHelper.IndexerName
The name for indexer members.
public const AttributeTargets Members
value = ReflectionHelper.Members
Attribute targets for fields and properties.
public const string RemovePrefix
value = ReflectionHelper.RemovePrefix
Removers prefix.
public const AttributeTargets Types
value = ReflectionHelper.Types
Attribute targets for classes, structs, and interfaces.