TypeBuilder.InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]) 方法

定義

叫用指定的成員。Invokes the specified member. 根據指定繫結器和引動過程屬性的條件約束,所要叫用的方法必須可存取,並提供與指定引數清單最特定的符合項目。The method that is to be invoked must be accessible and provide the most specific match with the specified argument list, under the constraints of the specified binder and invocation attributes.

public:
 override System::Object ^ InvokeMember(System::String ^ name, System::Reflection::BindingFlags invokeAttr, System::Reflection::Binder ^ binder, System::Object ^ target, cli::array <System::Object ^> ^ args, cli::array <System::Reflection::ParameterModifier> ^ modifiers, System::Globalization::CultureInfo ^ culture, cli::array <System::String ^> ^ namedParameters);
public override object? InvokeMember (string name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object? target, object?[]? args, System.Reflection.ParameterModifier[]? modifiers, System.Globalization.CultureInfo? culture, string[]? namedParameters);
public override object InvokeMember (string name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object target, object[] args, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters);
override this.InvokeMember : string * System.Reflection.BindingFlags * System.Reflection.Binder * obj * obj[] * System.Reflection.ParameterModifier[] * System.Globalization.CultureInfo * string[] -> obj
Public Overrides Function InvokeMember (name As String, invokeAttr As BindingFlags, binder As Binder, target As Object, args As Object(), modifiers As ParameterModifier(), culture As CultureInfo, namedParameters As String()) As Object

參數

name
String

要叫用之成員的名稱。The name of the member to invoke. 可以是建構函式、方法、屬性或欄位。This can be a constructor, method, property, or field. 您必須指定適當的引動過程屬性。A suitable invocation attribute must be specified. 請注意,將空字串當做成員名稱傳遞,可叫用類別的預設成員。Note that it is possible to invoke the default member of a class by passing an empty string as the name of the member.

invokeAttr
BindingFlags

引動過程屬性。The invocation attribute. 必須是來自 BindingFlags 的位元旗標。This must be a bit flag from BindingFlags.

binder
Binder

使用反映來啟用繫結、強制引數的類型、成員的引動過程,和擷取 MemberInfo 物件的物件。An object that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects using reflection. 如果繫結器為 null,則會使用預設繫結器。If binder is null, the default binder is used. 請參閱 BinderSee Binder.

target
Object

要在其上叫用指定成員的物件。The object on which to invoke the specified member. 如果是靜態成員,則會忽略這個參數。If the member is static, this parameter is ignored.

args
Object[]

引數清單。An argument list. 這是物件陣列,其中包含所要叫用之成員的參數數目、順序和類型。This is an array of Objects that contains the number, order, and type of the parameters of the member to be invoked. 如果沒有任何參數,則這應該是 null。If there are no parameters this should be null.

modifiers
ParameterModifier[]

args 長度相同的陣列,其中的項目代表與所要叫用的成員之引數關聯的屬性。An array of the same length as args with elements that represent the attributes associated with the arguments of the member to be invoked. 參數在中繼資料內具有與其相關聯的屬性。A parameter has attributes associated with it in the metadata. 許多互通性服務都會使用這些屬性。They are used by various interoperability services. 如需詳細資訊,請參閱中繼資料規格。See the metadata specs for more details.

culture
CultureInfo

CultureInfo 的執行個體,用於管理類型的強制型轉。An instance of CultureInfo used to govern the coercion of types. 如果這是 null,會使用目前執行緒的 CultureInfoIf this is null, the CultureInfo for the current thread is used. (請注意,要將代表 1000 的 String 轉換成 Double 值時,這是必要的,因為 1000 的表示方式會因不同文化特性而有所不同)。(Note that this is necessary to, for example, convert a String that represents 1000 to a Double value, since 1000 is represented differently by different cultures.)

namedParameters
String[]

namedParameters 陣列中的每個參數會在 args 陣列中取得對應項目的值。Each parameter in the namedParameters array gets the value in the corresponding element in the args array. 如果 args 的長度大於 namedParameters 的長度,則會依序傳遞其餘引數值。If the length of args is greater than the length of namedParameters, the remaining argument values are passed in order.

傳回

Object

傳回所叫用之成員的傳回值。Returns the return value of the invoked member.

例外狀況

這個方法目前不支援不完整的類型。This method is not currently supported for incomplete types.

備註

如果方法宣告中的參數數目等於指定引數清單中的引數數目,而且每個引數的類型都可以由系結器轉換成參數的類型,則會叫用方法。A method will be invoked if the number of parameters in the method declaration equals the number of arguments in the specified argument list, and the type of each argument can be converted by the binder to the type of the parameter.

系結器會尋找所有相符的方法。The binder will find all of the matching methods. 這些方法會根據要求的系結類型 (BindingFlags. InvokeMethod、BindingFlags GetProperties 等等來找到。 ) 。These methods are found based on the type of binding requested (BindingFlags.InvokeMethod, BindingFlags.GetProperties, and so on.). 這組方法會依名稱、引數數目和系結器中定義的一組搜尋修飾詞進行篩選。The set of methods is filtered by the name, number of arguments, and a set of search modifiers defined in the binder. 選取方法之後,將會叫用此方法。After the method is selected, it will be invoked. 協助工具會在該時間點檢查。Accessibility is checked at that point. 搜尋可以根據與方法相關聯的協助工具屬性,來控制要搜尋的方法集合。The search can control which set of methods are searched based upon the accessibility attribute associated with the method. IBinder.BindToMethod方法負責選取要叫用的方法。The IBinder.BindToMethod method is responsible for selecting the method to be invoked. 預設系結器會選取最特定的相符項。The default binder selects the most specific match.

注意

完全信任的程式碼會略過存取限制。Access restrictions are ignored for fully trusted code. 也就是說,每當程式碼完全受信任時,就可以使用反映來存取及叫用私用的函式、方法、欄位和屬性。That is, private constructors, methods, fields, and properties can be accessed and invoked using Reflection whenever the code is fully trusted.

目前不支援這個方法。This method is not currently supported. 您可以使用或來取得型別 Type.GetType Assembly.GetType ,並且在抓取的型別上使用反映。You can retrieve the type using Type.GetType or Assembly.GetType and use reflection on the retrieved type.

適用於