EditorBrowsableAttribute 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定類別或成員可在編輯器中檢視。 此類別無法獲得繼承。
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 值來隱藏類別的屬性。
在自己的組裝中建構 Class1 。 接著在 Visual Studio 建立一個新專案,並新增包含 Class1 的組件參考。 宣告一個實例, Class1然後輸入實例名稱並按 . key 啟動 IntelliSense 成員清單 Class1 。 該 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 和 屬性視窗。 對應 EditorBrowsableState 的 為 Advanced。
Note
在 C# 中, EditorBrowsableAttribute 不會抑制成員被同一組合群中的類別瀏覽。
建構函式
| 名稱 | Description |
|---|---|
| EditorBrowsableAttribute() |
初始化一個新的類別實例 EditorBrowsableAttribute ,將 State 設定為預設狀態。 |
| EditorBrowsableAttribute(EditorBrowsableState) |
初始化一個新的類別實例 EditorBrowsableAttribute ,帶有 EditorBrowsableState。 |
屬性
| 名稱 | Description |
|---|---|
| State |
取得該屬性或方法的可瀏覽狀態。 |
| TypeId |
在衍生類別中實作時,取得這個 Attribute的唯一標識碼。 (繼承來源 Attribute) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
回傳給定物件的值是否等於當前 EditorBrowsableAttribute值。 |
| GetHashCode() |
傳回這個實例的哈希碼。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsDefaultAttribute() |
在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。 (繼承來源 Attribute) |
| Match(Object) |
在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| _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) |