Skip to content

Latest commit

 

History

History
63 lines (48 loc) · 1.4 KB

IDISP021.md

File metadata and controls

63 lines (48 loc) · 1.4 KB

IDISP021

Call this.Dispose(true)

Topic Value
Id IDISP021
Severity Warning
Enabled True
Category IDisposableAnalyzers.Correctness
Code DisposeMethodAnalyzer

Description

Call this.Dispose(true).

Motivation

public class C : IDisposable
{
    public void Dispose()
    {
        this.Dispose(false); // should be true here
    }

    protected virtual void Dispose(bool disposing)
    {
        ...
    }
}

How to fix violations

Use the code fix.

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#pragma warning disable IDISP021 // Call this.Dispose(true)
Code violating the rule here
#pragma warning restore IDISP021 // Call this.Dispose(true)

Or put this at the top of the file to disable all instances.

#pragma warning disable IDISP021 // Call this.Dispose(true)

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness", 
    "IDISP021:Call this.Dispose(true)", 
    Justification = "Reason...")]