I have a disposable class which implements IDisposalbe interface with disposable pattern. To maintain the constrains, I need to make sure that when the object has been disposed, any subsequent call to any public method throws ObjectDisposedException. The obvious solution is to check a bool value isDisposed and throw an exception. But how can I use some reflection based solution (if any or some other approach) to automatically apply this constrain to every public method. What I don’t want to do is to do this check in every method I have (i.e. prior to every call I do NOT want to call IsObjectDisposed() method)
Apart from the practical application as I have described earlier I need to know a way to automatically call a method let’s say Foo() for every call of a method of a class say MyClass