Closed TonyValenti closed 2 years ago
Have you seen CA2000: Dispose objects before losing scope?
Other IDisposable
-related analyzers:
https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2213 https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1063 https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2215 https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1001
Closing. Please reopen if you have more questions.
Brief description: A class that implements
IDisposable
is special because it may represent a resource (potentially unmanaged) that should be freed. As C# is increasingly used to write low-level code, this continually becomes more and more important.An analyzer should exist that will flag when classes that implement
IDisposable
are created that:using
)var x = new <IDisposable Type>
tousing var x = new <IDisposable Type>
Additionally, it would be nice if the Visual Studio editor provided some type of unique colorization for variables that are of types that implement IDisposable.