When implementing IDisposable, I undertand that every method that shouldn't be called after the object's been disposed should throw the ObjectDisposedException. But what is the standard for the name object that should be passed to the exception's constructor?
I believe the recommended practice is to throw the following:
throw new ObjectDisposedException(GetType().FullName); Or including the check, these two lines of code at the top of each method that needs it (obviously not the Dispose method itself):
if (this.disposed) throw new ObjectDisposedException(GetType().FullName); Might even be helpful to refactor this into a tiny method for usability.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With