Reputation: 25927
Is there a point in securing myself against using a disposed class? I just cought myself on adding following two lines to all methods of my IDisposable
class:
if (disposed)
throw new InvalidOperationException("Attempt to use disposed object!");
That just doesn't seem right.
Upvotes: 4
Views: 114
Reputation: 54417
I would suggest that what you have done is overkill. I agree with dkackman that you should probably do as you have for those members that could fail silently but not for all. You could just do as the Form class does and provide an IsDisposed property. It is then the developer's responsibility to check for themselves if they don't already know that the object is disposed or not.
Upvotes: 0
Reputation: 15549
My best answer would be it depends.
Is the disposable class only used within a single project?
Is the class used by anyone outside of yourself or a small team?
What are the side effects of accessing a disposed object?
Upvotes: 3