WebDAVDisposableBase.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. namespace WebDAVSharp.Server
  3. {
  4. /// <summary>
  5. /// This abstract base class implements the <see cref="IDisposable" /> pattern in a reusable way.
  6. /// </summary>
  7. public abstract class WebDavDisposableBase : IDisposable
  8. {
  9. #region Properties
  10. private bool _isDisposed;
  11. #endregion
  12. #region Abstract Functions
  13. /// <summary>
  14. /// Releases unmanaged and - optionally - managed resources
  15. /// </summary>
  16. /// <param name="disposing">
  17. /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only
  18. /// unmanaged resources.
  19. /// </param>
  20. protected abstract void Dispose(bool disposing);
  21. #endregion
  22. #region Functions
  23. /// <summary>
  24. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  25. /// </summary>
  26. public void Dispose()
  27. {
  28. Dispose(true);
  29. GC.SuppressFinalize(this);
  30. _isDisposed = true;
  31. }
  32. /// <summary>
  33. /// This method will ensure that the object has not been disposed of through a call
  34. /// to
  35. /// <see cref="Dispose()" />, and if it has, it will throw
  36. /// <see cref="ObjectDisposedException" />
  37. /// </summary>
  38. /// <exception cref="System.ObjectDisposedException">The object has been disposed of.</exception>
  39. protected void EnsureNotDisposed()
  40. {
  41. if (_isDisposed)
  42. throw new ObjectDisposedException(GetType().FullName);
  43. }
  44. #endregion
  45. }
  46. }