Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

while coding what's the quickest way to determine if a type is IDisposable

In terms of coder productivity what is the quickest way in VS 2005 or 2008 to determine if Foo implements IDisposable. It has happened to me on more than one occasion that I've been caught using a type without a using block because it never occured to me that the thing would need to implement IDisposable.

like image 857
Ralph Shillington Avatar asked Jun 04 '09 13:06

Ralph Shillington


3 Answers

Put it in a using statement and see if it compiles:

using (var x = new TypeInQuestion(params)) {}

This won't compile if the TypeInQuestion doesn't implement IDisposable.

The other fastest way is to use ReSharper, click on the variable (x in this case), and see if it has a suggestion to put it in a using statement.

like image 55
John Saunders Avatar answered Sep 27 '22 22:09

John Saunders


If you've got ReSharper, highlight the variable, wait for the lightbulb, and then hit Alt+Enter. If one of the options is "Wrap with 'using'", it's IDisposable.

like image 35
Chris Doggett Avatar answered Sep 28 '22 00:09

Chris Doggett


Unfortunately there's no "simple simple simple" way.

You're going to have to hit F12 on the class name, and then keep hitting F12 on base classes until you're in the base class, if any of those implement IDisposable, you've got it.

like image 22
Lasse V. Karlsen Avatar answered Sep 28 '22 00:09

Lasse V. Karlsen