Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Title covers it all. I'd like classes which implement IDisposable to show up in a specific color so I can know if I should wrap them in a using block. Is there a setting or a process by which you can extend the IDE?

like image 233
quillbreaker Avatar asked Jul 27 '09 16:07

quillbreaker


1 Answers

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 popup
  • 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

like image 190
Joseph Lennox Avatar answered Oct 22 '22 19:10

Joseph Lennox