using System;
namespace StardewModdingAPI
{
/// The base class for a mod.
public abstract class Mod : IMod, IDisposable
{
/*********
** Accessors
*********/
///
public IModHelper Helper { get; internal set; } = null!;
///
public IMonitor Monitor { get; internal set; } = null!;
///
public IManifest ModManifest { get; internal set; } = null!;
/*********
** Public methods
*********/
///
public abstract void Entry(IModHelper helper);
///
public virtual object? GetApi()
{
return null;
}
/// Release or reset unmanaged resources.
public void Dispose()
{
(this.Helper as IDisposable)?.Dispose(); // deliberately do this outside overridable dispose method so mods don't accidentally suppress it
this.Dispose(true);
GC.SuppressFinalize(this);
}
/*********
** Private methods
*********/
/// Release or reset unmanaged resources when the game exits. There's no guarantee this will be called on every exit.
/// Whether the instance is being disposed explicitly rather than finalized. If this is false, the instance shouldn't dispose other objects since they may already be finalized.
protected virtual void Dispose(bool disposing) { }
/// Destruct the instance.
~Mod()
{
(this.Helper as IDisposable)?.Dispose(); // deliberately do this outside overridable dispose method so mods don't accidentally suppress it
this.Dispose(false);
}
}
}