Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why EditorBrowsableState.Never exists?

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

  • Advanced
  • Always
  • Never

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... :)

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.

like image 303
Diego Frehner Avatar asked Dec 02 '14 15:12

Diego Frehner


1 Answers

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.

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 has other usages.

  • 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.
like image 88
Adriano Repetti Avatar answered Nov 10 '22 13:11

Adriano Repetti