为什么EditorBrowsableState.Never不存在? [英] Why EditorBrowsableState.Never exists?

查看:187
本文介绍了为什么EditorBrowsableState.Never不存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存在一个 EditorBrowsableAttribute 在System.ComponentModel命名空间中.类型 EditorBrowsableState 有以下成员:

There exists an EditorBrowsableAttribute in the System.ComponentModel namespace. The type EditorBrowsableState has following members:

  • 高级
  • 总是
  • 从不

这个令人讨厌的属性可能是什么原因?特别是状态永不.它隐藏了功能,然后当您发现它时,会觉得使用起来很脏.因此,如果您在Microsoft工作并实现了此类,请告诉我plz ...:)

What could be the reason for this annoying attribute? Especially the state Never. It's hiding functionality and then when you find it you feel dirty using it. So if you are working at Microsoft and implemented this class tell me plz... :)

我能想象到的唯一情况是,当您想将某件商品标记为过时并将其从智能感知中隐藏起来以便更好地聚焦时,才有意义.但是在所有情况下,我遇到的该属性都没有过时的属性.我发现的最新示例是在wpf中的Dispatcher.CheckAccess()方法中.

The only case I can imagine this attribute makes sense is when you want to mark something as obsolete and hide it from intellisense to focus better. But in all cases I encountered this attribute was used without an obsolete attribute. The most recent example i found is in wpf the Dispatcher.CheckAccess() method.

推荐答案

IMO是VS解决方案内部专用于库构建的属性(当依赖项不在外部时),Intellisense只会忽略它.有用的用例很少.

IMO is an attribute devoted to libraries building, inside your VS solution (when dependencies are not external) Intellisense will simply ignore it. There are few useful use-cases.

让我们首先看到EditorBrowsableState.Advanced:使用某些语言(尤其是VB.NET),您可以指示IDE(实际上是Intellisense)隐藏高级成员,因此您将仅看到最常用的方法.对于初学者来说,噪声更少(当您更好地掌握BCL时,可以启用全屏显示,并且不必为众多晦涩的方法所困扰).

Let's first see EditorBrowsableState.Advanced: with some languages (notably VB.NET) you can instruct IDE (actually Intellisense) to hide advanced members so you'll see only most common methods. Less noise for very beginners (you can enable full view when you master BCL little bit better and you're not intimated by huge number of obscure methods).

EditorBrowsableState.Never还有其他用途.

  • 您所说的就是一个(隐藏不推荐使用的过时方法).一个例子是 old Form.Closing事件(由于被Form.FormClosing替换和扩展而被隐藏).
  • 另一种方法是隐藏错误 typos .例如,如果该属性适用于Keys.HanguelMode,则拼写错误将不可见(但出于兼容性考虑而出现).
  • 如果您需要向其他程序集公开几个 safe 内部方法,这可能也很有用.您不会使用这些方法来污染您的库接口(您可以将它们记录下来,并保留为仅供内部使用).最好比使用>通过 friend 程序集公开所有内部细节.
  • 您可以使用它来隐藏潜在的危险方法.您提供它们是因为某人可能需要它们,但如果可能的话,您想阻止人们使用它们.
  • One is what you said (hide deprecated obsolete methods). An example is old Form.Closing event (hidden because replaced and extended by Form.FormClosing).
  • Another one is to hide errors and typos. If that attribute was applicable to, for example, Keys.HanguelMode then typo won't be visible (but present for compatibility).
  • It may also be useful if you need to expose few safe internal methods to other assemblies. You won't pollute your library interface with that methods (you may keep them documented and keep them as internal use only). It may be better than exposing all internal details through friend assemblies with InternalsVisibleToAttribute.
  • You may use it to hide potentially dangerous methods. You provide them because someone may need them but you want to stop people to use them, if possible.

这篇关于为什么EditorBrowsableState.Never不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆