Topic | Value |
---|---|
Id | IDISP005 |
Severity | Warning |
Enabled | True |
Category | IDisposableAnalyzers.Correctness |
Code | ReturnValueAnalyzer |
Return type should indicate that the value should be disposed.
In the following method an IDisposable is created and returned but the api is not clear about that the caller should dispose the recieved value.
public object Meh()
{
return File.OpenRead(string.Empty);
}
Use a returntype that is or implements IDisposable
public IDisposable Meh()
{
return File.OpenRead(string.Empty);
}
or
public Stream Meh()
{
return File.OpenRead(string.Empty);
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable IDISP005 // Return type should indicate that the value should be disposed
Code violating the rule here
#pragma warning restore IDISP005 // Return type should indicate that the value should be disposed
Or put this at the top of the file to disable all instances.
#pragma warning disable IDISP005 // Return type should indicate that the value should be disposed
[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness",
"IDISP005:Return type should indicate that the value should be disposed",
Justification = "Reason...")]