CC0033 (Dispose field) does not currently handle the dispose pattern · Issue #935 · code-cracker/code-cracker · GitHub
Skip to content

CC0033 (Dispose field) does not currently handle the dispose pattern #935

Description

@Thieum

CodeCracker is not currently considering the dispose pattern, as it ignores the void Dispose(bool) method.

Dispose pattern: https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/dispose-pattern

CodeCracker will output a CC0033 even if the field is disposed:

class C : System.IDisposable
{
    private System.IDisposable d = new System.IO.MemoryStream();

    public void Dispose()
    {
        Dispose(true);
        System.GC.SuppressFinalize(this);
    }
    public void Dispose(bool disposing)
    {
        if (disposing && d != null)
            d.Dispose();
    }
}

CodeCracker only checks for void Dispose(), we should add void Dispose(bool).

This code should generate a CC0033 only if there is no call to dispose on the field in the method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions