AttributeTable.GetCustomAttributes 方法 (Type, String)

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

返回提供给指定的类型和成员名称的所有特性的枚举。

命名空间:  Microsoft.Windows.Design.Metadata
程序集:  Microsoft.Windows.Design.Extensibility(在 Microsoft.Windows.Design.Extensibility.dll 中)

语法

声明
Public Function GetCustomAttributes ( _
    ownerType As Type, _
    memberName As String _
) As IEnumerable
public IEnumerable GetCustomAttributes(
    Type ownerType,
    string memberName
)
public:
IEnumerable^ GetCustomAttributes(
    Type^ ownerType, 
    String^ memberName
)
member GetCustomAttributes : 
        ownerType:Type * 
        memberName:string -> IEnumerable 
public function GetCustomAttributes(
    ownerType : Type, 
    memberName : String
) : IEnumerable

参数

  • ownerType
    类型:System.Type
    依赖项属性的所属类型。
  • memberName
    类型:System.String
    要为其提供特性的成员的名称。

返回值

类型:System.Collections.IEnumerable
特性的枚举。

异常

异常 条件
ArgumentNullException

ownerType 或 memberName 为 nulla null reference (Nothing in Visual Basic)。

备注

此方法从不返回 nulla null reference (Nothing in Visual Basic) 枚举。

示例

下面的代码示例演示如何使用 GetCustomAttributes 方法来获取成员的自定义特性。 此代码示例摘自为 AttributeTable 类提供的一个更大的示例。

Dim attrs1 As IEnumerable = attributes.GetCustomAttributes(GetType(Button), "Background")
IEnumerable attrs1 = attributes.GetCustomAttributes(
    typeof(Button),
    "Background");

.NET Framework 安全性

请参见

参考

AttributeTable 类

GetCustomAttributes 重载

Microsoft.Windows.Design.Metadata 命名空间

AttributeTableBuilder