Binder.BindToMethod Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Selects a method to invoke from the given set of methods, based on the supplied arguments.
public:
abstract System::Reflection::MethodBase ^ BindToMethod(System::Reflection::BindingFlags bindingAttr, cli::array <System::Reflection::MethodBase ^> ^ match, cli::array <System::Object ^> ^ % args, cli::array <System::Reflection::ParameterModifier> ^ modifiers, System::Globalization::CultureInfo ^ culture, cli::array <System::String ^> ^ names, [Runtime::InteropServices::Out] System::Object ^ % state);
public abstract System.Reflection.MethodBase BindToMethod (System.Reflection.BindingFlags bindingAttr, System.Reflection.MethodBase[] match, ref object?[] args, System.Reflection.ParameterModifier[]? modifiers, System.Globalization.CultureInfo? culture, string[]? names, out object? state);
public abstract System.Reflection.MethodBase BindToMethod (System.Reflection.BindingFlags bindingAttr, System.Reflection.MethodBase[] match, ref object[] args, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] names, out object state);
abstract member BindToMethod : System.Reflection.BindingFlags * System.Reflection.MethodBase[] * Object[] * System.Reflection.ParameterModifier[] * System.Globalization.CultureInfo * string[] * obj -> System.Reflection.MethodBase
Public MustOverride Function BindToMethod (bindingAttr As BindingFlags, match As MethodBase(), ByRef args As Object(), modifiers As ParameterModifier(), culture As CultureInfo, names As String(), ByRef state As Object) As MethodBase
- bindingAttr
- BindingFlags
A bitwise combination of BindingFlags values.
- match
- MethodBase[]
The set of methods that are candidates for matching. For example, when a Binder object is used by InvokeMember, this parameter specifies the set of methods that reflection has determined to be possible matches, typically because they have the correct member name. The default implementation provided by DefaultBinder changes the order of this array.
- args
- Object[]
The arguments that are passed in. The binder can change the order of the arguments in this array; for example, the default binder changes the order of arguments if the names
parameter is used to specify an order other than positional order. If a binder implementation coerces argument types, the types and values of the arguments can be changed as well.
- modifiers
- ParameterModifier[]
An array of parameter modifiers that enable binding to work with parameter signatures in which the types have been modified. The default binder implementation does not use this parameter.
- culture
- CultureInfo
An instance of CultureInfo that is used to control the coercion of data types, in binder implementations that coerce types. If culture
is null
, the CultureInfo for the current thread is used.
- names
- String[]
The parameter names, if parameter names are to be considered when matching, or null
if arguments are to be treated as purely positional. For example, parameter names must be used if arguments are not supplied in positional order.
- state
- Object
After the method returns, state
contains a binder-provided object that keeps track of argument reordering. The binder creates this object, and the binder is the sole consumer of this object. If state
is not null
when BindToMethod
returns, you must pass state
to the ReorderArgumentArray(Object[], Object) method if you want to restore args
to its original order, for example, so that you can retrieve the values of ref
parameters (ByRef
parameters in Visual Basic).
The matching method.
For the default binder, match
contains multiple methods that are equally good matches for args
. For example, args
contains a MyClass
object that implements the IMyClass
interface, and match
contains a method that takes MyClass
and a method that takes IMyClass
.
For the default binder, match
contains no methods that can accept the arguments supplied in args
.
For the default binder, match
is null
or an empty array.
The default binder takes into account both parameters that have values and params
arrays (ParamArray
arrays in Visual Basic). Thus, it is possible to find a match in cases where args
and match
do not contain the same number of elements.
The binder enables a client to map the array of arguments back to its original form if the argument array has been manipulated by BindToMethod. Use this remap capability to get back by-reference arguments when such arguments are present. When you pass arguments by name, the binder reorders the argument array. The state
parameter keeps track of argument reordering, thus enabling the binder's ReorderArgumentArray method to reorder the argument array to its original form.
The BindToMethod method is used by the Type.InvokeMember method.
If a binder implementation allows coercion of string values to numeric types, the culture
parameter is necessary to convert a string that represents 1000 to a Double value, because 1000 is represented differently by different cultures. The default binder does not do such string coercions.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: