.NET Tips and Tricks

Blog archive

Hiding Methods from IntelliSense

Believe it or not, there are times when you have a member in your class that you don't want to appear in the class's IntelliSense lists.

In a column earlier this month I talked about how to have your class work with the .NET Framework support for formatting strings (things like "{0:G}," for example). By the time I had finished implementing this feature, my sample class had a method that no developer would ever call -- the method would only be called by .NET Framework components.

Because my method will never be called by a developer, it doesn't make a lot of sense to have that method cluttering up the class's IntelliSense list. To stop that method from appearing in the class's IntelliSense list, I could decorate the method with the EditorBrowsable attribute, passing the enumerated value EditorBrowsableState.Never. Here's the method from that column with the attribute applied to it:

<EditorBrowsable(EditorBrowsableState.Never)>
Public Function ToString1(format As String, formatProvider As IFormatProvider) As...

The trouble is, other than suppressing this ToString method, I literally cannot think of any other case when I'd want to use this attribute (after all, if I wanted a developer to stop using the method, I'd decorate it with the Obsolete attribute).

I suppose you could use the two attributes together: one to hide the method so a developer won't know about it while keeping the method in the class so old code would run; the other attribute to generate compile time warnings about how existing code should stop using the method. But that sure seems like a lot of work to invest in something you don't want people to use.

Posted by Peter Vogel on 01/21/2016


comments powered by Disqus

Featured

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

  • TypeScript Tops New JetBrains 'Language Promise Index'

    In its latest annual developer ecosystem report, JetBrains introduced a new "Language Promise Index" topped by Microsoft's TypeScript programming language.

Subscribe on YouTube