TypeDescriptor.GetAttributes Método
Definição
Retorna a coleção de atributos de um componente ou um tipo.Returns the collection of attributes for a component or a type.
Sobrecargas
| GetAttributes(Object) |
Retorna a coleção de atributos para o componente especificado.Returns the collection of attributes for the specified component. |
| GetAttributes(Type) |
Retorna uma coleção de atributos para o tipo de componente especificado.Returns a collection of attributes for the specified type of component. |
| GetAttributes(Object, Boolean) |
Retorna uma coleção de atributos para o componente especificado e um valor booliano que indica que um descritor de tipo personalizado foi criado.Returns a collection of attributes for the specified component and a Boolean indicating that a custom type descriptor has been created. |
GetAttributes(Object)
Retorna a coleção de atributos para o componente especificado.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
Parâmetros
- component
- Object
O componente para o qual você deseja obter atributos.The component for which you want to get attributes.
Retornos
Um AttributeCollection que contém os atributos do componente.An AttributeCollection containing the attributes for the component. Se component for null, esse método retornará uma coleção vazia.If component is null, this method returns an empty collection.
Exemplos
Para obter um exemplo desse método, consulte o Matches método.For an example of this method, see the Matches method.
Comentários
Os atributos retornados pelo GetAttributes método podem ser modificados dinamicamente da listagem de origem do componente original por provedores de extensor ( IExtenderProvider ), serviços de filtro ( ITypeDescriptorFilterService ) e filtros de atributo.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.
Quando você define um atributo personalizado com AttributeUsageAttribute.AllowMultiple definido como true , você deve substituir a Attribute.TypeId propriedade para torná-la exclusiva.When you define a custom attribute with AttributeUsageAttribute.AllowMultiple set to true, you must override the Attribute.TypeId property to make it unique. Se todas as instâncias do atributo forem exclusivas, substitua Attribute.TypeId para retornar a identidade do objeto do seu atributo.If all instances of your attribute are unique, override Attribute.TypeId to return the object identity of your attribute. Se apenas algumas instâncias do seu atributo forem exclusivas, retornar um valor Attribute.TypeId que retornaria igualdade nesses casos.If only some instances of your attribute are unique, return a value from Attribute.TypeId that would return equality in those cases. Por exemplo, alguns atributos têm um parâmetro de construtor que atua como uma chave exclusiva.For example, some attributes have a constructor parameter that acts as a unique key. Para esses atributos, retorne o valor do parâmetro de construtor da Attribute.TypeId propriedade.For these attributes, return the value of the constructor parameter from the Attribute.TypeId property.
Observação
A implementação padrão de Attribute.TypeId retorna a identidade do tipo, independentemente do valor da AttributeUsageAttribute.AllowMultiple propriedade.The default implementation of Attribute.TypeId returns the type identity regardless of the value of the AttributeUsageAttribute.AllowMultiple property. Para retornar várias instâncias de um AttributeUsageAttribute.AllowMultiple atributo do AttributeCollection , o atributo deve substituir a Attribute.TypeId propriedade.In order to return multiple instances of an AttributeUsageAttribute.AllowMultiple attribute from the AttributeCollection, your attribute must override the Attribute.TypeId property.
Confira também
Aplica-se a
GetAttributes(Type)
Retorna uma coleção de atributos para o tipo de componente especificado.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
Parâmetros
Retornos
Um AttributeCollection com os atributos do tipo de componente.An AttributeCollection with the attributes for the type of the component. Se o componente for null, esse método retornará uma coleção vazia.If the component is null, this method returns an empty collection.
Comentários
Chame esta versão deste método somente quando você não tiver uma instância do objeto.Call this version of this method only when you do not have an instance of the object.
Para atributos com AttributeUsageAttribute.AllowMultiple definido como true , a coleção de atributos remove instâncias duplicadas.For attributes with AttributeUsageAttribute.AllowMultiple set to true, the attribute collection removes duplicate instances. Essas são instâncias nas quais a Attribute.TypeId propriedade retorna valores iguais.These are instances in which the Attribute.TypeId property returns equal values.
Quando você define um atributo personalizado com AttributeUsageAttribute.AllowMultiple definido como true , você deve substituir a Attribute.TypeId propriedade para torná-la exclusiva.When you define a custom attribute with AttributeUsageAttribute.AllowMultiple set to true, you must override the Attribute.TypeId property to make it unique. Se todas as instâncias do atributo forem exclusivas, substitua Attribute.TypeId para retornar a identidade do objeto do seu atributo.If all instances of your attribute are unique, override Attribute.TypeId to return the object identity of your attribute. Se apenas algumas instâncias do seu atributo forem exclusivas, retornar um valor Attribute.TypeId que retornaria igualdade nesses casos.If only some instances of your attribute are unique, return a value from Attribute.TypeId that would return equality in those cases. Por exemplo, alguns atributos têm um parâmetro de construtor que atua como uma chave exclusiva.For example, some attributes have a constructor parameter that acts as a unique key. Para esses atributos, retorne o valor do parâmetro de construtor da Attribute.TypeId propriedade.For these attributes, return the value of the constructor parameter from the Attribute.TypeId property.
Observação
A implementação padrão de Attribute.TypeId retorna a identidade do tipo, independentemente do valor da AttributeUsageAttribute.AllowMultiple propriedade.The default implementation of Attribute.TypeId returns the type identity regardless of the value of the AttributeUsageAttribute.AllowMultiple property. Para retornar várias instâncias de um AttributeUsageAttribute.AllowMultiple atributo do AttributeCollection , o atributo deve substituir a Attribute.TypeId propriedade.In order to return multiple instances of an AttributeUsageAttribute.AllowMultiple attribute from the AttributeCollection, your attribute must override the Attribute.TypeId property.
Confira também
Aplica-se a
GetAttributes(Object, Boolean)
Retorna uma coleção de atributos para o componente especificado e um valor booliano que indica que um descritor de tipo personalizado foi criado.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
Parâmetros
- component
- Object
O componente para o qual você deseja obter atributos.The component for which you want to get attributes.
- noCustomTypeDesc
- Boolean
true para usar um conjunto de linha de base de atributos do descritor de tipo personalizado se o component for do tipo ICustomTypeDescriptor; caso contrário, false.true to use a baseline set of attributes from the custom type descriptor if component is of type ICustomTypeDescriptor; otherwise, false.
Retornos
Um AttributeCollection com os atributos para o componente.An AttributeCollection with the attributes for the component. Se o componente for null, esse método retornará uma coleção vazia.If the component is null, this method returns an empty collection.
Comentários
Os atributos retornados pelo GetAttributes método podem ser modificados dinamicamente da lista de origem dos componentes originais por provedores de extensor ( IExtenderProvider ), serviços de filtro ( ITypeDescriptorFilterService ) e filtros de atributo.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.
Quando você define um atributo personalizado com AttributeUsageAttribute.AllowMultiple definido como true , você deve substituir a Attribute.TypeId propriedade para torná-la exclusiva.When you define a custom attribute with AttributeUsageAttribute.AllowMultiple set to true, you must override the Attribute.TypeId property to make it unique. Se todas as instâncias do atributo forem exclusivas, substitua Attribute.TypeId para retornar a identidade do objeto do seu atributo.If all instances of your attribute are unique, override Attribute.TypeId to return the object identity of your attribute. Se apenas algumas instâncias do seu atributo forem exclusivas, retornar um valor Attribute.TypeId que retornaria igualdade nesses casos.If only some instances of your attribute are unique, return a value from Attribute.TypeId that would return equality in those cases. Por exemplo, alguns atributos têm um parâmetro de construtor que atua como uma chave exclusiva.For example, some attributes have a constructor parameter that acts as a unique key. Para esses atributos, retorne o valor do parâmetro de construtor da Attribute.TypeId propriedade.For these attributes, return the value of the constructor parameter from the Attribute.TypeId property.
Observação
A implementação padrão de Attribute.TypeId retorna a identidade do tipo, independentemente do valor da AttributeUsageAttribute.AllowMultiple propriedade.The default implementation of Attribute.TypeId returns the type identity regardless of the value of the AttributeUsageAttribute.AllowMultiple property. Para retornar várias instâncias de um AttributeUsageAttribute.AllowMultiple atributo do AttributeCollection , o atributo deve substituir a Attribute.TypeId propriedade.In order to return multiple instances of an AttributeUsageAttribute.AllowMultiple attribute from the AttributeCollection, your attribute must override the Attribute.TypeId property.
Confira também
- Attribute
- AttributeCollection
- ICustomTypeDescriptor
- GetAttributes()
- AddAttributes
- GetEvents
- GetProperties