DisposableObject.cs 997 B

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