EditorBrowsableAttribute Kelas

Definisi

Menentukan bahwa kelas atau anggota dapat dilihat di editor. Kelas ini tidak dapat diwariskan.

public ref class EditorBrowsableAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct)]
public sealed class EditorBrowsableAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct)>]
type EditorBrowsableAttribute = class
    inherit Attribute
Public NotInheritable Class EditorBrowsableAttribute
Inherits Attribute
Warisan
EditorBrowsableAttribute
Atribut

Contoh

Contoh berikut menunjukkan cara menyembunyikan properti kelas dari IntelliSense dengan mengatur nilai yang sesuai untuk EditorBrowsableAttribute atribut .

Bangun Class1 di assembly-nya sendiri. Kemudian, di Visual Studio, buat proyek baru dan tambahkan referensi ke assembly yang berisi Class1. Nyatakan instans Class1, lalu masukkan nama instans dan tekan tombol . untuk mengaktifkan daftar Class1 anggota IntelliSense. Properti Age tidak muncul di daftar drop-down karena disembunyikan.

#using <system.dll>

using namespace System;
using namespace System::ComponentModel;

namespace EditorBrowsableDemo
{
   public ref class Class1
   {
   public:
      Class1()
      { 
         //
         // TODO: Add constructor logic here
         //
      }

   private:
      int ageval;

   public:
      [EditorBrowsable(EditorBrowsableState::Never)]
      property int Age 
      {
         int get()
         {
            return ageval;
         }

         void set( int value )
         {
            if ( ageval != value )
            {
               ageval = value;
            }
         }
      }
   };
}
using System.ComponentModel;

namespace EditorBrowsableDemo
{
    public class Class1
    {
        public Class1() { }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public int Age
        {
            get; set;
        }

        public int Height
        {
            get; set;
        }
    }
}
Imports System.ComponentModel

Public Class Class1

    Private ageval As Integer

    <EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
    Public Property Age() As Integer

        Get
            Return ageval
        End Get

        Set(ByVal Value As Integer)
            If Not ageval.Equals(Value) Then
                ageval = Value
            End If
        End Set

    End Property

End Class

Keterangan

EditorBrowsableAttribute adalah petunjuk untuk perancang yang menunjukkan apakah kelas atau anggota harus ditampilkan. Anda dapat menggunakan jenis ini di desainer visual atau editor teks untuk menentukan apa yang harus dilihat oleh pengguna. Misalnya, mesin IntelliSense di Visual Studio menggunakan atribut ini untuk menentukan apakah akan menampilkan kelas atau anggota.

Di Visual Studio, Anda dapat mengontrol kapan properti tingkat lanjut muncul di C# IntelliSense dan jendela Properti dengan pengaturan Sembunyikan Anggota Tingkat Lanjut di bawah Opsi > Alat > Teks Editor > C#. Yang sesuai EditorBrowsableState adalah Advanced.

Catatan

Di C#, EditorBrowsableAttribute tidak menekan anggota agar tidak dijelajahi oleh kelas dalam rakitan yang sama.

Konstruktor

EditorBrowsableAttribute()

Menginisialisasi instans EditorBrowsableAttribute baru kelas dengan State diatur ke status default.

EditorBrowsableAttribute(EditorBrowsableState)

Menginisialisasi instans EditorBrowsableAttribute baru kelas dengan EditorBrowsableState.

Properti

State

Mendapatkan status properti atau metode yang dapat dijelajahi.

TypeId

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

(Diperoleh dari Attribute)

Metode

Equals(Object)

Mengembalikan apakah nilai objek yang diberikan sama dengan saat ini EditorBrowsableAttribute.

GetHashCode()

Mengembalikan kode hash untuk instans ini.

GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
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 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