System.Reflection.Binder.BindToMethod Method
Selects a method based on the specified criteria.

Syntax

public abstract MethodBase BindToMethod (BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] names, out object state)

Parameters

bindingAttr
A bitwise combination of System.Reflection.BindingFlags values that control the binding process. For requirements, see the Behaviors section.
match
An array of System.Reflection.MethodBase objects that represent the set of methods that Reflection has determined to be a possible match, typically because they have the correct member name.
args
An array of objects that represent the parameters passed in the method invocation. The types, values, and order of the elements of this array might be changed by this method to match the signature of the selected method.
modifiers
The only defined value for this parameter is null .
culture
The only defined value for this parameter is null .
names
A string array containing the names of methods to be searched.
state
A binder-provided object that keeps track of parameter reordering. The state object is totally defined by the implementer of the System.Reflection.Binder class. This object is null if the binder does not reorder the argument array of the bound method.

Returns

A System.Reflection.MethodBase instance that reflects the method that matches to the specified criteria. It is not required that this instance be contained in match . If a suitable method is not found, returns null .

Remarks

If state is not null, the system invokes Binder.ReorderArgumentArray(Object[]@, object) after this method returns.

Note: This allows a caller to map the argument array of a method back to the original form if the order has been altered by Binder.BindToMethod(BindingFlags, MethodBase[], Object[]@, ParameterModifier[], System.Globalization.CultureInfo, String[], Object@) . This is useful if ByRef arguments are in the argument array, because the caller can retrieve those arguments in their original order on return from this method. When arguments are passed by name (i.e., using named arguments), the binder reorders the argument array and that is what the caller sees. This method insures that the original order of the arguments is restored.

Operation

For the bindingAttr parameter, the caller is required to specify either BindingFlags.Public or BindingFlags.NonPublic, and either BindingFlags.Instance or BindingFlags.Static. If at least one value from each pair is not specified, this method is required to return null .

The Binder.BindToMethod(BindingFlags, MethodBase[], Object[]@, ParameterModifier[], System.Globalization.CultureInfo, String[], Object@) method is permitted to change the order of the argument array of a method call only if the binder returns, via the state parameter, a non-null opaque object that records the original order of the argument array. If, on return from Binder.BindToMethod(BindingFlags, MethodBase[], Object[]@, ParameterModifier[], System.Globalization.CultureInfo, String[], Object@), state is not null, the system calls Binder.ReorderArgumentArray(Object[]@, object) .

Requirements

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