.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

  • IDE Irony: Coding Errors Cause 'Critical' Vulnerability in Visual Studio

    In a larger-than-normal Patch Tuesday, Microsoft warned of a "critical" vulnerability in Visual Studio that should be fixed immediately if automatic patching isn't enabled, ironically caused by coding errors.

  • Building Blazor Applications

    A trio of Blazor experts will conduct a full-day workshop for devs to learn everything about the tech a a March developer conference in Las Vegas keynoted by Microsoft execs and featuring many Microsoft devs.

  • Gradient Boosting Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the gradient boosting regression technique, where the goal is to predict a single numeric value. Compared to existing library implementations of gradient boosting regression, a from-scratch implementation allows much easier customization and integration with other .NET systems.

  • Microsoft Execs to Tackle AI and Cloud in Dev Conference Keynotes

    AI unsurprisingly is all over keynotes that Microsoft execs will helm to kick off the Visual Studio Live! developer conference in Las Vegas, March 10-14, which the company described as "a must-attend event."

  • Copilot Agentic AI Dev Environment Opens Up to All

    Microsoft removed waitlist restrictions for some of its most advanced GenAI tech, Copilot Workspace, recently made available as a technical preview.

Subscribe on YouTube