Class ReflectionHelpers
Auxiliary functions for reflection.
Inherited Members
Namespace: TheXDS.MCART.Helpers
Assembly: MCART.dll
Syntax
public static class ReflectionHelpers
Methods
| Edit this page View SourceFieldsOf<T>(IEnumerable<FieldInfo>)
Enumerates the values of all static fields that return
values of type T
.
Declaration
public static IEnumerable<T> FieldsOf<T>(IEnumerable<FieldInfo> fields)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<FieldInfo> | fields | Collection of fields to analyze. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all values of type
|
Type Parameters
Name | Description |
---|---|
T | Type of fields to retrieve. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FieldsOf<T>(IEnumerable<FieldInfo>, object?)
Enumerates the values of all fields that return values of type
T
.
Declaration
public static IEnumerable<T> FieldsOf<T>(IEnumerable<FieldInfo> fields, object? instance)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<FieldInfo> | fields | Collection of fields to analyze. |
object | instance | Instance from which to retrieve fields. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all values of type
|
Type Parameters
Name | Description |
---|---|
T | Type of fields to retrieve. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
NullItemException | Thrown if any element of |
MissingFieldException | Thrown when |
MemberAccessException | Thrown when |
FieldsOf<T>(Type)
Enumerates the values of all static fields that return
values of type T
in the specified type.
Declaration
public static IEnumerable<T> FieldsOf<T>(this Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type from which to retrieve fields. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all values of type
|
Type Parameters
Name | Description |
---|---|
T | Type of fields to retrieve. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindAllObjects<T>()
Instantiates all objects of the specified type, returning them in an enumeration.
Declaration
public static IEnumerable<T> FindAllObjects<T>() where T : notnull
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all object instances of type
|
Type Parameters
Name | Description |
---|---|
T | Type of objects to find. |
FindAllObjects<T>(IEnumerable?)
Instantiates all objects of the specified type, returning them in an enumeration.
Declaration
public static IEnumerable<T> FindAllObjects<T>(IEnumerable? ctorArgs) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
IEnumerable | ctorArgs | Arguments to pass to the class instance constructor. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all object instances of type
|
Type Parameters
Name | Description |
---|---|
T | Type of objects to find. |
FindAllObjects<T>(IEnumerable?, Func<Type, bool>)
Instantiates all objects of the specified type, returning them in an enumeration.
Declaration
public static IEnumerable<T> FindAllObjects<T>(IEnumerable? ctorArgs, Func<Type, bool> typeFilter) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
IEnumerable | ctorArgs | Arguments to pass to the class instance constructor. |
Func<Type, bool> | typeFilter | Filter function to apply to matching types. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all object instances of type
|
Type Parameters
Name | Description |
---|---|
T | Type of objects to find. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindAllObjects<T>(Func<Type, bool>)
Instantiates all objects of the specified type, returning them in an enumeration.
Declaration
public static IEnumerable<T> FindAllObjects<T>(Func<Type, bool> typeFilter) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
Func<Type, bool> | typeFilter | Filter function to apply to matching types. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all object instances of type
|
Type Parameters
Name | Description |
---|---|
T | Type of objects to find. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindFirstObject<T>()
Retrieves the first object that matches the specified base type.
Declaration
public static T? FindFirstObject<T>() where T : notnull
Returns
Type | Description |
---|---|
T | A new instance of the requested object, or null if no matching type is found. |
Type Parameters
Name | Description |
---|---|
T | Type of object to find. |
FindFirstObject<T>(IEnumerable?)
Retrieves the first object that matches the specified base type.
Declaration
public static T? FindFirstObject<T>(IEnumerable? ctorArgs) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
IEnumerable | ctorArgs | Arguments to pass to the class instance constructor. |
Returns
Type | Description |
---|---|
T | A new instance of the requested object, or null if no matching type is found. |
Type Parameters
Name | Description |
---|---|
T | Type of object to find. |
FindFirstObject<T>(IEnumerable?, Func<Type, bool>)
Retrieves the first object that matches the specified base type.
Declaration
public static T? FindFirstObject<T>(IEnumerable? ctorArgs, Func<Type, bool> typeFilter) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
IEnumerable | ctorArgs | Arguments to pass to the class instance constructor. |
Func<Type, bool> | typeFilter | Filter function to apply to matching types. |
Returns
Type | Description |
---|---|
T | A new instance of the requested object, or null if no matching type is found. |
Type Parameters
Name | Description |
---|---|
T | Type of object to find. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindFirstObject<T>(Func<Type, bool>)
Retrieves the first object that matches the specified base type.
Declaration
public static T? FindFirstObject<T>(Func<Type, bool> typeFilter) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
Func<Type, bool> | typeFilter | Filter function to apply to matching types. |
Returns
Type | Description |
---|---|
T | A new instance of the requested object, or null if no matching type is found. |
Type Parameters
Name | Description |
---|---|
T | Type of object to find. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindSingleObject<T>()
Retrieves a single object that matches the specified base type.
Declaration
public static T? FindSingleObject<T>() where T : notnull
Returns
Type | Description |
---|---|
T | A new instance of the requested object, or null if no matching type is found. |
Type Parameters
Name | Description |
---|---|
T | Type of object to find. |
FindSingleObject<T>(IEnumerable?)
Retrieves a single object that matches the specified base type.
Declaration
public static T? FindSingleObject<T>(IEnumerable? ctorArgs) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
IEnumerable | ctorArgs | Arguments to pass to the class instance constructor. |
Returns
Type | Description |
---|---|
T | A new instance of the requested object, or null if no matching type is found. |
Type Parameters
Name | Description |
---|---|
T | Type of object to find. |
FindSingleObject<T>(IEnumerable?, Func<Type, bool>)
Retrieves a single object that matches the specified base type.
Declaration
public static T? FindSingleObject<T>(IEnumerable? ctorArgs, Func<Type, bool> typeFilter) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
IEnumerable | ctorArgs | Arguments to pass to the class instance constructor. |
Func<Type, bool> | typeFilter | Filter function to apply to matching types. |
Returns
Type | Description |
---|---|
T | A new instance of the requested object, or null if no matching type is found. |
Type Parameters
Name | Description |
---|---|
T | Type of object to find. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindSingleObject<T>(Func<Type, bool>)
Retrieves a single object that matches the specified base type.
Declaration
public static T? FindSingleObject<T>(Func<Type, bool> typeFilter) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
Func<Type, bool> | typeFilter | Filter function to apply to matching types. |
Returns
Type | Description |
---|---|
T | A new instance of the requested object, or null if no matching type is found. |
Type Parameters
Name | Description |
---|---|
T | Type of object to find. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindType(string)
Searches the current AppDomain for a type that contains the specified TagAttribute.
Declaration
public static Type? FindType(string identifier)
Parameters
Type | Name | Description |
---|---|---|
string | identifier | Identifier to search for. |
Returns
Type | Description |
---|---|
Type | A type that has been tagged with the specified identifier, or null if no type contains the identifier. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindType(string, AppDomain)
Searches the specified AppDomain for a type that contains the specified TagAttribute.
Declaration
public static Type? FindType(string identifier, AppDomain domain)
Parameters
Type | Name | Description |
---|---|---|
string | identifier | Identifier to search for. |
AppDomain | domain | Domain in which to search. |
Returns
Type | Description |
---|---|
Type | A type that has been tagged with the specified identifier, or null if no type contains the identifier. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindType<T>(string)
Searches the current AppDomain for a type that contains the specified TagAttribute.
Declaration
public static Type? FindType<T>(string identifier)
Parameters
Type | Name | Description |
---|---|---|
string | identifier | Identifier to search for. |
Returns
Type | Description |
---|---|
Type | A type that has been tagged with the specified identifier, or null if no type contains the identifier. |
Type Parameters
Name | Description |
---|---|
T | Restrict search to these types. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FindType<T>(string, AppDomain)
Searches the specified AppDomain for a type that contains the specified TagAttribute.
Declaration
public static Type? FindType<T>(string identifier, AppDomain domain)
Parameters
Type | Name | Description |
---|---|---|
string | identifier | Identifier to search for. |
AppDomain | domain | Domain in which to search. |
Returns
Type | Description |
---|---|
Type | A type that has been tagged with the specified identifier, or null if no type contains the identifier. |
Type Parameters
Name | Description |
---|---|
T | Restrict search to these types. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
GetCallingMethod()
Gets a reference to the method that called the currently executing method.
Declaration
public static MethodBase? GetCallingMethod()
Returns
Type | Description |
---|---|
MethodBase | The method that called the current method where this function is
used. Will return null if called from the
application entry point (generally the |
Remarks
Due to some compiler optimizations, it is recommended that methods calling GetCallingMethod() be annotated with the MethodImplAttribute with the value NoInlining.
GetCallingMethod(int)
Gets a reference to the method that called the current method.
Declaration
public static MethodBase? GetCallingMethod(int nCaller)
Parameters
Type | Name | Description |
---|---|---|
int | nCaller | Number of parent method iterations to return. Must be a value greater than or equal to 1. |
Returns
Type | Description |
---|---|
MethodBase | The method that called the current method where this function is
used. Will return null if the call stack is
analyzed and the application entry point is reached (generally the
|
Remarks
Due to some compiler optimizations, it is recommended that methods calling GetCallingMethod(int) be annotated with the MethodImplAttribute with the value NoInlining.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
OverflowException | Thrown if |
GetEntryAssembly()
Gets the assembly that contains the entry point of the currently executing application.
Declaration
public static Assembly? GetEntryAssembly()
Returns
Type | Description |
---|---|
Assembly | The assembly where the entry point of the current application is defined. |
GetEntryPoint()
Gets the entry point of the currently executing application.
Declaration
public static MethodInfo? GetEntryPoint()
Returns
Type | Description |
---|---|
MethodInfo | The method that is the entry point of the current application. |
GetField<T>(Expression<Func<T, object?>>)
Gets a reference to the field selected by an expression.
Declaration
public static FieldInfo GetField<T>(Expression<Func<T, object?>> fieldSelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, object>> | fieldSelector | Expression that indicates which field of the type to return. |
Returns
Type | Description |
---|---|
FieldInfo | A FieldInfo that represents the field selected in the expression. |
Type Parameters
Name | Description |
---|---|
T | Type from which to select the field to retrieve. |
GetField<TValue>(Expression<Func<TValue>>)
Gets a reference to the selected field via an expression.
Declaration
public static FieldInfo GetField<TValue>(Expression<Func<TValue>> fieldSelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<TValue>> | fieldSelector | Expression indicating which field to return. |
Returns
Type | Description |
---|---|
FieldInfo | A FieldInfo representing the selected field. |
Type Parameters
Name | Description |
---|---|
TValue | Type returned by the field to get. |
GetField<T, TValue>(Expression<Func<T, TValue>>)
Gets a reference to the field selected by an expression.
Declaration
public static FieldInfo GetField<T, TValue>(Expression<Func<T, TValue>> fieldSelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TValue>> | fieldSelector | Expression that indicates which field of the type to return. |
Returns
Type | Description |
---|---|
FieldInfo | A FieldInfo that represents the field selected in the expression. |
Type Parameters
Name | Description |
---|---|
T | Type from which to select the field to retrieve. |
TValue | Type returned by the field to retrieve. |
GetMember(Expression<Func<object?>>)
Gets a member from an expression.
Declaration
public static MemberInfo GetMember(Expression<Func<object?>> memberSelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<object>> | memberSelector | Expression indicating which member to return. |
Returns
Type | Description |
---|---|
MemberInfo | A MemberInfo representing the selected member. |
GetMember<T>(Expression<Func<T, object?>>)
Gets a member of a class from an expression.
Declaration
public static MemberInfo GetMember<T>(Expression<Func<T, object?>> memberSelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, object>> | memberSelector | Expression indicating which member to return. |
Returns
Type | Description |
---|---|
MemberInfo | A MemberInfo representing the selected member. |
Type Parameters
Name | Description |
---|---|
T | Class from which to get the member. |
GetMember<TValue>(Expression<Func<TValue>>)
Gets a member from an expression.
Declaration
public static MemberInfo GetMember<TValue>(Expression<Func<TValue>> memberSelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<TValue>> | memberSelector | Expression indicating which member to return. |
Returns
Type | Description |
---|---|
MemberInfo | A MemberInfo representing the selected member. |
Type Parameters
Name | Description |
---|---|
TValue | Type of the member to get. |
GetMember<T, TValue>(Expression<Func<T, TValue>>)
Gets an instance member of a class from an expression.
Declaration
public static MemberInfo GetMember<T, TValue>(Expression<Func<T, TValue>> memberSelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TValue>> | memberSelector | Expression indicating which member to return. |
Returns
Type | Description |
---|---|
MemberInfo | A MemberInfo representing the selected member. |
Type Parameters
Name | Description |
---|---|
T | Class from which to get the member. |
TValue | Type of the member to get. |
GetMember<TMember, TValue>(Expression<Func<TValue>>)
Gets a reference to the selected member via an expression.
Declaration
public static TMember GetMember<TMember, TValue>(Expression<Func<TValue>> memberSelector) where TMember : MemberInfo
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<TValue>> | memberSelector | Expression indicating which member to return. |
Returns
Type | Description |
---|---|
TMember | A MemberInfo representing the selected member. |
Type Parameters
Name | Description |
---|---|
TMember | Type of the member to get. |
TValue | Type from which to get the member. |
GetMember<TMember, T, TValue>(Expression<Func<T, TValue>>)
Gets a reference to the selected member via an expression.
Declaration
public static TMember GetMember<TMember, T, TValue>(Expression<Func<T, TValue>> memberSelector) where TMember : MemberInfo
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TValue>> | memberSelector | Expression indicating which member to return. |
Returns
Type | Description |
---|---|
TMember | A MemberInfo representing the selected member. |
Type Parameters
Name | Description |
---|---|
TMember | Type of the member to get. |
T | Type from which to get the member. |
TValue | Type returned by the member to get. |
GetMethod<T>(Expression<Func<T, Delegate>>)
Gets a reference to the selected method via an expression.
Declaration
public static MethodInfo GetMethod<T>(Expression<Func<T, Delegate>> methodSelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Delegate>> | methodSelector | Expression indicating which method to return. |
Returns
Type | Description |
---|---|
MethodInfo | A MethodInfo representing the selected method. |
Type Parameters
Name | Description |
---|---|
T | Type from which to select the method. |
GetMethod<TMethod>(Expression<Func<TMethod>>)
Gets a reference to the selected method via an expression.
Declaration
public static MethodInfo GetMethod<TMethod>(Expression<Func<TMethod>> methodSelector) where TMethod : Delegate
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<TMethod>> | methodSelector | Expression indicating which method to return. |
Returns
Type | Description |
---|---|
MethodInfo | A MethodInfo representing the selected method. |
Type Parameters
Name | Description |
---|---|
TMethod | Delegate type of the method to get. |
GetMethod<T, TMethod>(Expression<Func<T, TMethod>>)
Gets a reference to the selected method via an expression.
Declaration
public static MethodInfo GetMethod<T, TMethod>(Expression<Func<T, TMethod>> methodSelector) where TMethod : Delegate
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TMethod>> | methodSelector | Expression indicating which method to return. |
Returns
Type | Description |
---|---|
MethodInfo | A MethodInfo representing the selected method. |
Type Parameters
Name | Description |
---|---|
T | Type from which to select the method. |
TMethod | Delegate type of the method to get. |
GetPropertiesOf<T>(Type)
Enumerates the properties of the specified type whose value type is
T
.
Declaration
public static IEnumerable<PropertyInfo> GetPropertiesOf<T>(this Type t)
Parameters
Type | Name | Description |
---|---|---|
Type | t | Type from which to enumerate the properties. |
Returns
Type | Description |
---|---|
IEnumerable<PropertyInfo> | An enumeration of the properties of the desired type contained within the specified type. |
Type Parameters
Name | Description |
---|---|
T | Type of the properties to get. |
GetPropertiesOf<T>(Type, BindingFlags)
Enumerates the properties of the specified type whose value type is
T
.
Declaration
public static IEnumerable<PropertyInfo> GetPropertiesOf<T>(this Type t, BindingFlags flags)
Parameters
Type | Name | Description |
---|---|---|
Type | t | Type from which to enumerate the properties. |
BindingFlags | flags | Declaration flags to use for filtering the members to get. |
Returns
Type | Description |
---|---|
IEnumerable<PropertyInfo> | An enumeration of the properties of the desired type contained within the specified type. |
Type Parameters
Name | Description |
---|---|
T | Type of the properties to get. |
GetProperty<T>(Expression<Func<T, object?>>)
Gets a reference to the property selected via an expression.
Declaration
public static PropertyInfo GetProperty<T>(Expression<Func<T, object?>> propertySelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, object>> | propertySelector | Expression indicating which property to return. |
Returns
Type | Description |
---|---|
PropertyInfo | A PropertyInfo representing the selected property. |
Type Parameters
Name | Description |
---|---|
T | Type from which to select the property. |
GetProperty<TValue>(Expression<Func<TValue>>)
Gets a reference to the property selected via an expression.
Declaration
public static PropertyInfo GetProperty<TValue>(Expression<Func<TValue>> propertySelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<TValue>> | propertySelector | Expression indicating which property to return. |
Returns
Type | Description |
---|---|
PropertyInfo | A PropertyInfo representing the selected property. |
Type Parameters
Name | Description |
---|---|
TValue | Type returned by the property. |
GetProperty<T, TValue>(Expression<Func<T, TValue>>)
Gets a reference to the property selected via an expression.
Declaration
public static PropertyInfo GetProperty<T, TValue>(Expression<Func<T, TValue>> propertySelector)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TValue>> | propertySelector | Expression indicating which property to return. |
Returns
Type | Description |
---|---|
PropertyInfo | A PropertyInfo representing the selected property. |
Type Parameters
Name | Description |
---|---|
T | Type from which to select the property. |
TValue | Type returned by the property. |
GetTypes<T>()
Gets a list of types assignable from the specified interface or base class.
Declaration
public static IEnumerable<Type> GetTypes<T>()
Returns
Type | Description |
---|---|
IEnumerable<Type> | A list of types of classes that implement the interface or inherit from the base class
|
Type Parameters
Name | Description |
---|---|
T | Interface or base class to search for. |
Remarks
This function gets all types (private and public) defined within all assemblies in the current domain. To get only publicly exported types, use PublicTypes(Type), PublicTypes(Type, AppDomain), PublicTypes<T>() or PublicTypes<T>(AppDomain).
GetTypes<T>(AppDomain)
Gets a list of types assignable from the specified interface or base class within the specified AppDomain.
Declaration
public static IEnumerable<Type> GetTypes<T>(AppDomain domain)
Parameters
Type | Name | Description |
---|---|---|
AppDomain | domain | AppDomain in which to perform the search. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | A list of types of classes that implement the interface or inherit from the base class
|
Type Parameters
Name | Description |
---|---|
T | Interface or base class to search for. |
Remarks
This function gets all types (private and public) defined within all assemblies in the specified domain. To get only publicly exported types, use PublicTypes(Type), PublicTypes(Type, AppDomain), PublicTypes<T>() or PublicTypes<T>(AppDomain).
GetTypes<T>(AppDomain, in bool)
Gets a list of types assignable from the specified interface or base class within the specified AppDomain.
Declaration
public static IEnumerable<Type> GetTypes<T>(AppDomain domain, in bool instantiablesOnly)
Parameters
Type | Name | Description |
---|---|---|
AppDomain | domain | AppDomain in which to perform the search. |
bool | instantiablesOnly | If set to true, only instantiable types will be included. false will return all matching types. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | A list of types of classes that implement the interface or inherit from the base class
|
Type Parameters
Name | Description |
---|---|
T | Interface or base class to search for. |
Remarks
This function gets all types (private and public) defined within all assemblies in the specified domain. To get only publicly exported types, use PublicTypes(Type), PublicTypes(Type, AppDomain), PublicTypes<T>() or PublicTypes<T>(AppDomain).
GetTypes<T>(bool)
Gets a list of types assignable from the specified interface or base class.
Declaration
public static IEnumerable<Type> GetTypes<T>(bool instantiablesOnly)
Parameters
Type | Name | Description |
---|---|---|
bool | instantiablesOnly | If set to true, only instantiable types will be included. false will return all matching types. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | A list of types of classes that implement the interface or inherit from the base class
|
Type Parameters
Name | Description |
---|---|
T | Interface or base class to search for. |
Remarks
This function gets all types (private and public) defined within all assemblies in the current domain. To get only publicly exported types, use PublicTypes(Type), PublicTypes(Type, AppDomain), PublicTypes<T>() or PublicTypes<T>(AppDomain).
GetTypes<T>(IEnumerable<Assembly>)
Gets a list of assignable types from the specified interface or base class within the specified AppDomain.
Declaration
public static IEnumerable<Type> GetTypes<T>(this IEnumerable<Assembly> assemblies)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Assembly> | assemblies | Collection of assemblies to search in. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | A list of types of classes that implement the interface or inherit from
the base class |
Type Parameters
Name | Description |
---|---|
T | Interface or base class to search for. |
Remarks
This function gets all types (private and public) defined within all assemblies in the specified collection. To get only publicly exported types, use PublicTypes(Type), PublicTypes(Type, AppDomain), PublicTypes<T>() or PublicTypes<T>(AppDomain).
GetTypes<T>(IEnumerable<Assembly>, bool)
Gets a list of assignable types from the specified interface or base class within the specified AppDomain.
Declaration
public static IEnumerable<Type> GetTypes<T>(this IEnumerable<Assembly> assemblies, bool instantiablesOnly)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Assembly> | assemblies | Collection of assemblies to search in. |
bool | instantiablesOnly | If set to true, only instantiable types are included. false returns all matching types. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | A list of types of classes that implement the interface or inherit from
the base class |
Type Parameters
Name | Description |
---|---|
T | Interface or base class to search for. |
Remarks
This function gets all types (private and public) defined within all assemblies in the specified collection. To get only publicly exported types, use PublicTypes(Type), PublicTypes(Type, AppDomain), PublicTypes<T>() or PublicTypes<T>(AppDomain).
PropertiesOf<T>(IEnumerable<PropertyInfo>)
Enumerates the value of all static properties that return values of type
T
.
Declaration
public static IEnumerable<T> PropertiesOf<T>(this IEnumerable<PropertyInfo> properties)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<PropertyInfo> | properties | Collection of properties to analyze. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all values of type |
Type Parameters
Name | Description |
---|---|
T | Type of properties to get. |
PropertiesOf<T>(IEnumerable<PropertyInfo>, object?)
Enumerates the value of all properties that return values of type
T
.
Declaration
public static IEnumerable<T> PropertiesOf<T>(this IEnumerable<PropertyInfo> properties, object? instance)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<PropertyInfo> | properties | Collection of properties to analyze. |
object | instance | Instance from which to get the properties. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all values of type |
Type Parameters
Name | Description |
---|---|
T | Type of properties to get. |
PublicTypes()
Gets all public types within the current AppDomain.
Declaration
public static IEnumerable<Type> PublicTypes()
Returns
Type | Description |
---|---|
IEnumerable<Type> | An enumeration of all public types found in the current domain. |
Remarks
This function gets all public types exported from the current domain, excluding dynamic assemblies (generated using the System.Reflection.Emit namespace). To get an indiscriminate list of types, use GetTypes<T>().
PublicTypes(AppDomain)
Gets all public types within the specified AppDomain.
Declaration
public static IEnumerable<Type> PublicTypes(AppDomain domain)
Parameters
Type | Name | Description |
---|---|---|
AppDomain | domain | Application domain within which to search for types. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | An enumeration of all public types found in the specified domain. |
Remarks
This function gets all public types exported from the specified domain, excluding dynamic assemblies (generated using the System.Reflection.Emit namespace). To get an indiscriminate list of types, use GetTypes<T>().
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
PublicTypes(Type)
Gets all public types that implement the specified type.
Declaration
public static IEnumerable<Type> PublicTypes(Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type to get. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | An enumeration of all types that inherit from or implement the specified type. |
Remarks
This function gets all public types exported from the current domain, excluding dynamic assemblies (generated using the System.Reflection.Emit namespace). To get an indiscriminate list of types, use GetTypes<T>().
PublicTypes(Type, AppDomain)
Gets all public types that implement the specified type.
Declaration
public static IEnumerable<Type> PublicTypes(Type type, AppDomain domain)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type to get. |
AppDomain | domain | Application domain within which to search for types. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | An enumeration of all types that inherit from or implement the specified type. |
Remarks
This function gets all public types exported from the specified domain, excluding dynamic assemblies (generated using the System.Reflection.Emit namespace). To get an indiscriminate list of types, use GetTypes<T>().
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
PublicTypes<T>()
Gets all public types that implement the specified type.
Declaration
public static IEnumerable<Type> PublicTypes<T>()
Returns
Type | Description |
---|---|
IEnumerable<Type> | An enumeration of all types that inherit from or implement the specified type. |
Type Parameters
Name | Description |
---|---|
T | Type of objects to get. |
Remarks
This function gets all public types exported from the current domain, excluding dynamic assemblies (generated using the System.Reflection.Emit namespace). To get an indiscriminate list of types, use GetTypes<T>().
PublicTypes<T>(AppDomain)
Gets all public types that implement the specified type.
Declaration
public static IEnumerable<Type> PublicTypes<T>(AppDomain domain)
Parameters
Type | Name | Description |
---|---|---|
AppDomain | domain | Application domain within which to search for types. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | An enumeration of all types that inherit from or implement the specified type. |
Type Parameters
Name | Description |
---|---|
T | Type of objects to get. |
Remarks
This function gets all public types exported from the specified domain, excluding dynamic assemblies (generated using the System.Reflection.Emit namespace). To get an indiscriminate list of types, use GetTypes<T>().
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
WithSignature<T>(IEnumerable<MethodInfo>)
Gets all static methods with a signature compatible with the specified delegate.
Declaration
public static IEnumerable<T> WithSignature<T>(this IEnumerable<MethodInfo> methods) where T : Delegate
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<MethodInfo> | methods | Collection of methods in which to search. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all methods that have a signature compatible with |
Type Parameters
Name | Description |
---|---|
T | Delegate to use as the signature to check. |
WithSignature<T>(IEnumerable<MethodInfo>, object)
Gets all instance methods with a signature compatible with the specified delegate.
Declaration
public static IEnumerable<T> WithSignature<T>(this IEnumerable<MethodInfo> methods, object instance) where T : Delegate
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<MethodInfo> | methods | Collection of methods in which to search. |
object | instance | Instance of the object on which to construct the delegates. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all methods that have a signature compatible with |
Type Parameters
Name | Description |
---|---|
T | Delegate to use as the signature to check. |