WebDAVDisposableBase.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. namespace Mtp2Dav.WebDAVSharp.Server._1d2086a502937936ebc6bfe19cfa15d855be1c31
  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. private bool _isDisposed;
  10. /// <summary>
  11. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  12. /// </summary>
  13. public void Dispose()
  14. {
  15. Dispose(true);
  16. GC.SuppressFinalize(this);
  17. _isDisposed = true;
  18. }
  19. /// <summary>
  20. /// This method will ensure that the object has not been disposed of through a call
  21. /// to
  22. /// <see cref="Dispose()" />, and if it has, it will throw
  23. /// <see cref="ObjectDisposedException" />
  24. /// </summary>
  25. /// <exception cref="System.ObjectDisposedException">The object has been disposed of.</exception>
  26. protected void EnsureNotDisposed()
  27. {
  28. if (_isDisposed)
  29. throw new ObjectDisposedException(GetType().FullName);
  30. }
  31. /// <summary>
  32. /// Releases unmanaged and - optionally - managed resources
  33. /// </summary>
  34. /// <param name="disposing">
  35. /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only
  36. /// unmanaged resources.
  37. /// </param>
  38. protected abstract void Dispose(bool disposing);
  39. }
  40. }