#nullable enable namespace Terminal.Gui.App; using System; /// /// Provides helper methods for executing event-driven workflows in the Cancellable Work Pattern (CWP). /// /// /// /// Used for workflows where an event is raised to allow cancellation or customization of a result, /// such as in . The method invokes an /// event handler and returns whether the operation was handled, supporting result production /// scenarios with . /// /// /// public static class CWPEventHelper { /// /// Executes an event-driven CWP workflow by raising an event. /// /// The type of the result in the event arguments. /// The event handler to invoke, or null if no handler is subscribed. /// The event arguments, containing a result and handled status. /// True if the event was handled, false otherwise. /// Thrown if is null. /// /// /// EventHandler<ResultEventArgs<Key>>? keyDownHandler = (sender, args) => /// { /// if (args.Result?.KeyCode == KeyCode.Q | KeyCode.CtrlMask) /// { /// args.Handled = true; /// } /// }; /// ResultEventArgs<Key> args = new(new Key(KeyCode.Q | KeyCode.CtrlMask)); /// bool handled = CWPEventHelper.Execute(keyDownHandler, args); /// /// public static bool Execute ( EventHandler>? eventHandler, ResultEventArgs args) { ArgumentNullException.ThrowIfNull (args); if (eventHandler == null) { return false; } eventHandler.Invoke (null, args); return args.Handled; } }