Table of Contents

Method ExecuteWithResult

Namespace
Terminal.Gui.App
Assembly
Terminal.Gui.dll

ExecuteWithResult<TResult>(Func<ResultEventArgs<TResult>, bool>, EventHandler<ResultEventArgs<TResult>>?, ResultEventArgs<TResult>, Func<TResult>)

Executes a CWP workflow that produces a result, suitable for methods like GetScheme().

public static TResult ExecuteWithResult<TResult>(Func<ResultEventArgs<TResult>, bool> onMethod, EventHandler<ResultEventArgs<TResult>>? eventHandler, ResultEventArgs<TResult> args, Func<TResult> defaultAction)

Parameters

onMethod Func<ResultEventArgs<TResult>, bool>

The virtual method invoked first, returning true to mark the workflow as handled.

eventHandler EventHandler<ResultEventArgs<TResult>>

The event handler to invoke, or null if no handlers are subscribed.

args ResultEventArgs<TResult>

The event arguments containing a result and handled status.

defaultAction Func<TResult>

The default action that produces the result if the workflow is not handled.

Returns

TResult

The result from the event arguments or the default action.

Type Parameters

TResult

The type of the result, which may be a nullable reference type (e.g., Scheme?).

Examples

ResultEventArgs<Scheme?> args = new();
Func<ResultEventArgs<Scheme?>, bool> onGettingScheme = _ => false;
EventHandler<ResultEventArgs<Scheme?>>? gettingSchemeHandler = null;
Func<Scheme> defaultAction = () => SchemeManager.GetScheme("Base");
Scheme scheme = CWPWorkflowHelper.ExecuteWithResult(onGettingScheme, gettingSchemeHandler, args, defaultAction);

Exceptions

ArgumentNullException

Thrown if onMethod, args, or defaultAction is null.

InvalidOperationException

Thrown if Result is null for non-nullable reference types when Handled is true.