Share via


Type.GetMethodImpl 方法

当在派生类中重写时,使用指定的绑定约束和指定的调用约定搜索其参数与指定的参数类型和修饰符匹配的指定方法。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Protected MustOverride Function GetMethodImpl ( _
    name As String, _
    bindingAttr As BindingFlags, _
    binder As Binder, _
    callConvention As CallingConventions, _
    types As Type(), _
    modifiers As ParameterModifier() _
) As MethodInfo
用法
Dim name As String
Dim bindingAttr As BindingFlags
Dim binder As Binder
Dim callConvention As CallingConventions
Dim types As Type()
Dim modifiers As ParameterModifier()
Dim returnValue As MethodInfo

returnValue = Me.GetMethodImpl(name, bindingAttr, binder, callConvention, types, modifiers)
protected abstract MethodInfo GetMethodImpl (
    string name,
    BindingFlags bindingAttr,
    Binder binder,
    CallingConventions callConvention,
    Type[] types,
    ParameterModifier[] modifiers
)
protected:
virtual MethodInfo^ GetMethodImpl (
    String^ name, 
    BindingFlags bindingAttr, 
    Binder^ binder, 
    CallingConventions callConvention, 
    array<Type^>^ types, 
    array<ParameterModifier>^ modifiers
) abstract
protected abstract MethodInfo GetMethodImpl (
    String name, 
    BindingFlags bindingAttr, 
    Binder binder, 
    CallingConventions callConvention, 
    Type[] types, 
    ParameterModifier[] modifiers
)
protected abstract function GetMethodImpl (
    name : String, 
    bindingAttr : BindingFlags, 
    binder : Binder, 
    callConvention : CallingConventions, 
    types : Type[], 
    modifiers : ParameterModifier[]
) : MethodInfo

参数

  • name
    包含要获取的方法名称的 String
  • bindingAttr
    一个位屏蔽,由一个或多个指定搜索执行方式的 BindingFlags 组成。

    - 或 -

    零,以返回 空引用(在 Visual Basic 中为 Nothing)。

  • binder
    一个 Binder 对象,该对象定义一组属性并启用绑定,而绑定可能涉及选择重载方法、强制参数类型和通过反射调用成员。

    - 或 -

    若为 空引用(在 Visual Basic 中为 Nothing),则使用 DefaultBinder

  • callConvention
    CallingConventions 对象,用于指定要使用的一套规则,这些规则涉及参数的顺序和布局、传递返回值的方式、用于参数的寄存器以及哪个进程清理堆栈。
  • types
    表示此方法要获取的参数的个数、顺序和类型的 Type 对象数组。

    - 或 -

    获取不使用参数的方法的 Type 类型的空数组(即 Type[] types = new Type[0])。

    - 或 -

    空引用(在 Visual Basic 中为 Nothing)。如果 types 为 空引用(在 Visual Basic 中为 Nothing),则参数不匹配。

  • modifiers
    ParameterModifier 对象数组,表示与 types 数组中的相应元素关联的属性。默认的联编程序不处理此参数。

返回值

表示符合指定要求的方法的 MethodInfo 对象(如果找到的话);否则为 空引用(在 Visual Basic 中为 Nothing)。

异常

异常类型 条件

AmbiguousMatchException

找到多个有指定名称且与指定绑定约束匹配的方法。

ArgumentNullException

name 为 空引用(在 Visual Basic 中为 Nothing)。

ArgumentException

types 是多维的。

- 或 -

modifiers 是多维的。

- 或 -

types 和 modifiers 的长度不同。

备注

尽管默认的联编程序不处理 ParameterModifier(modifiers 参数),您仍然可以使用抽象 System.Reflection.Binder 类编写会处理 modifiers 的自定义联编程序。仅当通过 COM interop 进行调用时才使用 ParameterModifier,并且仅处理通过引用传递的参数。

如果 types 为 空引用(在 Visual Basic 中为 Nothing),则参数不匹配。

types 数组和 modifiers 数组的长度相同。types 数组中指定的参数可具有下列在 modifiers 数组中指定的属性 (Attribute):pdIn、pdOut、pdLcid、pdRetval、pdOptional 和 pdHasDefault,它们分别表示 [In]、[Out]、[lcid]、[retval]、[optional] 和一个指定参数是否有默认值的值。参数的关联属性 (Attribute) 存储在元数据中并且增强了交互操作。

可以使用下列 BindingFlags 筛选标志定义包含在搜索中的方法:

  • 为了获取返回值,必须指定 BindingFlags.InstanceBindingFlags.Static

  • 指定 BindingFlags.Public 可在搜索中包含公共方法。

  • 指定 BindingFlags.NonPublic 可在搜索中包含非公共成员(即私有成员和受保护的成员)。

  • 指定 BindingFlags.FlattenHierarchy 以便沿层次结构向上包括 publicprotected 静态成员;不包括继承类中的 private 静态成员。

下列 BindingFlags 修饰符标志可用于更改搜索的执行方式:

  • BindingFlags.IgnoreCase,表示忽略 name 的大小写。

  • BindingFlags.DeclaredOnly,表示仅搜索在 Type 上声明的方法,而不搜索简单继承的方法。

有关更多信息,请参见 System.Reflection.BindingFlags

如果请求的类型是非公共类型,并且调用方不具有 ReflectionPermission 来反射当前程序集之外的非公共对象,则此方法返回 空引用(在 Visual Basic 中为 Nothing)。

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Type 类
Type 成员
System 命名空间
MethodInfo
String 类
BindingFlags
Binder
DefaultBinder
CallingConventions
ParameterModifier
ReflectionPermission
GetMethod
GetMethods