BrowsableAttribute Classe
In questo articolo
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.
Indica se visualizzare una proprietà o un evento 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à
- Attributi
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.
return 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 successivo viene illustrato come controllare il valore dell'oggetto BrowsableAttribute per MyProperty
. Prima di tutto, il codice ottiene un PropertyDescriptorCollection con tutte le proprietà per l'oggetto. Successivamente, gli indici di codice nell'oggetto PropertyDescriptorCollection per ottenere MyProperty
. Restituisce quindi gli attributi per questa proprietà e li salva nella variabile attributi.
L'esempio presenta due modi diversi per controllare il valore di BrowsableAttribute. Nel secondo frammento di codice, nell'esempio viene chiamato il Equals metodo . Nell'ultimo frammento di codice, nell'esempio viene usata 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 BrowsableAttribute, usare 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
Una finestra di progettazione visiva visualizza in genere nella Finestra Proprietà i membri che non hanno alcun 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 parametro del browsable
costruttore impostato su false
non sono appropriati per la BrowsableAttribute modifica in fase di progettazione e pertanto non vengono visualizzati in una finestra di progettazione visiva. Il valore predefinito è true
.
Nota
Quando si contrassegna una proprietà con Browsable(true)
, il valore di questo attributo è 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.
Browsable |
Inizializza una nuova istanza della classe BrowsableAttribute. |
Default |
Consente di specificare il valore predefinito per l'attributo BrowsableAttribute, che è Yes. Questo campo |
No |
Specifica che una proprietà o un evento non può essere modificato in fase di progettazione. Questo campo |
Yes |
Specifica che una proprietà o un evento può essere modificato in fase di progettazione. Questo campo |
Browsable |
Ottiene un valore che indica se un oggetto è esplorabile. |
Type |
Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute. (Ereditato da Attribute) |
Equals(Object) |
Indica se questa istanza e un oggetto specificato sono uguali. |
Get |
Restituisce il codice hash per l'istanza. |
Get |
Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object) |
Is |
Determina se questo attributo è predefinito. |
Is |
In caso di 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 equivale a un oggetto specificato. (Ereditato da Attribute) |
Memberwise |
Crea una copia superficiale dell'oggetto Object corrente. (Ereditato da Object) |
To |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
_Attribute. |
Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch. (Ereditato da Attribute) |
_Attribute. |
Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia. (Ereditato da Attribute) |
_Attribute. |
Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1). (Ereditato da Attribute) |
_Attribute. |
Fornisce l'accesso a proprietà e metodi esposti da un oggetto. (Ereditato da Attribute) |
Prodotto | Versioni |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Feedback su .NET
.NET è un progetto di open source. Selezionare un collegamento per fornire feedback: