using System.Reflection; namespace Terminal.Gui; /// Responder base class implemented by objects that want to participate on keyboard and mouse input. public class Responder : IDisposable { private bool _disposedValue; /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resource. public void Dispose () { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Disposing?.Invoke (this, EventArgs.Empty); Dispose (true); GC.SuppressFinalize (this); #if DEBUG_IDISPOSABLE WasDisposed = true; foreach (Responder instance in Instances.Where (x => x.WasDisposed).ToList ()) { Instances.Remove (instance); } #endif } /// Event raised when has been called to signal that this object is being disposed. [CanBeNull] public event EventHandler Disposing; /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// /// If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and /// unmanaged resources can be disposed. If disposing equals false, the method has been called by the runtime from /// inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed. /// /// protected virtual void Dispose (bool disposing) { if (!_disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects) } _disposedValue = true; } } #if DEBUG_IDISPOSABLE /// For debug purposes to verify objects are being disposed properly public bool WasDisposed; /// For debug purposes to verify objects are being disposed properly public int DisposedCount = 0; /// For debug purposes public static List Instances = new (); /// For debug purposes public Responder () { Instances.Add (this); } #endif }