Share via


Type.GetConstructorImpl 方法

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

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

语法

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

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

参数

  • bindingAttr
    一个位屏蔽,由一个或多个指定搜索执行方式的 BindingFlags 组成。

    - 或 -

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

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

    - 或 -

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

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

    - 或 -

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

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

返回值

表示符合指定要求的构造函数的 ConstructorInfo 对象(如果找到的话);否则为 空引用(在 Visual Basic 中为 Nothing)。

异常

异常类型 条件

ArgumentNullException

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

- 或 -

types 中的一个元素为 空引用(在 Visual Basic 中为 Nothing)。

ArgumentException

types 是多维的。

- 或 -

modifiers 是多维的。

- 或 -

types 和 modifiers 的长度不同。

备注

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

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

如果不存在完全匹配项,binder 将尝试强制 types 数组中指定的参数类型以便选择一个匹配项。如果 binder 无法选择匹配项,则返回 空引用(在 Visual Basic 中为 Nothing)。

下列 BindingFlags 筛选标志可用于定义要包含在搜索中的构造函数:

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

  • 指定 BindingFlags.Public 可在搜索中包含公共构造函数。

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

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

此方法实现 GetConstructor

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

GetConstructorGetConstructorImpl 不能用于获得类初始值设定项。只能通过 GetMemberGetMembersFindMembersGetConstructors 使用类初始值设定项。

.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 命名空间
ConstructorInfo
BindingFlags
Binder
DefaultBinder
CallingConventions
ParameterModifier
ReflectionPermission
GetConstructor
GetConstructors