DescriptionAttribute Classe

Definição

Especifica uma descrição de uma propriedade ou evento.

public ref class DescriptionAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public class DescriptionAttribute : Attribute
public class DescriptionAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type DescriptionAttribute = class
    inherit Attribute
type DescriptionAttribute = class
    inherit Attribute
Public Class DescriptionAttribute
Inherits Attribute
Herança
DescriptionAttribute
Derivado
Atributos

Exemplos

O exemplo a seguir cria a MyImage propriedade. A propriedade tem dois atributos, a DescriptionAttribute e um CategoryAttribute.

public:
   property Image^ MyImage 
   {
      [Description("The image associated with the control"),Category("Appearance")]
      Image^ get()
      {
         // Insert code here.
         return image1;
      }

      void set( Image^ value )
      {
         // Insert code here.
      }
   }
[Description("The image associated with the control"),Category("Appearance")] 
 public Image MyImage {
    get {
       // Insert code here.
       return image1;
    }
    set {
       // Insert code here.
    }
 }
<Description("The image associated with the control"), _
    Category("Appearance")> _
Public Property MyImage() As Image
    Get
        ' Insert code here.
        Return image1
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

O próximo exemplo obtém a descrição de MyImage. Primeiro, o código obtém uma PropertyDescriptorCollection com todas as propriedades do objeto. Em seguida, ele indexa para obter PropertyDescriptorCollection MyImage. Em seguida, retorna os atributos dessa propriedade e os salva na variável de atributos.

Em seguida, o exemplo imprime a descrição recuperando-a AttributeCollectione gravando-a DescriptionAttribute na tela do console.

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyImage" ]->Attributes;

/* Prints the description by retrieving the DescriptionAttribute 
      * from the AttributeCollection. */
DescriptionAttribute^ myAttribute = dynamic_cast<DescriptionAttribute^>(attributes[ DescriptionAttribute::typeid ]);
Console::WriteLine( myAttribute->Description );
// Gets the attributes for the property.
 AttributeCollection attributes = 
    TypeDescriptor.GetProperties(this)["MyImage"].Attributes;
 
 /* Prints the description by retrieving the DescriptionAttribute 
  * from the AttributeCollection. */
 DescriptionAttribute myAttribute = 
    (DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
 Console.WriteLine(myAttribute.Description);
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("MyImage").Attributes

' Prints the description by retrieving the DescriptionAttribute
' from the AttributeCollection. 
Dim myAttribute As DescriptionAttribute = _
    CType(attributes(GetType(DescriptionAttribute)), DescriptionAttribute)
Console.WriteLine(myAttribute.Description)

Comentários

Um designer visual pode exibir a descrição especificada ao referenciar o membro do componente, como em um janela Propriedades. Chame Description para acessar o valor desse atributo.

Para obter mais informações, consulte Atributos.

Construtores

DescriptionAttribute()

Inicializa uma nova instância da classe DescriptionAttribute sem nenhum parâmetro.

DescriptionAttribute(String)

Inicializa uma nova instância da classe DescriptionAttribute com uma descrição.

Campos

Default

Especifica o valor padrão para o DescriptionAttribute, que é uma cadeia de caracteres vazia (""). Esse campo static é somente leitura.

Propriedades

Description

Obtém a descrição armazenada nesse atributo.

DescriptionValue

Obtém ou define a cadeia de caracteres armazenada como a descrição.

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.

(Herdado de Attribute)

Métodos

Equals(Object)

Retorna se o valor do objeto especificado é igual ao DescriptionAttribute atual.

GetHashCode()

Retorna o código hash para a instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Retorna um valor que indica se esta é a instância de DescriptionAttribute padrão.

IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a

Confira também