AttributeTable.GetCustomAttributes 方法 (Type, String)
會傳回提供給所指定型別和成員名稱之所有屬性 (Attribute) 的列舉。
命名空間: 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
相依性屬性 (Property) 的擁有者型別。
- memberName
型別:System.String
要為其提供屬性 (Attribute) 的成員名稱。
傳回值
型別:System.Collections.IEnumerable
屬性 (Attribute) 的列舉型別。
例外狀況
例外狀況 | 條件 |
---|---|
ArgumentNullException | ownerType 或 memberName 是 nullNull 參照 (即 Visual Basic 中的 Nothing)。 |
備註
這個方法決不會傳回 nullNull 參照 (即 Visual Basic 中的 Nothing) 列舉型別。
範例
在下列程式碼範例中,會說明如何使用 GetCustomAttributes 方法,取得成員的自訂屬性 (Attribute)。 這個程式碼範例是 AttributeTable 類別完整範例的一部分。
Dim attrs1 As IEnumerable = attributes.GetCustomAttributes(GetType(Button), "Background")
IEnumerable attrs1 = attributes.GetCustomAttributes(
typeof(Button),
"Background");
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。