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. 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; } } // TODO: v2 - nuke this /// Utilty function to determine is overridden in the . /// The view. /// The method name. /// if it's overridden, otherwise. internal static bool IsOverridden (Responder subclass, string method) { MethodInfo m = subclass.GetType () .GetMethod ( method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly ); if (m is null) { return false; } return m.GetBaseDefinition ().DeclaringType != m.DeclaringType; } #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 }