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

定義

根據提供的引數,從一組指定的方法中選取要叫用 (Invoke) 的方法。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);
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 值的位元組合。A bitwise combination of BindingFlags values.

match
MethodBase[]

可能相符的方法集合。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.

args
Object[]

傳入的引數。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. 如果繫結器實作強制型轉了引數型別 (Argument Type),引數的型別和值也可能會變更。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

CultureInfo 的執行個體 (Instance),用來控制強制型轉型別的繫結器 (Binder) 實作中資料型別的強制型轉 (Coercion)。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.

注意:例如,如果繫結器實作允許您將字串值強制型轉為數值,則將表示 1000 的 String 轉換成 Double 值時必須使用這個參數,因為 1000 在不同的文化特性中有不同的表示方式。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.

names
String[]

如果比對時必須考慮參數名稱,便為參數名稱;如果只將引數視為單純的位置引數,則為 nullThe 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

在此方法傳回之後,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. 如果 null 傳回時 state 不是 BindToMethod,而且您想要將 state 還原成原來的順序,使您可以擷取 ref 參數 (在 Visual Basic 中為 ByRef 參數) 的值,就必須將 args 傳遞至 ReorderArgumentArray(Object[], 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.

例外狀況

如果是預設繫結器,match 將包含同樣都與 args 相符的多個方法。For the default binder, match contains multiple methods that are equally good matches for args. 例如,args 包含的 MyClass 物件會實作 IMyClass 介面,而 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.

如果是預設繫結器 (Binder),match 會是 null 或空白陣列。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.

如果引數陣列已由BindToMethod操作,則系結器可讓用戶端將引數的陣列對應回其原始格式。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. 參數會追蹤引數的重新排列順序,因此可讓ReorderArgumentArray系結器的方法將引數陣列重新排序為其原始格式。 stateThe 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.

適用於

另請參閱