EditorBrowsableAttribute 類別

定義

指定類別或成員可在編輯器中檢視。 此類別無法獲得繼承。

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
繼承
EditorBrowsableAttribute
屬性

範例

下列範例示範如何藉由設定 EditorBrowsableAttribute 屬性的適當值,從 IntelliSense 隱藏類別的屬性。

在自己的元件中建置 Class1 。 然後,在 Visual Studio 中,建立新的專案,並加入包含 Class1 之元件的參考。 宣告 的 Class1 實例,然後輸入 實例的名稱,然後按 鍵以啟動成員的 Class1 IntelliSense 清單。 屬性 Age 不會出現在下拉式清單中,因為它已隱藏。

#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

備註

EditorBrowsableAttribute 是設計工具的提示,指出是否應該顯示類別或成員。 您可以在視覺化設計工具或文字編輯器中使用此類型來判斷要讓使用者看見的內容。 例如,Visual Studio 中的 IntelliSense 引擎會使用這個屬性來判斷是否要顯示類別或成員。

在 Visual Studio 中,您可以使用 [工具 > 選項 > 文字編輯器 C#] >下的 [隱藏進階成員] 設定,控制進階屬性出現在 C# IntelliSense 和 屬性視窗。 對應的 EditorBrowsableStateAdvanced

注意

在 C# 中, EditorBrowsableAttribute 不會隱藏同一個元件中的類別流覽成員。

建構函式

EditorBrowsableAttribute()

使用將 EditorBrowsableAttribute 設定為預設狀態,初始化 State 類別的新執行個體。

EditorBrowsableAttribute(EditorBrowsableState)

使用 EditorBrowsableAttribute,初始化 EditorBrowsableState 類別的新執行個體。

屬性

State

取得屬性或方法的可瀏覽狀態。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,表示指定的物件值是否等於目前的 EditorBrowsableAttribute

GetHashCode()

傳回這個執行個體的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱