Topic | Value |
---|---|
Id | IDISP002 |
Severity | Warning |
Enabled | True |
Category | IDisposableAnalyzers.Correctness |
Code | FieldAndPropertyDeclarationAnalyzer |
Dispose the member as it is assigned with a created IDisposable
.
In the example below the file will be left open.
public class Foo
{
private FileStream stream = File.OpenRead("file.txt");
}
Implement IDisposable
and dispose the member.
public sealed class Foo : IDisposable
{
private FileStream stream = File.OpenRead("file.txt");
public void Dispose()
{
this.stream.Dispose();
}
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable IDISP002 // Dispose member
Code violating the rule here
#pragma warning restore IDISP002 // Dispose member
Or put this at the top of the file to disable all instances.
#pragma warning disable IDISP002 // Dispose member
[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness",
"IDISP002:Dispose member",
Justification = "Reason...")]