PostSharp 2023.0 / / Post­Sharp Documentation / API Reference / Post­Sharp.​Reflection Namespace / Custom­Reflection­Binder Class / Custom­Reflection­Binder Methods / Custom­Reflection­Binder.​Bind­To­Method Method

CustomReflectionBinder.BindToMethod Method

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

Namespace:  PostSharp.Reflection
Assembly:  PostSharp (in PostSharp.dll) Version: 2023.0.3.0 (2023.0.3.0)
public override MethodBase BindToMethod(
	BindingFlags bindingFlags,
	MethodBase[] match,
	ref Object[] args,
	ParameterModifier[] modifiers,
	CultureInfo culture,
	string[] names,
	out Object state


Type: System.Reflection.BindingFlags
Type: System.Reflection.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.
Type: System.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.
Type: System.Reflection.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.
Type: System.Globalization.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. Note   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.
Type: System.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.
Type: System.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).

Return Value

Type: MethodBase
The matching method.
AmbiguousMatchExceptionFor 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.
MissingMethodExceptionFor the default binder, match contains no methods that can accept the arguments supplied in args.
ArgumentExceptionFor the default binder, match is null or an empty array.
See Also