Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Binder.BindToMethod Method

Selects a method to invoke from the given set of methods, based on the supplied arguments.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

public abstract MethodBase BindToMethod (
	BindingFlags bindingAttr,
	MethodBase[] match,
	ref Object[] args,
	ParameterModifier[] modifiers,
	CultureInfo culture,
	string[] names,
	out Object state
)
public abstract MethodBase BindToMethod (
	BindingFlags bindingAttr, 
	MethodBase[] match, 
	/** @ref */ Object[] args, 
	ParameterModifier[] modifiers, 
	CultureInfo culture, 
	String[] names, 
	/** @attribute OutAttribute() */ /** @ref */ Object state
)
Not applicable.

Parameters

bindingAttr

A bitwise combination of BindingFlags values.

match

The set of methods that are candidates for matching. For example, when a Binder object is used by System.Type.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 Type.DefaultBinder changes the order of this array.

args

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

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

An instance of CultureInfo that is used to control the coercion of data types, in binder implementations that coerce types. If culture is a null reference (Nothing in Visual Basic), the CultureInfo for the current thread is used.

NoteNote:

For example, if a binder implementation allows coercion of string values to numeric types, this 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.

names

The parameter names, if parameter names are to be considered when matching, or a null reference (Nothing in Visual Basic) 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

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 a null reference (Nothing in Visual Basic) when BindToMethod returns, you must pass state to the ReorderArgumentArray 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).

Return Value

The matching method.
Exception typeCondition

AmbiguousMatchException

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.

MissingMethodException

For the default binder, match contains no methods that can accept the arguments supplied in args.

ArgumentException

For the default binder, match is a null reference (Nothing in Visual Basic) 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.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.