Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary finalizer #14

Open
sharwell opened this issue Nov 17, 2014 · 0 comments
Open

Remove unnecessary finalizer #14

sharwell opened this issue Nov 17, 2014 · 0 comments

Comments

@sharwell
Copy link
Member

Diagnostic

A common mistake when implementing IDisposable is including an unnecessary finalizer. The proposed diagnostic would identify finalizers with the following form:

~ClassName()
{
    Dispose(false);
}

It would then examine the methods called by Dispose(bool) method within that class.

  1. Ignore any block of code guarded by if (disposing), where disposing is the first parameter to Dispose(bool).
  2. Ignore any call to IDisposable.Dispose.

If any method calls are remaining after the above steps, do not report the diagnostic.

The message reported by the diagnostic might have the name UnnecessaryFinalizer and a message like the following:

Unnecessary user-defined finalizers should be removed.

Code Fix

The code fix for the above diagnostic is to simply remove the user-defined finalizer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant