TypeDescriptor.GetAttributes 方法

定義

傳回元件或類型的屬性集合。

多載

GetAttributes(Object)

傳回指定元件的屬性集合。

GetAttributes(Type)

傳回指定元件類型的屬性集合。

GetAttributes(Object, Boolean)

傳回指定元件的屬性集合,以及表示是否已建立自訂類型描述元的布林值。

GetAttributes(Object)

來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs

傳回指定元件的屬性集合。

public:
 static System::ComponentModel::AttributeCollection ^ GetAttributes(System::Object ^ component);
public static System.ComponentModel.AttributeCollection GetAttributes (object component);
static member GetAttributes : obj -> System.ComponentModel.AttributeCollection
Public Shared Function GetAttributes (component As Object) As AttributeCollection

參數

component
Object

您要取得屬性的元件。

傳回

AttributeCollection,其包含元件的屬性。 如果 componentnull,這個方法會傳回空集合。

範例

如需這個方法的範例,請參閱 Matches 方法。

備註

方法所 GetAttributes 傳回的屬性可以從原始元件的來源清單中,由擴充項提供者動態修改 () IExtenderProvider 、篩選服務 (ITypeDescriptorFilterService) 和屬性篩選。

當您定義已設定為true的自定義屬性AttributeUsageAttribute.AllowMultiple時,必須覆寫 Attribute.TypeId 屬性,使其是唯一的。 如果屬性的所有實例都是唯一的,請覆寫 Attribute.TypeId 以傳回屬性的對象識別。 如果只有某些屬性實例是唯一的,請從 Attribute.TypeId 傳回值,以在這些情況下傳回相等。 例如,某些屬性具有建構函式參數,做為唯一索引鍵。 針對這些屬性,從 Attribute.TypeId 屬性傳回建構函式參數的值。

注意

的預設實 Attribute.TypeId 作會傳回型別識別,而不論 屬性的值 AttributeUsageAttribute.AllowMultiple 為何。 若要從 AttributeCollection傳回屬性的AttributeUsageAttribute.AllowMultiple多個實例,您的屬性必須覆寫 Attribute.TypeId 屬性。

另請參閱

適用於

GetAttributes(Type)

來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs

傳回指定元件類型的屬性集合。

public:
 static System::ComponentModel::AttributeCollection ^ GetAttributes(Type ^ componentType);
public static System.ComponentModel.AttributeCollection GetAttributes (Type componentType);
static member GetAttributes : Type -> System.ComponentModel.AttributeCollection
Public Shared Function GetAttributes (componentType As Type) As AttributeCollection

參數

componentType
Type

目標元件的 Type

傳回

內含這個元件類型之屬性的 AttributeCollection。 如果元件為 null,這個方法會傳回空集合。

備註

只有在您沒有 對象的實例時,才呼叫這個版本的這個方法。

對於設定為true的屬性AttributeUsageAttribute.AllowMultiple,屬性集合會移除重複的實例。 這些是 屬性傳回相等值的實例 Attribute.TypeId

當您定義已設定為true的自定義屬性AttributeUsageAttribute.AllowMultiple時,必須覆寫 Attribute.TypeId 屬性,使其是唯一的。 如果屬性的所有實例都是唯一的,請覆寫 Attribute.TypeId 以傳回屬性的對象識別。 如果只有某些屬性實例是唯一的,請從 Attribute.TypeId 傳回值,以在這些情況下傳回相等。 例如,某些屬性具有建構函式參數,做為唯一索引鍵。 針對這些屬性,從 Attribute.TypeId 屬性傳回建構函式參數的值。

注意

的預設實 Attribute.TypeId 作會傳回型別識別,而不論 屬性的值 AttributeUsageAttribute.AllowMultiple 為何。 若要從 AttributeCollection傳回屬性的AttributeUsageAttribute.AllowMultiple多個實例,您的屬性必須覆寫 Attribute.TypeId 屬性。

另請參閱

適用於

GetAttributes(Object, Boolean)

來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs
來源:
TypeDescriptor.cs

傳回指定元件的屬性集合,以及表示是否已建立自訂類型描述元的布林值。

public:
 static System::ComponentModel::AttributeCollection ^ GetAttributes(System::Object ^ component, bool noCustomTypeDesc);
public static System.ComponentModel.AttributeCollection GetAttributes (object component, bool noCustomTypeDesc);
static member GetAttributes : obj * bool -> System.ComponentModel.AttributeCollection
Public Shared Function GetAttributes (component As Object, noCustomTypeDesc As Boolean) As AttributeCollection

參數

component
Object

您要取得屬性的元件。

noCustomTypeDesc
Boolean

true 表示當 component 屬於 ICustomTypeDescriptor 類型時,使用自訂類型描述元中的一組基準屬性,否則為 false

傳回

內含這個元件之屬性的 AttributeCollection。 如果元件為 null,這個方法會傳回空集合。

備註

方法傳 GetAttributes 回的屬性可以從擴充項提供者的原始元件來源清單中動態修改, () IExtenderProvider 、篩選服務 (ITypeDescriptorFilterService) 和屬性篩選。

當您定義已設定為true的自定義屬性AttributeUsageAttribute.AllowMultiple時,必須覆寫 Attribute.TypeId 屬性,使其是唯一的。 如果屬性的所有實例都是唯一的,請覆寫 Attribute.TypeId 以傳回屬性的對象識別。 如果只有某些屬性實例是唯一的,請從 Attribute.TypeId 傳回值,以在這些情況下傳回相等。 例如,某些屬性具有建構函式參數,做為唯一索引鍵。 針對這些屬性,從 Attribute.TypeId 屬性傳回建構函式參數的值。

注意

的預設實 Attribute.TypeId 作會傳回型別識別,而不論 屬性的值 AttributeUsageAttribute.AllowMultiple 為何。 若要從 AttributeCollection傳回屬性的AttributeUsageAttribute.AllowMultiple多個實例,您的屬性必須覆寫 Attribute.TypeId 屬性。

另請參閱

適用於