System.Reflection.IReflect.InvokeMember Method

Invokes a specified member.

Syntax

public object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters)

Parameters

name
The name of the member to find.
invokeAttr
One of the System.Reflection.BindingFlags invocation attributes. The invokeAttr parameter may be a constructor, method, property, or field. A suitable invocation attribute must be specified. Invoke the default member of a class by passing the empty string ("") as the name of the member.
binder
One of the System.Reflection.BindingFlags bit flags. Implements System.Reflection.Binder, containing properties related to this method.
target
The object on which to invoke the specified member. This parameter is ignored for static members.
args
An array of objects that contains the number, order, and type of the parameters of the member to be invoked. This is an empty array if there are no parameters.
modifiers
An array of System.Reflection.ParameterModifier objects. This array has the same length as the args parameter, representing the invoked member's argument attributes in the metadata. A parameter can have the following attributes: pdIn, pdOut, pdRetval, pdOptional, and pdHasDefault. These represent [In], [Out], [retval], [optional], and a default parameter, respectively. These attributes are used by various interoperability services.
culture
An instance of System.Globalization.CultureInfo used to govern the coercion of types. For example, culture converts a String that represents 1000 to a Double value, since 1000 is represented differently by different cultures. If this parameter is null, the System.Globalization.CultureInfo for the current thread is used.
namedParameters
A String array of parameters.

Returns

The specified member.

Remarks

The method that is to be invoked must be accessible and provide the most specific match with the specified argument list, under the constraints of the specified binder and invocation attributes.

A method is invoked if the number of parameters in the method declaration equals the number of arguments in the specified argument list, and the type of each argument can be converted by the binder to the type of the parameter.

Note:

The array of parameter modifiers passed to the IReflect.InvokeMember(string, BindingFlags, Binder, object, Object[], ParameterModifier[], System.Globalization.CultureInfo, String[]) method must contain a single parameter modifier. Only the first parameter modifier is considered when determining which argument needs to be passed by reference when exposed to COM.

The binder finds all matching methods, in accordance with the type of binding requested (BindingFlags.InvokeMethod, IReflect.GetProperties(BindingFlags), and so on). The set of methods is filtered by the name, number of arguments, and a set of search modifiers defined in the binder. After the method is selected, it is invoked, and accessibility is checked at that point. The search may control which set of methods is searched based upon the accessibility attribute associated with the method. Binder.BindToMethod(BindingFlags, MethodBase[], Object[]@, ParameterModifier[], System.Globalization.CultureInfo, String[], Object@) selects the method to be invoked. The default binder selects the most specific match.

Access restrictions are ignored for fully trusted code. That is, private constructors, methods, fields, and properties can be accessed and invoked through reflection whenever the code is fully trusted.

Requirements

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0