Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. /// <summary>
  5. /// A disposable base class.
  6. /// </summary>
  7. /// <seealso cref="T:System.IDisposable" />
  8. public abstract class DisposableBase : IDisposable
  9. {
  10. private bool _disposed;
  11.  
  12. /// <summary>
  13. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  14. /// </summary>
  15. [DebuggerStepThrough]
  16. public void Dispose() => Dispose(false);
  17.  
  18. /// <summary>
  19. /// Finalizes an instance of the DisposableBase class.
  20. /// </summary>
  21. [DebuggerStepThrough]
  22. ~DisposableBase() => Dispose(true);
  23.  
  24. /// <summary>
  25. /// Dispose resources.
  26. /// </summary>
  27. protected virtual void DisposeResources() { }
  28.  
  29. /// <summary>
  30. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  31. /// </summary>
  32. /// <param name="isFinalizing">true if this DisposableBase is finalizing.</param>
  33. [DebuggerStepThrough]
  34. private void Dispose(bool isFinalizing) {
  35. if(_disposed) return;
  36. DisposeResources();
  37. if(!isFinalizing) GC.SuppressFinalize(this);
  38. _disposed = true;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement