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
[<System.AttributeUsage(System.AttributeTargets.All)>]
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, um 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.
        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 exemplo a seguir 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 PropertyDescriptorCollectionMyImage. 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

Nome Description
DescriptionAttribute()

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

DescriptionAttribute(String)

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

Campos

Nome Description
Default

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

Propriedades

Nome Description
Description

Obtém a descrição armazenada neste 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 esse Attribute.

(Herdado de Attribute)

Métodos

Nome Description
Equals(Object)

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

GetHashCode()

Retorna o código hash dessa instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

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

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 Objectatual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

Nome Description
_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 de um objeto, que podem ser usadas para obter as informações de tipo de 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