Type.GetPropertyImpl 方法

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

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

语法

声明
Protected MustOverride Function GetPropertyImpl ( _
    name As String, _
    bindingAttr As BindingFlags, _
    binder As Binder, _
    returnType As Type, _
    types As Type(), _
    modifiers As ParameterModifier() _
) As PropertyInfo
用法
Dim name As String
Dim bindingAttr As BindingFlags
Dim binder As Binder
Dim returnType As Type
Dim types As Type()
Dim modifiers As ParameterModifier()
Dim returnValue As PropertyInfo

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

参数

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

    - 或 -

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

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

    - 或 -

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

  • returnType
    属性的返回类型。
  • types
    表示要获取的索引属性的参数的个数、顺序和类型的 Type 对象数组。

    - 或 -

    获取未被索引的属性的 Type 类型的空数组(即 Type[] types = new Type[0])。

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

返回值

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

异常

异常类型 条件

AmbiguousMatchException

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

ArgumentNullException

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

- 或 -

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] 和一个指定参数是否有默认值的值。参数的关联特属性存储在元数据中并且用于交互操作。

可以使用下列 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)。

平台

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 命名空间
PropertyInfo
String 类
BindingFlags
Binder
DefaultBinder
ParameterModifier
ReflectionPermission
GetProperty
GetProperties