It is suggested that IDisposable
objects should be disposed in either using
statement or by calling Dispose()
method. I find it is not intuitive to find out if an object is disposable in Visual Studio.
My question is: is there any way to recognize IDisposable
objects in VS?
If you want to highlight disposable objects differently in VS please check out this post. I personally prefer Resharper answer as I always use R#.
If you just want to figure out if your object is an instance of some interface you can right-button-click on the variable name and Navigate -> Object Browser
or Go to Declaration
and then right-button-click on class name Go to Definition
/Peek Definition
.
You might like Peek Definition
as it shows everything you need inline:
You can always check what methods object has, if it has Dispose()
method then 99.9% it's a disposable object. I'll give this 0.01% for those who give methods bad names :).