Created
April 30, 2009 14:43
-
-
Save anonymous/104477 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Disposable : IDisposable | |
{ | |
#if DEBUG | |
StackTrace stack = new StackTrace(); | |
#endif | |
readonly Action _action; | |
public Disposable(Action action) | |
{ | |
_action = action; | |
} | |
public void Dispose() | |
{ | |
_action(); | |
#if DEBUG | |
GC.SuppressFinalize(this); | |
GC.KeepAlive(this); | |
#endif | |
} | |
#if DEBUG | |
~Disposable() { | |
Debug.Assert(false, "Disposable was not used correctly " + stack.ToString()); | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment