Topic | Value |
---|---|
Id | IDISP015 |
Severity | Warning |
Enabled | True |
Category | IDisposableAnalyzers.Correctness |
Code | MethodReturnValuesAnalyzer |
Member should not return created and cached instance.
When calling the method below it is not obvious if we are responsible for disposing the returned instance. Avoid mixing created and cached disposables.
public IDisposable Bar()
{
if (condition)
{
return this.disposable;
}
return File.OpenRead(string.Empty);
}
Redesign.
Configure the severity per project, for more info see MSDN.
#pragma warning disable IDISP015 // Member should not return created and cached instance
Code violating the rule here
#pragma warning restore IDISP015 // Member should not return created and cached instance
Or put this at the top of the file to disable all instances.
#pragma warning disable IDISP015 // Member should not return created and cached instance
[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness",
"IDISP015:Member should not return created and cached instance",
Justification = "Reason...")]