views:

141

answers:

4

Is it possible to identify classes that implement IDisposable. I was hoping to do so in the Visual Studio Color settings or with an addon.

I don't use Resharper and I have heard that FXcop has this feature. I was looking for something different than these options.

+2  A: 

Look for the method Dispose() on the class.

Brody
+3  A: 

You can right click on the type and select go to definition. It should show you the public members of the class and the interfaces it implements. The object browser can also be used to see this.

However Brody's answer is usually the simplest way and works so long as someone hasn't implemented a method called Dispose but not implemented the IDisposable interface.

JoshBerke
+2  A: 

You can use the Class View and Object Browser to determine it. But going to the definition is the best idea as the MetaData generated will show you all the methods and the inheritance of the class

Slace
A: 

Not at a risk of coming across the wrong way (so please don't take it that way), but the best way is to know your code and know the Framework. You should only need to look something up a couple of times to learn which are which. There is not really a dependable way apart from either checking if .Dispose() is a method (which always does not work, as Dispose can be private on some of the Framework classes, such as ManualResetEvent where it is protected), or by going to the definition to find it.

That is not to say that someone could not write an add-in that would do it. I don't see any issues with the technical feasibility of that. A cursory search of Google didn't turn up any existing add-ins that do it, but there might be something out there already.

joseph.ferris
How many classes are their in the BCL you want to tell me you remember every single disposable class you've ever come accross? I do think it should be common to know which types of classes are (DB Connections, File Streams etc...) but there is just to much information to remember it all.
JoshBerke
How often do you use everything? You missed the point. You should know your own code, period. The things you use most often you will be the things you will no longer have to look for.
joseph.ferris
so your suggestion is to memorize the libraries?
Ted Smith
The parts of the framework you use all the time will be absorbed. You should know all of your own code and the rest will fall into place, through association.
joseph.ferris