Binder.BindToMethod 方法

定義

根據提供的引數,從一組指定的方法中選取要叫用 (Invoke) 的方法。

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 參數來指定位置順序以外的其他順序,預設繫結器就會變更引數的順序。 如果繫結器實作強制型轉了引數型別 (Argument Type),引數的型別和值也可能會變更。

modifiers
ParameterModifier[]

參數修飾詞的陣列,啟用繫結以使用型別已被修改的參數簽章。 預設繫結器實作時並不會使用這個參數。

culture
CultureInfo

CultureInfo 的執行個體 (Instance),用來控制強制型轉型別的繫結器 (Binder) 實作中資料型別的強制型轉 (Coercion)。 如果 culturenull,會使用目前執行緒的 CultureInfo

names
String[]

如果比對時必須考慮參數名稱,便為參數名稱;如果只將引數視為單純的位置引數,則為 null。 例如,如果位置順序中並未提供引數,您就必須使用參數名稱。

state
Object

在此方法傳回之後,state 就會包含繫結器提供的物件,用以記錄引數重新調整順序。 繫結器會建立這個物件,而且也是這個物件的唯一使用者。 如果 null 傳回時 state 不是 BindToMethod,而且您想要將 state 還原成原來的順序,使您可以擷取 ref 參數 (在 Visual Basic 中為 ByRef 參數) 的值,就必須將 args 傳遞至 ReorderArgumentArray(Object[], Object) 方法。

傳回

符合的方法。

例外狀況

如果是預設繫結器,match 將包含同樣都與 args 相符的多個方法。 例如, args 包含實 MyClassIMyClass 介面的 物件,並 match 包含採用 的方法 MyClass ,以及採用 IMyClass 的方法。

如果是預設繫結器,match 不會包含可以接受 args 中提供之引數的方法。

如果是預設繫結器 (Binder),match 會是 null 或空白陣列。

備註

預設系結器會考慮在 Visual Basic) 中具有值和 params 陣列 (ParamArray 陣列的參數。 因此,如果 和 argsmatch 不包含相同數目的專案,就可以找到相符專案。

如果引數陣列已由 BindToMethod 操作,系結器可讓用戶端將引數的陣列對應回其原始格式。 當這類引數存在時,請使用這個重新對應功能來取回參考引數。 當您依名稱傳遞引數時,系結器會重新排序引數陣列。 參數 state 會持續追蹤引數重新排序,因此讓系結器 ReorderArgumentArray 的方法將引數陣列重新排序為其原始形式。

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

如果系結器實作允許將字串值強制轉型為數數值型別, culture 則必須將代表 1000 的字串轉換成值,因為 1000 Double 會以不同的文化特性以不同的方式表示。 預設的繫結器不會處理這種字串強制型轉。

適用於

另請參閱