diff options
Diffstat (limited to 'src/SMAPI/Framework/StateTracking/FieldWatchers/BaseDisposableWatcher.cs')
-rw-r--r-- | src/SMAPI/Framework/StateTracking/FieldWatchers/BaseDisposableWatcher.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/BaseDisposableWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/BaseDisposableWatcher.cs new file mode 100644 index 00000000..40ec6c57 --- /dev/null +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/BaseDisposableWatcher.cs @@ -0,0 +1,36 @@ +using System; + +namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers +{ + /// <summary>The base implementation for a disposable watcher.</summary> + internal abstract class BaseDisposableWatcher : IDisposable + { + /********* + ** Properties + *********/ + /// <summary>Whether the watcher has been disposed.</summary> + protected bool IsDisposed { get; private set; } + + + /********* + ** Public methods + *********/ + /// <summary>Stop watching the field and release all references.</summary> + public virtual void Dispose() + { + this.IsDisposed = true; + } + + + /********* + ** Protected methods + *********/ + /// <summary>Throw an exception if the watcher is disposed.</summary> + /// <exception cref="ObjectDisposedException">The watcher is disposed.</exception> + protected void AssertNotDisposed() + { + if (this.IsDisposed) + throw new ObjectDisposedException(this.GetType().Name); + } + } +} |