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

CC0029 should only apply if the class has a finalizer #990

Open
AridTag opened this issue Jul 21, 2018 · 0 comments
Open

CC0029 should only apply if the class has a finalizer #990

AridTag opened this issue Jul 21, 2018 · 0 comments

Comments

@AridTag
Copy link

AridTag commented Jul 21, 2018

Version 1.1.0

The CC0029 warning should only show up if the class implementing IDisposable contains a finalizer itself.

MSDN Remarks on GC.SuppressFinalize

If obj does not have a finalizer, the call to the SuppressFinalize method has no effect.

In this example our class owns an IDisposable that may itself have a finalizer but we don't need to know that. Our example class is disposing the disposable and has no finalizer itself.

public class Example : IDisposable
{
    private bool _IsDisposed;
    private IDisposable _SomeDisposable;

    public Example(IDisposable someDisposable)
    {
        _SomeDisposable = someDisposable;
    }

    public void Dispose()
    {
        Dispose(true);
    }

    private void Dispose(bool disposing)
    {
        if (!_IsDisposed)
        {
            if (disposing)
            {
                if (_SomeDisposable != null)
                {
                    _SomeDisposable.Dispose();
                    _SomeDisposable = null;
                }
            }
        }
        _IsDisposed = true;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant