Condividi tramite


BrowsableAttribute Classe

Definizione

Specifica se una proprietà o un evento deve essere visualizzato in una finestra Proprietà.

public ref class BrowsableAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class BrowsableAttribute : Attribute
public sealed class BrowsableAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type BrowsableAttribute = class
    inherit Attribute
type BrowsableAttribute = class
    inherit Attribute
Public NotInheritable Class BrowsableAttribute
Inherits Attribute
Ereditarietà
BrowsableAttribute
Attributi

Esempio

Nell'esempio seguente viene contrassegnata una proprietà come esplorabile.

public:
   [Browsable(true)]
   property int MyProperty 
   {
      int get()
      {
         // Insert code here.
         return 0;
      }
      void set( int value )
      {
         // Insert code here.
      }
   }
[Browsable(true)]
public int MyProperty
{
    get =>
        // Insert code here.
        0;
    set
    {
        // Insert code here.
    }
}

<Browsable(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

Nell'esempio seguente viene illustrato come controllare il valore di BrowsableAttribute per MyProperty. Innanzitutto, il codice ottiene un PropertyDescriptorCollection oggetto con tutte le proprietà per l'oggetto . Successivamente, il codice indicizza in PropertyDescriptorCollection per ottenere MyProperty. Restituisce quindi gli attributi per questa proprietà e li salva nella variabile degli attributi.

L'esempio presenta due modi diversi per controllare il valore di BrowsableAttribute. Nel secondo frammento di codice l'esempio chiama il Equals metodo . Nell'ultimo frammento di codice, nell'esempio viene utilizzata la Browsable proprietà per controllare il valore.

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

// Checks to see if the value of the BrowsableAttribute is Yes.
if ( attributes[ BrowsableAttribute::typeid ]->Equals( BrowsableAttribute::Yes ) )
{
   
   // Insert code here.
}

// This is another way to see whether the property is browsable.
BrowsableAttribute^ myAttribute = dynamic_cast<BrowsableAttribute^>(attributes[ BrowsableAttribute::typeid ]);
if ( myAttribute->Browsable )
{
   // Insert code here.
}
// Gets the attributes for the property.
AttributeCollection attributes =
   TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

// Checks to see if the value of the BrowsableAttribute is Yes.
if (attributes[typeof(BrowsableAttribute)].Equals(BrowsableAttribute.Yes))
{
    // Insert code here.
}

// This is another way to see whether the property is browsable.
BrowsableAttribute myAttribute =
   (BrowsableAttribute)attributes[typeof(BrowsableAttribute)];
if (myAttribute.Browsable)
{
    // Insert code here.
}
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("MyProperty").Attributes

' Checks to see if the value of the BrowsableAttribute is Yes.
If attributes(GetType(BrowsableAttribute)).Equals(BrowsableAttribute.Yes) Then
    ' Insert code here.
End If 

' This is another way to see whether the property is browsable.
Dim myAttribute As BrowsableAttribute = _
    CType(attributes(GetType(BrowsableAttribute)), BrowsableAttribute)
If myAttribute.Browsable Then
    ' Insert code here.
End If

Se è stata contrassegnata una classe con , BrowsableAttributeusare il codice seguente per controllare il valore.

AttributeCollection^ attributes = TypeDescriptor::GetAttributes( MyProperty );
if ( attributes[ BrowsableAttribute::typeid ]->Equals( BrowsableAttribute::Yes ) )
{
   // Insert code here.
}
AttributeCollection attributes =
    TypeDescriptor.GetAttributes(MyProperty);
if (attributes[typeof(BrowsableAttribute)].Equals(BrowsableAttribute.Yes))
{
    // Insert code here.
}
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(BrowsableAttribute)).Equals(BrowsableAttribute.Yes) Then
    ' Insert code here.
End If

Commenti

Una finestra di progettazione visiva visualizza in genere nella finestra Proprietà i membri che non dispongono di un attributo esplorabile o sono contrassegnati con il BrowsableAttribute parametro del browsable costruttore impostato su true. Questi membri possono essere modificati in fase di progettazione. I membri contrassegnati con il BrowsableAttribute parametro del browsable costruttore impostato su false non sono appropriati per la modifica in fase di progettazione e pertanto non vengono visualizzati in una finestra di progettazione visiva. Il valore predefinito è true.

Annotazioni

Quando si contrassegna una proprietà con Browsable(true), il valore di questo attributo viene impostato sul membro Yescostante . Per una proprietà contrassegnata con Browsable(false), il valore è No. Pertanto, quando si controlla il valore di questo attributo nel codice, è necessario specificare l'attributo come BrowsableAttribute.Yes o BrowsableAttribute.No.

Per altre informazioni, vedere Attributi.

Costruttori

Nome Descrizione
BrowsableAttribute(Boolean)

Inizializza una nuova istanza della classe BrowsableAttribute.

Campi

Nome Descrizione
Default

Specifica il valore predefinito per , BrowsableAttributeovvero Yes. Questo static campo è di sola lettura.

No

Specifica che non è possibile modificare una proprietà o un evento in fase di progettazione. Questo static campo è di sola lettura.

Yes

Specifica che una proprietà o un evento può essere modificato in fase di progettazione. Questo static campo è di sola lettura.

Proprietà

Nome Descrizione
Browsable

Ottiene un valore che indica se un oggetto è esplorabile.

TypeId

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

(Ereditato da Attribute)

Metodi

Nome Descrizione
Equals(Object)

Indica se questa istanza e un oggetto specificato 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 ID 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 delle 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