DisposableObject.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using UnityEngine;
  2. using System;
  3. namespace OpenCVForUnity
  4. {
  5. abstract public class DisposableObject : IDisposable
  6. {
  7. public bool IsDisposed { get; protected set; }
  8. public bool IsEnabledDispose { get; set; }
  9. protected DisposableObject ()
  10. : this (true)
  11. {
  12. }
  13. protected DisposableObject (bool isEnabledDispose)
  14. {
  15. IsEnabledDispose = isEnabledDispose;
  16. IsDisposed = false;
  17. }
  18. public void Dispose ()
  19. {
  20. Dispose (true);
  21. GC.SuppressFinalize (this);
  22. }
  23. protected virtual void Dispose (bool disposing)
  24. {
  25. if (!IsDisposed)
  26. {
  27. if (disposing)
  28. {
  29. }
  30. IsDisposed = true;
  31. }
  32. }
  33. ~DisposableObject ()
  34. {
  35. Dispose (false);
  36. }
  37. public void ThrowIfDisposed ()
  38. {
  39. if (IsDisposed)
  40. throw new ObjectDisposedException (GetType ().FullName);
  41. }
  42. }
  43. }