Class Reflect
Helper methods for inspecting a type by reflection.
Many of these methods take ICustomAttributeProvider as an argument to avoid duplication, even though certain attributes can only appear on specific types of members, like MethodInfo or Type.
In the case where a type is being examined for the presence of an attribute, interface or named member, the Reflect methods operate with the full name of the member being sought. This removes the necessity of the caller having a reference to the assembly that defines the item being sought and allows the NUnit core to inspect assemblies that reference an older version of the NUnit framework.
public class Reflect
- Inheritance
-
Reflect
- Inherited Members
Methods
Construct(Type)
Invoke the default constructor on a Type
public static object Construct(Type type)
Parameters
type
TypeThe Type to be constructed
Returns
- object
An instance of the Type
Construct(Type, object[])
Invoke a constructor on a Type with arguments
public static object Construct(Type type, object[] arguments)
Parameters
Returns
- object
An instance of the Type
GetMethodsWithAttribute(Type, Type, bool)
Examine a fixture type and return an array of methods having a particular attribute. The array is order with base methods first.
public static MethodInfo[] GetMethodsWithAttribute(Type fixtureType, Type attributeType, bool inherit)
Parameters
fixtureType
TypeThe type to examine
attributeType
TypeThe attribute Type to look for
inherit
boolSpecifies whether to search the fixture type inheritance chain
Returns
- MethodInfo[]
The array of methods found
HasMethodWithAttribute(Type, Type)
Examine a fixture type and return true if it has a method with a particular attribute.
public static bool HasMethodWithAttribute(Type fixtureType, Type attributeType)
Parameters
Returns
- bool
True if found, otherwise false
InvokeMethod(MethodInfo, object)
Invoke a parameterless method returning void on an object.
public static object InvokeMethod(MethodInfo method, object fixture)
Parameters
method
MethodInfoA MethodInfo for the method to be invoked
fixture
objectThe object on which to invoke the method
Returns
InvokeMethod(MethodInfo, object, params object[])
Invoke a method, converting any TargetInvocationException to an NUnitException.
public static object InvokeMethod(MethodInfo method, object fixture, params object[] args)
Parameters
method
MethodInfoA MethodInfo for the method to be invoked
fixture
objectThe object on which to invoke the method
args
object[]The argument list for the method
Returns
- object
The return value from the invoked method