How can I make all of the IDisposable classes colored differently in the Visual Studio IDE?

I assume this will become easier/extension-free once Roslyn comes out, but this is presently not easy because you can't access the code as C# from an extension easily.

In Resharper it's easy, though! My example was tested in ReSharper 9.0. Sadly, there's no easy way to give this to you.

  • Extensions -> Resharper -> Options -> Code Inspection -> Custom Patterns -> Add, dialog popsup
  • Select C# (upper left)
  • Select "Find" (upper right)
  • Add the pattern of new $disp$($args$)
  • Pattern severity: Show as suggestion
  • Description: Disposable construction
  • "Add Placeholder" of type: Type, name: disp, type: System.IDisposable
  • "Add Placeholder" of type: Arguments, name: args

Save and you'll now get a "suggestion" whenever a new disposable is being constructed.

Adding the pattern $disp$ $var$ = $exp$; could also be helpful.

  • "Add Placeholder" of type: Type, name: disp, type: System.IDisposable
  • "Add Placeholder" of type: Expression, name: exp
  • "Add Placeholder" of type: Identifier, name: var

enter image description here


It is certainly possible to do this though it isn't as simple as just changing a setting. You would need to write a Visual Studio addin to accomplish this.

Visit http://msdn.microsoft.com/en-us/vsx/bb980955.aspx to get started. As others will point out. This is not for the faint of heart.

Here's a link that may point you toward what you are looking for:http://msdn.microsoft.com/en-us/library/bb166778.aspx