diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-19 18:04:57 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-19 18:04:57 -0400 |
commit | 16281fb58944e7e829b184b014e27822c91c9f43 (patch) | |
tree | e9db3b9943d61163a87190c4293673a002d17da1 /src/StardewModdingAPI/Mod.cs | |
parent | c84310dfebafd3085dc418f3620154f9934865de (diff) | |
parent | cbb1777ba00f581b428e61a0f7245a87ac53cf09 (diff) | |
download | SMAPI-16281fb58944e7e829b184b014e27822c91c9f43.tar.gz SMAPI-16281fb58944e7e829b184b014e27822c91c9f43.tar.bz2 SMAPI-16281fb58944e7e829b184b014e27822c91c9f43.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/Mod.cs')
-rw-r--r-- | src/StardewModdingAPI/Mod.cs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Mod.cs b/src/StardewModdingAPI/Mod.cs index 8033e1fd..171088cf 100644 --- a/src/StardewModdingAPI/Mod.cs +++ b/src/StardewModdingAPI/Mod.cs @@ -1,11 +1,12 @@ using System; using System.IO; using StardewModdingAPI.Framework; +using StardewModdingAPI.Framework.Models; namespace StardewModdingAPI { /// <summary>The base class for a mod.</summary> - public class Mod : IMod + public class Mod : IMod, IDisposable { /********* ** Properties @@ -88,6 +89,14 @@ namespace StardewModdingAPI /// <param name="helper">Provides simplified APIs for writing mods.</param> public virtual void Entry(IModHelper helper) { } + /// <summary>Release or reset unmanaged resources.</summary> + public void Dispose() + { + (this.Helper as IDisposable)?.Dispose(); // deliberate do this outside overridable dispose method so mods don't accidentally suppress it + this.Dispose(true); + GC.SuppressFinalize(this); + } + /********* ** Private methods @@ -106,5 +115,15 @@ namespace StardewModdingAPI } return Path.Combine(this.PathOnDisk, "psconfigs"); } + + /// <summary>Release or reset unmanaged resources when the game exits. There's no guarantee this will be called on every exit.</summary> + /// <param name="disposing">Whether the instance is being disposed explicitly rather than finalised. If this is false, the instance shouldn't dispose other objects since they may already be finalised.</param> + protected virtual void Dispose(bool disposing) { } + + /// <summary>Destruct the instance.</summary> + ~Mod() + { + this.Dispose(false); + } } } |