summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/StateTracking/FieldWatchers/BaseDisposableWatcher.cs
blob: 40ec6c5707ae10d0af966bcf7a3a2817e0d8c653 (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
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);
        }
    }
}