EditorBrowsableAttribute 類別

定義

指定在編輯器中可檢視的屬性或方法。Specifies that a property or method is viewable in an editor. 此類別無法獲得繼承。This class cannot be inherited.

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
type EditorBrowsableAttribute = class
    inherit Attribute
Public NotInheritable Class EditorBrowsableAttribute
Inherits Attribute
繼承
EditorBrowsableAttribute
屬性

範例

下列範例示範如何藉由設定 EditorBrowsableAttribute 屬性的適當值,從 IntelliSense 隱藏類別的屬性。The following sample demonstrates how to hide a property of a class from IntelliSense by setting the appropriate value for the EditorBrowsableAttribute attribute. 組建 Class1 在自己的元件中。Build Class1 in its own assembly.

在 Visual Studio 中,建立新的 Windows 應用程式方案,並加入包含 Class1之元件的參考。In Visual Studio, create a new Windows Application solution, and add a reference to the assembly which contains Class1. 在 Form1 函式中,宣告 Class1的實例,輸入實例的名稱,然後按下句點鍵,以啟動 Class1 成員的 IntelliSense 下拉式清單。In the Form1 constructor, declare an instance of Class1, type the name of the instance, and press the period key to activate the IntelliSense drop-down list of Class1 members. [Age] 屬性不會出現在下拉式清單中。The Age property does not appear in the drop-down list.

#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;
using System.ComponentModel;

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

        int ageval;

        [EditorBrowsable(EditorBrowsableState.Never)]
        public int Age
        {
            get { return ageval; }
            set
            {
                if (!ageval.Equals(value))
                {
                    ageval = value;
                }
            }
        }
    }
}
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 是設計工具的提示,指出是否要顯示內容或方法。EditorBrowsableAttribute is a hint to a designer indicating whether a property or method is to be displayed. 您可以在視覺化設計工具或文字編輯器中使用此類型,以判斷使用者可看見的內容。You can use this type in a visual designer or text editor to determine what is visible to the user. 例如,Visual Studio 中的 IntelliSense 引擎會使用這個屬性來判斷是否要顯示內容或方法。For example, the IntelliSense engine in Visual Studio uses this attribute to determine whether to show a property or method.

在 Visual C#中,您可以使用 工具 | |選項 文字編輯器| C# 底下的 隱藏高級成員 設定,來控制 IntelliSense 和 屬性 視窗中出現的In Visual C#, you can control when advanced properties appear in IntelliSense and the Properties Window with the Hide Advanced Members setting under Tools | Options | Text Editor | C#. 對應的 EditorBrowsableStateAdvancedThe corresponding EditorBrowsableState is Advanced.

注意

在 Visual C#中,EditorBrowsableAttribute 不會隱藏相同元件中類別的成員。In Visual C#, EditorBrowsableAttribute does not suppress members from a class in the same assembly.

建構函式

EditorBrowsableAttribute()

使用將 EditorBrowsableAttribute 設定為預設狀態,初始化 State 類別的新執行個體。Initializes a new instance of the EditorBrowsableAttribute class with State set to the default state.

EditorBrowsableAttribute(EditorBrowsableState)

使用 EditorBrowsableAttribute,初始化 EditorBrowsableState 類別的新執行個體。Initializes a new instance of the EditorBrowsableAttribute class with an EditorBrowsableState.

屬性

State

取得屬性或方法的可瀏覽狀態。Gets the browsable state of the property or method.

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,表示指定的物件值是否等於目前的 EditorBrowsableAttributeReturns whether the value of the given object is equal to the current EditorBrowsableAttribute.

GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

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

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

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

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

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

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 Attribute)

適用於

另請參閱