BrowsableAttribute Kelas

Definisi

Menentukan apakah properti atau peristiwa harus ditampilkan di jendela Properti.

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
Warisan
BrowsableAttribute
Atribut

Contoh

Contoh berikut menandai properti sebagai dapat ditelusuri.

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

Contoh berikutnya menunjukkan cara memeriksa nilai BrowsableAttribute untuk MyProperty. Pertama, kode mendapatkan PropertyDescriptorCollection dengan semua properti untuk objek . Selanjutnya, kode mengindeks ke PropertyDescriptorCollection dalam untuk mendapatkan MyProperty. Kemudian mengembalikan atribut untuk properti ini dan menyimpannya dalam variabel atribut.

Contohnya menyajikan dua cara berbeda untuk memeriksa nilai BrowsableAttribute. Dalam fragmen kode kedua, contoh memanggil Equals metode . Dalam fragmen kode terakhir, contoh menggunakan Browsable properti untuk memeriksa nilai.

// 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

Jika Anda menandai kelas dengan BrowsableAttribute, gunakan kode berikut untuk memeriksa nilainya.

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

Keterangan

Perancang visual biasanya ditampilkan di jendela Properti anggota yang tidak memiliki atribut yang dapat dijelajahi atau ditandai dengan BrowsableAttribute parameter konstruktor browsable yang diatur ke true. Anggota ini dapat dimodifikasi pada waktu desain. Anggota yang ditandai dengan BrowsableAttribute parameter konstruktor browsable diatur ke false tidak sesuai untuk pengeditan waktu desain dan oleh karena itu tidak ditampilkan dalam desainer visual. Default adalah true.

Catatan

Saat Anda menandai properti dengan Browsable(true), nilai atribut ini diatur ke anggota Yeskonstanta . Untuk properti yang ditandai dengan Browsable(false), nilainya adalah No. Oleh karena itu, ketika Anda memeriksa nilai atribut ini dalam kode Anda, Anda harus menentukan atribut sebagai BrowsableAttribute.Yes atau BrowsableAttribute.No.

Untuk informasi selengkapnya, lihat Atribut.

Konstruktor

BrowsableAttribute(Boolean)

Menginisialisasi instans baru kelas BrowsableAttribute.

Bidang

Default

Menentukan nilai default untuk BrowsableAttribute, yaitu Yes. Bidang ini static bersifat baca-saja.

No

Menentukan bahwa properti atau peristiwa tidak dapat dimodifikasi pada waktu desain. Bidang ini static bersifat baca-saja.

Yes

Menentukan bahwa properti atau peristiwa dapat dimodifikasi pada waktu desain. Bidang ini static bersifat baca-saja.

Properti

Browsable

Mendapatkan nilai yang menunjukkan apakah objek dapat dijelajahi.

TypeId

Ketika diimplementasikan di kelas turunan, mendapatkan pengidentifikasi unik untuk ini Attribute.

(Diperoleh dari Attribute)

Metode

Equals(Object)

Menunjukkan apakah instans ini dan objek tertentu sama.

GetHashCode()

Mengembalikan kode hash untuk instans ini.

GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Menentukan apakah atribut ini adalah default.

IsDefaultAttribute()

Ketika ditimpa di kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk

Lihat juga