DisplayNameAttribute Classe

Definizione

Specifica il nome visualizzato per una proprietà, un evento o un metodo void pubblico che non accetta argomenti.

public ref class DisplayNameAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Property)]
public class DisplayNameAttribute : Attribute
public class DisplayNameAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Property)>]
type DisplayNameAttribute = class
    inherit Attribute
type DisplayNameAttribute = class
    inherit Attribute
Public Class DisplayNameAttribute
Inherits Attribute
Ereditarietà
DisplayNameAttribute
Attributi

Esempio

Nell'esempio di codice seguente viene illustrato l'uso della DisplayNameAttribute classe per modificare il nome di una proprietà chiamata MisnamedProperty a RenamedProperty in un PropertyGrid controllo . Per un elenco di codice completo, vedere Come: Applicare attributi nei controlli Windows Forms.

// This property exists only to demonstrate the
// DisplayName attribute. When this control
// is attached to a PropertyGrid control, the
// property will appear as "RenamedProperty"
// instead of "MisnamedProperty".
[Description("Demonstrates DisplayNameAttribute.")]
[DisplayName("RenamedProperty")]
public bool MisnamedProperty => true;
' This property exists only to demonstrate the 
' DisplayName attribute. When this control 
' is attached to a PropertyGrid control, the
' property will be appear as "RenamedProperty"
' instead of "MisnamedProperty".
<Description("Demonstrates DisplayNameAttribute."), _
DisplayName("RenamedProperty")> _
Public ReadOnly Property MisnamedProperty() As Boolean
    Get
        Return True
    End Get
End Property

Commenti

Il valore predefinito è il nome della proprietà o dell'evento. L'implementazione predefinita di GetSortedActionItems usa reflection per eseguire ricerche nelle proprietà pubbliche e nei metodi public void che non accettano argomenti. GetSortedActionItems cerca in DisplayNameAttribute ogni proprietà e metodo e, se trovato, usa tale stringa anziché il nome della proprietà o del metodo.

Costruttori

Nome Descrizione
DisplayNameAttribute()

Inizializza una nuova istanza della classe DisplayNameAttribute.

DisplayNameAttribute(String)

Inizializza una nuova istanza della DisplayNameAttribute classe utilizzando il nome visualizzato.

Campi

Nome Descrizione
Default

Specifica il valore predefinito per .DisplayNameAttribute Questo campo è di sola lettura.

Proprietà

Nome Descrizione
DisplayName

Ottiene il nome visualizzato per un metodo property, event o public void che non accetta argomenti archiviati in questo attributo.

DisplayNameValue

Ottiene o imposta il nome visualizzato.

TypeId

Se implementato in una classe derivata, ottiene un identificatore univoco per questo Attribute.

(Ereditato da Attribute)

Metodi

Nome Descrizione
Equals(Object)

Determina se due DisplayNameAttribute istanze sono uguali.

GetHashCode()

Restituisce il codice hash per questa istanza.

GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

Determina se questo attributo è l'impostazione predefinita.

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)

Si applica a

Vedi anche