Coding the fastest way to determine if an IDisposable type is

As for encoder performance, what is the fastest way in VS 2005 or 2008 to determine if Foo IDisposable implements. It happened to me more than once that I was caught using a type without a block using, because it never occurred to me that a thing would have to implement IDisposable.

+5
source share
10 answers

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

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

This will not compile unless TypeInQuestionit implements IDisposable.

- ReSharper, (x ) , using.

+8

ReSharper, , Alt + Enter. : "Wrap with 'using", IDisposable.

+6

, .

F12 , F12 , , - IDisposable, .

+1

IO, / , , Dispose.

, "Close" , , , XmlReader ( IDisposable), Dispose, .

+1

- , , ( ) , , IDisposable. . , .

+1

IDE, , - IDisposible, . IDE , , .

+1

PowerShell, .

[System.Management.Automation.Runspaces.pipeline].getinterface("IDisposable")

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    IDisposable

[datetime].getinterface("IDisposable")

.

+1

ReSharper, Visual Studio, , , stringWriter :

TextWriter writer = new StringWriter();
writer.WriteLine("Test");

"" "" "", :

using (TextWriter writer = new StringWriter()) {
    writer.WriteLine("Test");
}

" ..." , IDisposable.

+1

, intellisense .Dispose

( , () )

0

, FXCop, , IDisposable arent using().

# , , , , ".Dispose()", , , IDisposable. , intellisence Dispose(), () ... !

-1

All Articles