Table of Contents

Method TryGetSource

Namespace
Terminal.Gui.ViewBase
Assembly
Terminal.Gui.dll

TryGetSource(WeakReference<View>?, out View?)

Tries to get the source View from a WeakReference<T>.

public static bool TryGetSource(this WeakReference<View>? weakRef, out View? source)

Parameters

weakRef WeakReference<View>
source View

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

Returns

bool

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

Remarks

This is a convenience method to simplify the common pattern of checking a weak reference and retrieving its target. It's particularly useful with Source.

Example usage:

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