BrowsableAttribute Classe

Definição

Especifica se uma propriedade ou evento deve ser exibido numa janela Propriedades.

public ref class BrowsableAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class BrowsableAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type BrowsableAttribute = class
    inherit Attribute
Public NotInheritable Class BrowsableAttribute
Inherits Attribute
Herança
BrowsableAttribute
Atributos

Exemplos

O exemplo seguinte marca uma propriedade como navegável.

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

O exemplo seguinte mostra como verificar o valor do BrowsableAttribute para MyProperty. Primeiro, o código recebe a PropertyDescriptorCollection com todas as propriedades do objeto. De seguida, o código indexa-se para obter PropertyDescriptorCollectionMyProperty. Depois, devolve os atributos dessa propriedade e guarda-os na variável de atributos.

O exemplo apresenta duas formas diferentes de verificar o valor do BrowsableAttribute. No segundo fragmento de código, o exemplo chama o Equals método. No último fragmento de código, o exemplo usa a Browsable propriedade para verificar o valor.

// 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 marcou uma classe com o BrowsableAttribute, use o seguinte código para verificar o valor.

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

Observações

Um designer visual normalmente exibe no janela Propriedades aqueles membros que não têm atributo navegável ou que estão marcados com o parâmetro do construtor >. Estes elementos podem ser modificados no momento do projeto. Os membros marcados com o BrowsableAttribute parâmetro do browsable construtor definido para false não são apropriados para edição em tempo de design e, por isso, não são apresentados num designer visual. A predefinição é true.

Observação

Quando se marca uma propriedade com Browsable(true), o valor deste atributo é definido como o elemento Yesconstante . Para uma propriedade marcada com Browsable(false), o valor é No. Portanto, ao verificar o valor deste atributo no seu código, deve especificar o atributo como BrowsableAttribute.Yes ou BrowsableAttribute.No.

Para obter mais informações, consulte Atributos.

Construtores

Name Description
BrowsableAttribute(Boolean)

Inicializa uma nova instância da BrowsableAttribute classe.

Campos

Name Description
Default

Especifica o valor padrão para o BrowsableAttribute, que é Yes. Este static campo é só de leitura.

No

Especifica que uma propriedade ou evento não pode ser modificado no momento do projeto. Este static campo é só de leitura.

Yes

Especifica que uma propriedade ou evento pode ser modificado no momento do projeto. Este static campo é só de leitura.

Propriedades

Name Description
Browsable

Recebe um valor que indica se um objeto é navegável.

TypeId

Quando implementado numa classe derivada, obtém um identificador único para esta Attribute.

(Herdado de Attribute)

Métodos

Name Description
Equals(Object)

Indica se esta instância e um objeto especificado são iguais.

GetHashCode()

Devolve o código de hash para esta instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Determina se este atributo é o padrão.

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)

Aplica-se a

Ver também