Upraviť

Zdieľať cez


TypeDescriptor.GetAttributes Method

Definition

Returns the collection of attributes for a component or a type.

Overloads

GetAttributes(Object, Boolean)

Returns a collection of attributes for the specified component and a Boolean indicating that a custom type descriptor has been created.

GetAttributes(Type)

Returns a collection of attributes for the specified type of component.

GetAttributes(Object)

Returns the collection of attributes for the specified component.

GetAttributes(Object, Boolean)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

Returns a collection of attributes for the specified component and a Boolean indicating that a custom type descriptor has been created.

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

Parameters

component
Object

The component for which you want to get attributes.

noCustomTypeDesc
Boolean

true to use a baseline set of attributes from the custom type descriptor if component is of type ICustomTypeDescriptor; otherwise, false.

Returns

An AttributeCollection with the attributes for the component. If the component is null, this method returns an empty collection.

Remarks

The attributes returned by the GetAttributes method may be dynamically modified from the original components source listing by extender providers (IExtenderProvider), filter services (ITypeDescriptorFilterService), and attribute filters.

When you define a custom attribute with AttributeUsageAttribute.AllowMultiple set to true, you must override the Attribute.TypeId property to make it unique. If all instances of your attribute are unique, override Attribute.TypeId to return the object identity of your attribute. If only some instances of your attribute are unique, return a value from Attribute.TypeId that would return equality in those cases. For example, some attributes have a constructor parameter that acts as a unique key. For these attributes, return the value of the constructor parameter from the Attribute.TypeId property.

Note

The default implementation of Attribute.TypeId returns the type identity regardless of the value of the AttributeUsageAttribute.AllowMultiple property. In order to return multiple instances of an AttributeUsageAttribute.AllowMultiple attribute from the AttributeCollection, your attribute must override the Attribute.TypeId property.

See also

Applies to

GetAttributes(Type)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

Returns a collection of attributes for the specified type of component.

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

Parameters

componentType
Type

The Type of the target component.

Returns

An AttributeCollection with the attributes for the type of the component. If the component is null, this method returns an empty collection.

Remarks

Call this version of this method only when you do not have an instance of the object.

For attributes with AttributeUsageAttribute.AllowMultiple set to true, the attribute collection removes duplicate instances. These are instances in which the Attribute.TypeId property returns equal values.

When you define a custom attribute with AttributeUsageAttribute.AllowMultiple set to true, you must override the Attribute.TypeId property to make it unique. If all instances of your attribute are unique, override Attribute.TypeId to return the object identity of your attribute. If only some instances of your attribute are unique, return a value from Attribute.TypeId that would return equality in those cases. For example, some attributes have a constructor parameter that acts as a unique key. For these attributes, return the value of the constructor parameter from the Attribute.TypeId property.

Note

The default implementation of Attribute.TypeId returns the type identity regardless of the value of the AttributeUsageAttribute.AllowMultiple property. In order to return multiple instances of an AttributeUsageAttribute.AllowMultiple attribute from the AttributeCollection, your attribute must override the Attribute.TypeId property.

See also

Applies to

GetAttributes(Object)

Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs
Source:
TypeDescriptor.cs

Returns the collection of attributes for the specified component.

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

Parameters

component
Object

The component for which you want to get attributes.

Returns

An AttributeCollection containing the attributes for the component. If component is null, this method returns an empty collection.

Examples

For an example of this method, see the Matches method.

Remarks

The attributes returned by the GetAttributes method may be dynamically modified from the original component's source listing by extender providers (IExtenderProvider), filter services (ITypeDescriptorFilterService), and attribute filters.

When you define a custom attribute with AttributeUsageAttribute.AllowMultiple set to true, you must override the Attribute.TypeId property to make it unique. If all instances of your attribute are unique, override Attribute.TypeId to return the object identity of your attribute. If only some instances of your attribute are unique, return a value from Attribute.TypeId that would return equality in those cases. For example, some attributes have a constructor parameter that acts as a unique key. For these attributes, return the value of the constructor parameter from the Attribute.TypeId property.

Note

The default implementation of Attribute.TypeId returns the type identity regardless of the value of the AttributeUsageAttribute.AllowMultiple property. In order to return multiple instances of an AttributeUsageAttribute.AllowMultiple attribute from the AttributeCollection, your attribute must override the Attribute.TypeId property.

See also

Applies to