Binder.BindToMethod(BindingFlags, MethodBase[], Object[], ParameterModifier[], CultureInfo, String[], Object) 方法


基于提供的参数,从给定的方法集中选择要调用的方法。Selects a method to invoke from the given set of methods, based on the supplied arguments.

 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



BindingFlags 值的按位组合。A bitwise combination of BindingFlags values.


用于匹配的候选方法集。The set of methods that are candidates for matching. 例如,当 Binder 使用 InvokeMember 对象时,此参数将指定反射已确定为可能匹配项的方法集,通常是因为它们有正确的成员名称。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. DefaultBinder 提供的默认实现会更改此数组的顺序。The default implementation provided by DefaultBinder changes the order of this array.


传入的参数。The arguments that are passed in. 联编程序可以更改此数组中的参数的顺序;例如,如果 names 参数用于指定位置顺序以外的顺序,则默认联编程序会更改参数的顺序。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.


使绑定能够处理在其中修改了类型的参数签名的参数修饰符数组。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.


一个 CultureInfo 实例,用于在强制类型的联编程序实现中控制数据类型强制。An instance of CultureInfo that is used to control the coercion of data types, in binder implementations that coerce types. 如果 culturenull,则使用当前线程的 CultureInfoIf culture is null, the CultureInfo for the current thread is used.


参数名(如果匹配时要考虑参数名)或 null(如果要将变量视为纯位置)。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 包含一个联编程序提供的对象,用于跟踪参数的重新排序。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. 如果在返回 nullstate 不为 BindToMethod,若要将 state 还原为其原始顺序,您必须将 args 传递给 ReorderArgumentArray(Object[], Object) 方法,以便可以检索 ref 参数(在 Visual Basic 中为 ByRef)的值。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.


对于默认联编程序,match 包含多个与 args 良好匹配且匹配程序相同的方法。For the default binder, match contains multiple methods that are equally good matches for args. 例如,args 包含一个实现 IMyClass 接口的 MyClass 对象,并且 match 包含一个采用 MyClass 的方法和一个采用 IMyClass 的方法。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.

对于默认联编程序,match 不包含可以接受 args 中提供的参数的任何方法。For the default binder, match contains no methods that can accept the arguments supplied in args.

对于默认联编程序,matchnull 或一个空数组。For the default binder, match is null or an empty array.


默认联编程序会将具有值和数组的两个参数都 params (ParamArray 数组 Visual Basic) 中。The default binder takes into account both parameters that have values and params arrays (ParamArray arrays in Visual Basic). 因此,在 argsmatch 不包含相同数量的元素的情况下,可能会找到匹配项。Thus, it is possible to find a match in cases where args and match do not contain the same number of elements.

如果参数数组已被操作,则该联编程序使客户端能够将参数数组重新映射回其原始形式 BindToMethodThe 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. state参数跟踪参数的重新排序,从而使联编程序的 ReorderArgumentArray 方法能够将参数数组重新排序为其原始形式。The state parameter keeps track of argument reordering, thus enabling the binder's ReorderArgumentArray method to reorder the argument array to its original form.

方法由 BindToMethod Type.InvokeMember 方法使用。The BindToMethod method is used by the Type.InvokeMember method.

如果联编程序实现允许将字符串值强制转换为数值类型,则 culture 参数对于将表示1000的字符串转换为值是必需的 Double ,因为不同的区域性以不同的方式表示1000。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.