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中,创建新的Windows应用程序解决方案,并添加对包含的程序集的Class1引用。 在 Form1 构造函数中,声明一个 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 C# 中,可以控制高级属性何时显示在 IntelliSense 和“属性”窗口中,其“ 隐藏高级成员 ”设置位于 “工具”|选项|文本编辑器| C# 下。 对应的 EditorBrowsableStateAdvanced

备注

在 Visual 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)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅