Table of Contents

Method TryGetSource

Namespace
Terminal.Gui.Input
Assembly
Terminal.Gui.dll

TryGetSource(ICommandContext?, out View?)

Tries to get the source View from a command context.

public static bool TryGetSource(this ICommandContext? context, out View? source)

Parameters

context ICommandContext
source View

When this method returns, contains the source View if the context is not null and the source weak reference target is still alive; otherwise, null.

Returns

bool

true if the context is not null and the source weak reference target is still alive; otherwise, false.

Remarks

This is a convenience method to simplify accessing the source view from a command context. It combines null-checking the context and retrieving the weak reference target in one call.

Example usage:

if (commandContext.TryGetSource(out View? view))
    {
        // use view
    }