DescriptionAttribute Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Especifica uma descrição para 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
- Derivado
- Atributos
Exemplos
O exemplo seguinte cria a MyImage propriedade. A propriedade tem dois atributos, a DescriptionAttribute e a 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 seguinte recebe a descrição de MyImage. Primeiro, o código recebe uma PropertyDescriptorCollection com todas as propriedades do objeto. De seguida, indexa em para PropertyDescriptorCollection obter MyImage. Depois, devolve os atributos dessa propriedade e guarda-os na variável de atributos.
O exemplo imprime então a descrição recuperando-a DescriptionAttributeAttributeCollectiondo , e escrevendo-a no ecrã da consola.
// 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)
Observações
Um designer visual pode mostrar a descrição especificada ao referenciar o elemento componente, como numa janela Propriedades. Ligue Description para aceder ao valor deste atributo.
Para obter mais informações, consulte Atributos.
Construtores
| Name | 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
| Name | Description |
|---|---|
| Default |
Especifica o valor padrão para o DescriptionAttribute, que é uma cadeia vazia (""). Este |
Propriedades
| Name | Description |
|---|---|
| Description |
A descrição fica armazenada neste atributo. |
| DescriptionValue |
Obtém ou define a cadeia armazenada como a descrição. |
| TypeId |
Quando implementado numa classe derivada, obtém um identificador único para esta Attribute. (Herdado de Attribute) |
Métodos
| Name | Description |
|---|---|
| Equals(Object) |
Devolve se o valor do objeto dado é igual à corrente DescriptionAttribute. |
| GetHashCode() |
Devolve o código de hash para esta instância. |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| IsDefaultAttribute() |
Devolve um valor que indica se esta é a instância padrão DescriptionAttribute . |
| IsDefaultAttribute() |
Quando sobrescrito numa classe derivada, indica se o valor desta instância é o valor padrão para a classe derivada. (Herdado de Attribute) |
| Match(Object) |
Quando sobrescrito numa classe derivada, devolve um valor que indica se esta instância é igual a um objeto especificado. (Herdado de Attribute) |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |
Implementações de Interface Explícita
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de despacho. (Herdado de Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera a informação de tipo de um objeto, que pode ser usada para obter a informação de tipo para uma interface. (Herdado de Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Recupera o número de interfaces de informações de tipo que um objeto fornece (0 ou 1). (Herdado de Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Proporciona acesso a propriedades e métodos expostos por um objeto. (Herdado de Attribute) |