IReflect.InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]) IReflect.InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]) IReflect.InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]) Method


调用指定的成员。Invokes a specified member.

 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 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);
abstract member InvokeMember : string * System.Reflection.BindingFlags * System.Reflection.Binder * obj * obj[] * System.Reflection.ParameterModifier[] * System.Globalization.CultureInfo * string[] -> obj


String String String

要查找的成员的名称。The name of the member to find.

BindingFlags BindingFlags BindingFlags

BindingFlags 调用特性之一。One of the BindingFlags invocation attributes. invokeAttr 参数可以是构造函数、方法、属性或字段。The invokeAttr parameter may be a constructor, method, property, or field. 必须指定合适的调用属性。A suitable invocation attribute must be specified. 通过将空字符串 ("") 作为成员的名称传递来调用类的默认成员。Invoke the default member of a class by passing the empty string ("") as the name of the member.

Binder Binder Binder

BindingFlags 位标志之一。One of the BindingFlags bit flags. 实现 Binder,包含与此方法相关的属性。Implements Binder, containing properties related to this method.

Object Object Object

对其调用指定成员的对象。The object on which to invoke the specified member. 对于静态成员,此参数被忽略。This parameter is ignored for static members.


包含要调用的成员的参数数目、顺序和类型的对象数组。An array of objects that contains the number, order, and type of the parameters of the member to be invoked. 如果没有参数,则这是一个空数组。This is an empty array if there are no parameters.


一个 ParameterModifier 对象数组。An array of ParameterModifier objects. 此数组与表示元数据中被调用成员的参数属性的 args 参数具有相同的长度。This array has the same length as the args parameter, representing the invoked member's argument attributes in the metadata. 参数可以有下列属性:pdInpdOutpdRetvalpdOptionalpdHasDefaultA parameter can have the following attributes: pdIn, pdOut, pdRetval, pdOptional, and pdHasDefault. 这些属性分别表示 [In]、[Out]、[retval]、[optional] 和默认参数。These represent [In], [Out], [retval], [optional], and a default parameter, respectively. 这些属性由不同的互操作性服务使用。These attributes are used by various interoperability services.

CultureInfo CultureInfo CultureInfo

用于控制类型强制的 CultureInfo 的实例。An instance of CultureInfo used to govern the coercion of types. 例如,culture 将表示 1000 的 String 转换为 Double 值,因为不同的区域性以不同的方式表示 1000。For example, culture converts a String that represents 1000 to a Double value, since 1000 is represented differently by different cultures. 如果此参数为 null,则使用当前线程的 CultureInfoIf this parameter is null, the CultureInfo for the current thread is used.


参数的 String 数组。A String array of parameters.


指定的成员。The specified member.


为字段 set 指定了多个参数。More than one argument is specified for a field set.

找不到此字段或属性。The field or property cannot be found.

找不到此方法。The method cannot be found.

在没有所需 ReflectionPermission 的情况下调用私有成员。A private member is invoked without the necessary ReflectionPermission.


以下示例获取的值Now属性。The following example obtains the value of the Now property.

#using <System.DLL>

using namespace System;
using namespace System::Reflection;

#define NULL 0
void main()
   Type^ tDate = Type::GetType( L"System.DateTime" );
   Object^ result = tDate->InvokeMember( L"Now", BindingFlags::GetProperty, nullptr, NULL, gcnew array<Object^>(0) );
   Console::WriteLine( result->ToString() );

using System;
using System.Reflection;

public class MainClass 
    public static void Main(string[] args)
        Type tDate = typeof(System.DateTime);
        Object result = tDate.InvokeMember("Now", 
            BindingFlags.GetProperty, null, null, new Object[0]);
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class MainClass
    Public Overloads Shared Sub Main(ByVal args() As String)
        Dim tDate As Type = GetType(System.DateTime)
        Dim result As [Object] = tDate.InvokeMember("Now", _
            BindingFlags.GetProperty, Nothing, Nothing, New [Object](-1) {})
    End Sub 'Main
End Class 'MainClass


在指定的活页夹和调用属性的约束下,要调用的方法必须为可访问,并且提供与指定的自变量列表最具体的匹配。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.

如果在方法声明中的参数数量等于指定的参数列表中的参数数目和每个自变量的类型可以转换为参数的类型的联编程序通过,调用方法。A method is 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.


参数修饰符的数组传递给InvokeMember方法必须包含单个参数修饰符。The array of parameter modifiers passed to the InvokeMember method must contain a single parameter modifier. 当确定哪些参数需要通过引用向 COM 公开时传递时,被视为仅第一个参数修饰符Only the first parameter modifier is considered when determining which argument needs to be passed by reference when exposed to COM.

此联编程序查找所有匹配的方法,根据请求的绑定类型 (BindingFlags.InvokeMethodGetProperties,依此类推)。The binder finds all matching methods, in accordance with the type of binding requested (BindingFlags.InvokeMethod, 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 is invoked, and accessibility is checked at that point. 搜索可能来控制哪些组的方法是基于与方法关联的可访问性特性。The search may control which set of methods is searched based upon the accessibility attribute associated with the method. BindToMethod 选择要调用的方法。BindToMethod selects 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 through reflection whenever the code is fully trusted.