你们用过 EditorBrowsableAttribute 没有?

RexZheng 2007-12-12 11:48:48
引用MSDN:

EditorBrowsableAttribute 类
指定某个属性或方法在编辑器中可以查看。不能继承此类。

备注
您可以在可视化设计器或文本编辑器中使用该类来确定用户可见的内容。例如,Visual Studio .NET 中的智能感知引擎使用此特性来确定是否显示方法或属性。

示例
下面的示例说明如何通过为 EditorBrowsableAttribute 特性设置适当的值来向智能感知隐藏控件的属性。在打开新应用程序,添加对控件的引用,并且声明该控件的实例之后,IntelliSense 不在下拉列表框中显示 Age 属性。
int ageval;
[EditorBrowsable(EditorBrowsableState.Never)]
public int Age
{
get { return ageval; }
set
{
if (!ageval.Equals(value))
{
ageval = value;
}
}
}


我怎么测试都没有效果?
快晕了~~

用Reflector查看一些框架代码,确实也是用这个方法来屏蔽成员的,如TextBoxBase的AutoSize。可是我怎么测试都出不来效果。。。。。
有用过这个Attribute的兄弟过来帮帮忙。谢了!
...全文
225 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
RexZheng 2007-12-12
  • 打赏
  • 举报
回复
Google到答案了。

http://groups.google.com/group/microsoft.public.dotnet.framework.windowsforms.controls/browse_thread/thread/2f88b987be3948d0?fwc=1

Speaking for C#, the EditorBrowsableAttribute attribute only influences C#
IntelliSense filtering behavior if the decorated item is imported from
metadata.

That's to say, you should compile the EditorBrowsableAttribute-decorated
project(e.g project 1) into an assembly(.dll or .exe) and then in another
project(e.g project 2) add a reference to that assembly. In project 2, you
should see the attribute at work.

C# IntelliSense filtering behavior is not influenced if you are coding in
project 1. What's more, if you add a project-to-project reference to
project 1 in project 2, C# IntelliSense filtering behavior is not
influenced when you are coding in project 2 either.

The IDE is intended to filter items from consumers of your assembly and not
to filter items from yourself as you code the assembly.

Hope this helps.
If you have anything unclear, please don't hesitate to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support


大意是说 EditorBrowsableAttribute 属性只对编译后的程序集生效,对工程内,或者工程对工程引用无效,具体参见这个帖子中MS工作人员的解释。


好久没上CSDN,这帖子当是散分了 ^_^

对以后有遇到这问题的人也是一个参考,下午下班前结贴。
wuhq030710914 2007-12-12
  • 打赏
  • 举报
回复
没有
shinaterry 2007-12-12
  • 打赏
  • 举报
回复
既然解决了...

就接分吧...

^o^
shinaterry 2007-12-12
  • 打赏
  • 举报
回复
用过, Visual Studio .NET 控制智能感知引擎是否显示类型以及类成员...

必须把使用EditorBrowsableAttribute属性的*.cs文件编译成dll类库...

在其他工程中引用该dll才会有效果的...

多测试一下吧...

^o^
danjiewu 2007-12-12
  • 打赏
  • 举报
回复
以前有人问过同样的问题。
想想智能提示的原理不难猜到的。
北京的雾霾天 2007-12-12
  • 打赏
  • 举报
回复
原来如此。
3000sunqin 2007-12-12
  • 打赏
  • 举报
回复
jf
vwxyzh 2007-12-12
  • 打赏
  • 举报
回复
学习,用过EditorBrowsableAttribute,不过没注意这个细节。。。
csharp_start 2007-12-12
  • 打赏
  • 举报
回复
mark!
/// /// 一个强类型的资源类,用于查找本地化的字符串等。 /// // 此类是由 StronglyTypedResourceBuilder // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // (以 /str 作为命令选项),或重新生成 VS 项目。 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } /// /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("让屏幕开满玫瑰把妹必备.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } /// /// 使用此强类型资源类,为所有资源查找 /// 重写当前线程的 CurrentUICulture 属性。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } internal static System.Drawing.Bitmap 稀饭你 { get { object obj = ResourceManager.GetObject("稀饭你", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } }
用C#开发的中介管理系统! namespace MeiPing.Properties { /// /// 一个强类型的资源类,用于查找本地化的字符串等。 /// // 此类是由 StronglyTypedResourceBuilder // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // (以 /str 作为命令选项),或重新生成 VS 项目。 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } /// /// 返回此类使用的、缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if ((resourceMan == null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MeiPing.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } }

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧