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 AttributePublic NotInheritable Class EditorBrowsableAttribute
Inherits Attribute- 继承
- 属性
示例
以下示例演示如何通过设置属性的相应值,对 IntelliSense 隐藏类的属性 EditorBrowsableAttribute 。
在其自己的程序集中生成 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 和属性窗口>中何时显示高级属性。 对应的 EditorBrowsableState 为 Advanced。
注意
在 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) |