summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/StateTracking/FieldWatchers/BaseDisposableWatcher.cs
blob: 03bf84d9bdf7f8546148d09c1ecf5cc9690e4fda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#nullable disable

using System;

namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
{
    /// <summary>The base implementation for a disposable watcher.</summary>
    internal abstract class BaseDisposableWatcher : IDisposable
    {
        /*********
        ** Fields
        *********/
        /// <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);
        }
    }
}