Saturday, May 19, 2018

c# - Is this how to "Implement IDisposable correctly"?

I ran Code Analysis on one of my projects, and it gave me two finger wags, namely:


CA1063 Implement IDisposable correctly Provide an overridable implementation of Dispose(bool) on 'UserStore' or mark the type as sealed. A call to Dispose(false) should only clean up native resources. A call to Dispose(true) should clean up both managed and native resources.


...on this line of code:


public class UserStore : IUserStore, IUserPasswordStore,  IUserClaimStore

...and this:


CA1063 Implement IDisposable correctly Modify 'UserStore.Dispose()' so that it calls Dispose(true), then calls GC.SuppressFinalize on the current object instance ('this' or 'Me' in Visual Basic), and then returns.


...on my empty Dispose:


public void Dispose()
{
//
}

Can I assassinate two avians with one petrified dirtclod by doing this:


public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

? Is that what it's suggesting?


UPDATE


To answer my question (sort of), apparently not - I figured I'd just add the code and see if the Code Analysis would then feed back the yearned-for "'NRBQ.API.UserStore.Dispose()': no suitable method found to override"

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...