Class ReflectionHelpers
- Namespace
- Steeltoe.Common.Reflection
- Assembly
- Steeltoe.Common.dll
public static class ReflectionHelpers
- Inheritance
-
ReflectionHelpers
- Inherited Members
Methods
CreateInstance(Type, object[])
Create an instance of a type
public static object CreateInstance(Type t, object[] args = null)
Parameters
Returns
- object
New instance of desired type
FindAssemblies(Func<Assembly, bool>)
Find assemblies matching a query
public static IEnumerable<Assembly> FindAssemblies(Func<Assembly, bool> assemblyQuery)
Parameters
Returns
- IEnumerable<Assembly>
Assemblies in CurrentDomain matching the query
FindAssembliesWithAttribute<T>()
Find a list of types specified in an assembly attribute
public static IEnumerable<Assembly> FindAssembliesWithAttribute<T>() where T : AssemblyContainsTypeAttribute
Returns
- IEnumerable<Assembly>
A list of matching types
Type Parameters
TThe attribute that defines the types to get
FindAssembly(string)
Find an assembly
public static Assembly FindAssembly(string name)
Parameters
namestringName of the assembly to find
Returns
- Assembly
A representation of the assembly
FindAttributedTypesFromAssemblyAttribute<T>()
Finds a list of types with the attributed identified by T
public static IEnumerable<Type> FindAttributedTypesFromAssemblyAttribute<T>() where T : AssemblyContainsTypeAttribute
Returns
- IEnumerable<Type>
Matching types from within matching assemblies
Type Parameters
TThe assembly attribute that defines the desired type
FindDescendantTypes(Func<Assembly, bool>, Type)
Find types from assemblies matching the query that are based on a common type
public static IEnumerable<Type> FindDescendantTypes(Func<Assembly, bool> assemblyQuery, Type baseType)
Parameters
Returns
- IEnumerable<Type>
A list of types that have the given type as a base type
FindInterfacedTypesFromAssemblyAttribute<TAttribute>()
Finds a list of types implementing the interface identified by TAttribute
public static IEnumerable<Type> FindInterfacedTypesFromAssemblyAttribute<TAttribute>() where TAttribute : AssemblyContainsTypeAttribute
Returns
- IEnumerable<Type>
Matching types from within matching assemblies
Type Parameters
TAttributeThe assembly attribute that defines the desired interface type
FindMethod(Type, string, Type[])
Find a method within a type
public static MethodInfo FindMethod(Type type, string methodName, Type[] parameters = null)
Parameters
typeTypeThe type to search
methodNamestringThe name of the method
parametersType[](Optional) The parameters in the signature
Returns
- MethodInfo
The method you're searching for
FindType(Assembly, string)
Find a type from within an assembly
public static Type FindType(Assembly assembly, string typeName)
Parameters
Returns
- Type
The type
FindType(string[], string[])
Search a list of assemblies for the first matching type
public static Type FindType(string[] assemblyNames, string[] typeNames)
Parameters
Returns
- Type
An appropriate type
Remarks
Great for finding an implementation type that could have one or more names in one or more assemblies
FindTypeFromAssemblyAttribute<T>()
Find a type specified in an assembly attribute
public static IEnumerable<Type> FindTypeFromAssemblyAttribute<T>() where T : AssemblyContainsTypeAttribute
Returns
- IEnumerable<Type>
A list of matching types. Won't return more than one type per assembly
Type Parameters
TThe attribute that defines the type to get
FindTypeOrThrow(string[], string[], string, string)
Search a list of assemblies for the first matching type
public static Type FindTypeOrThrow(string[] assemblyNames, string[] typeNames, string typeName, string assemblyShortDescription)
Parameters
assemblyNamesstring[]List of assembly names to search
typeNamesstring[]List of suitable types
typeNamestringTo use in exception
assemblyShortDescriptionstringDescribe what might be missing
Returns
- Type
An appropriate type
Remarks
Great for finding an implementation type that could have one or more names in one or more assemblies
Exceptions
- Exception
When type isn't found
FindTypesWithAttributeFromAssemblyAttribute<TTypeAttribute, TAssemblyAttribute>()
Finds a list of assemblies with TTypeAttribute contained within assemblies with TAssemblyAttribute
public static IEnumerable<Type> FindTypesWithAttributeFromAssemblyAttribute<TTypeAttribute, TAssemblyAttribute>() where TTypeAttribute : Attribute where TAssemblyAttribute : AssemblyContainsTypeAttribute
Returns
- IEnumerable<Type>
Matching types from within matching assemblies
Type Parameters
TTypeAttributeThe Type attribute to locate
TAssemblyAttributeThe Assembly-level attribute to use to filter the assembly list
FindTypesWithAttribute<T>(Assembly)
Finds a list of types with T
public static IEnumerable<Type> FindTypesWithAttribute<T>(Assembly assembly) where T : Attribute
Parameters
assemblyAssemblyThe assembly to search for the type(s)
Returns
- IEnumerable<Type>
A list of types with the specified attribute
Type Parameters
TType of Attribute to search for
Invoke(MethodBase, object, object[])
Invoke a function
public static object Invoke(MethodBase member, object instance, object[] args)
Parameters
memberMethodBaseThe method to execute
instanceobjectInstance of an object, if required by the method
argsobject[]Arguments to pass to the method
Returns
- object
Results of method call
IsAssemblyLoaded(string)
Try to load an assembly
public static bool IsAssemblyLoaded(string assembly)
Parameters
assemblystringName of the assembly
Returns
- bool
Boolean indicating success/failure of finding the assembly
TrySetProperty(object, string, object)
Try to set a property on an object
public static void TrySetProperty(object obj, string property, object value)