DescriptionAttribute Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Specifica una descrizione per una proprietà o un 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
- Ereditarietà
- Derivato
- Attributi
Esempio
Nell'esempio seguente viene creata la MyImage proprietà . La proprietà ha due attributi, un DescriptionAttribute e un .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
Nell'esempio seguente viene recuperata la descrizione di MyImage. Prima di tutto, il codice ottiene un PropertyDescriptorCollection oggetto con tutte le proprietà per l'oggetto . Successivamente, indicizza nell'oggetto PropertyDescriptorCollection per ottenere MyImage. Restituisce quindi gli attributi per questa proprietà e li salva nella variabile degli attributi.
Nell'esempio viene quindi stampata la descrizione recuperando DescriptionAttribute da AttributeCollectione scrivendola nella schermata della 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)
Commenti
Una finestra di progettazione visiva può visualizzare la descrizione specificata quando si fa riferimento al membro del componente, ad esempio in un Finestra Proprietà. Chiamare Description per accedere al valore di questo attributo.
Per altre informazioni, vedere Attributi.
Costruttori
| Nome | Descrizione |
|---|---|
| DescriptionAttribute() |
Inizializza una nuova istanza della DescriptionAttribute classe senza parametri. |
| DescriptionAttribute(String) |
Inizializza una nuova istanza della DescriptionAttribute classe con una descrizione. |
Campi
| Nome | Descrizione |
|---|---|
| Default |
Specifica il valore predefinito per , DescriptionAttributeovvero una stringa vuota (""). Questo |
Proprietà
| Nome | Descrizione |
|---|---|
| Description |
Ottiene la descrizione archiviata in questo attributo. |
| DescriptionValue |
Ottiene o imposta la stringa archiviata come descrizione. |
| TypeId |
Se implementato in una classe derivata, ottiene un identificatore univoco per questo Attribute. (Ereditato da Attribute) |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Restituisce un valore che indica se il valore dell'oggetto specificato è uguale all'oggetto corrente DescriptionAttribute. |
| GetHashCode() |
Restituisce il codice hash per questa istanza. |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| IsDefaultAttribute() |
Restituisce un valore che indica se si tratta dell'istanza predefinita DescriptionAttribute . |
| IsDefaultAttribute() |
Quando sottoposto a override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata. (Ereditato da Attribute) |
| Match(Object) |
Quando sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza è uguale a un oggetto specificato. (Ereditato da Attribute) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Implementazioni dell'interfaccia esplicita
| Nome | Descrizione |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Esegue il mapping di un set di nomi a un set corrispondente di identificatori dispatch. (Ereditato da Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera le informazioni sul tipo per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per un'interfaccia. (Ereditato da Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Recupera il numero di interfacce di informazioni sul tipo fornite da un oggetto (0 o 1). (Ereditato da Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto . (Ereditato da Attribute) |