views:

150

answers:

6

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?

A: 

You cannot. This would require language service support and neither C# or VB.Net provide this functionality.

Cannot is probably too strong of a word. It's certainly possible to do this with an Add-In which does deep inspection of the code and figures out hierarchies. However it's a very non-trivial task.

JaredPar
+3  A: 

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

codeelegance
good points. here is another good link http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.textmanager.interop.ivshicoloritem.aspx
Stan R.
I used to program ATL COM objects. I'm not faint-hearted.
quillbreaker
A: 

Sure, there is a large set of tools to build VS extensions, see Visual Studio 2008 SDK 1.1 But time required to build such an add-in will require more time that you will spend by browsing components and determining whether they are Disposable or not

Bogdan_Ch
A: 

I am not sure, if FXCop or StyleCop can do this already. But then, it will be a post-compile suggestion/warning.

Resharper suggests this, I guess.

shahkalpesh
A: 

The word on the street is this kind of thing will be much easier in VS.NET 2010. The editor is being rewritten in WPF.

Jake Pearson
A: 

Maybe I'm a bad person for doing this, but I've been using this piece of code recently:

public static void BulkDispose(object[] objects)
{
  foreach (object o in objects)
  {
    if (o != null)
    {
      if (o is IDisposable)
      {
        IDisposable disposable = o as IDisposable;
        disposable.Dispose();
      }
    }
  }
}
quillbreaker