Binder.BindToMethod 方法

定义

基于提供的参数,从给定的方法集中选择要调用的方法。

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

BindingFlags 值的按位组合。

match
MethodBase[]

用于匹配的候选方法集。 例如,当 Binder 使用 InvokeMember 对象时,此参数将指定反射已确定为可能匹配项的方法集,通常是因为它们有正确的成员名称。 由 DefaultBinder 提供的默认实现会更改此数组的顺序。

args
Object[]

传入的参数。 联编程序可以更改此数组中的参数的顺序;例如,如果 names 参数用于指定位置顺序以外的顺序,则默认联编程序会更改参数的顺序。 如果联编程序实现强制转换参数类型,则也可以更改参数的类型和值。

modifiers
ParameterModifier[]

使绑定能够处理在其中修改了类型的参数签名的参数修饰符数组。 默认的联编程序实现不使用此参数。

culture
CultureInfo

一个 CultureInfo 实例,用于在强制类型的联编程序实现中控制数据类型强制。 如果 culturenull,则使用当前线程的 CultureInfo

names
String[]

参数名(如果匹配时要考虑参数名)或 null(如果要将变量视为纯位置)。 例如,如果没有按位置顺序提供变量,则必须使用参数名。

state
Object

方法返回之后,state 包含一个联编程序提供的对象,用于跟踪参数的重新排序。 联编程序创建此对象,并且联编程序是此对象的唯一使用者。 如果在返回 nullstate 不为 BindToMethod,若要将 state 还原为其原始顺序,您必须将 args 传递给 ReorderArgumentArray(Object[], Object) 方法,以便可以检索 ref 参数(在 Visual Basic 中为 ByRef)的值。

返回

匹配的方法。

例外

对于默认联编程序,match 包含多个与 args 良好匹配且匹配程序相同的方法。 例如, args 包含实现 MyClass 接口的对象 IMyClass ,并 match 包含采用 MyClass 的方法和采用 IMyClass的方法。

对于默认联编程序,match 不包含可以接受 args 中提供的参数的任何方法。

对于默认联编程序,matchnull 或一个空数组。

注解

默认绑定器同时考虑在 Visual Basic) 中具有值和 params 数组 (ParamArray 数组的参数。 因此,在 和 match 不包含相同数量的元素的情况下args,可以找到匹配项。

如果参数数组已由 BindToMethod操作,则通过绑定器,客户端可以将参数数组映射回其原始形式。 当存在此类参数时,使用此重新映射功能可取回引用参数。 按名称传递参数时,绑定器对参数数组重新排序。 参数 state 会跟踪参数重新排序,从而使绑定器的 ReorderArgumentArray 方法能够将参数数组重新排序为其原始形式。

BindToMethod方法由 Type.InvokeMember 方法使用。

如果绑定器实现允许将字符串值强制转换为数值类型, culture 则需要 参数将表示 1000 的字符串转换为 Double 值,因为 1000 由不同区域性表示的方式不同。 默认联编程序不进行此类字符串强制。

适用于

另请参阅