AttributeTable.GetCustomAttributes 方法 (Type)
返回提供给指定类型的所有特性的枚举。
命名空间: Microsoft.Windows.Design.Metadata
程序集: Microsoft.Windows.Design.Extensibility(在 Microsoft.Windows.Design.Extensibility.dll 中)
语法
声明
Public Function GetCustomAttributes ( _
type As Type _
) As IEnumerable
public IEnumerable GetCustomAttributes(
Type type
)
public:
IEnumerable^ GetCustomAttributes(
Type^ type
)
member GetCustomAttributes :
type:Type -> IEnumerable
public function GetCustomAttributes(
type : Type
) : IEnumerable
参数
- type
类型:System.Type
要为其获取类级别特性的类型。
返回值
类型:System.Collections.IEnumerable
特性的枚举。
异常
异常 | 条件 |
---|---|
ArgumentNullException | type 为 nullnull 引用(在 Visual Basic 中为 Nothing)。 |
备注
此方法从不返回 nullnull 引用(在 Visual Basic 中为 Nothing) 枚举。
示例
下面的代码示例演示如何使用 GetCustomAttributes 方法来获取类型的自定义特性。 此代码示例摘自为 AttributeTable 类提供的一个更大的示例。
Dim attrs0 As IEnumerable = attributes.GetCustomAttributes(GetType(Button))
IEnumerable attrs0 = attributes.GetCustomAttributes(typeof(Button));
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。