Table of Contents

Method ChangeProperty

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

ChangeProperty<T>(T, T, Func<ValueChangingEventArgs<T>, bool>, EventHandler<ValueChangingEventArgs<T>>?, Action<T>, Action<ValueChangedEventArgs<T>>?, EventHandler<ValueChangedEventArgs<T>>?, out T)

Executes a CWP workflow for a property change, with pre- and post-change events.

public static bool ChangeProperty<T>(T currentValue, T newValue, Func<ValueChangingEventArgs<T>, bool> onChanging, EventHandler<ValueChangingEventArgs<T>>? changingEvent, Action<T> doWork, Action<ValueChangedEventArgs<T>>? onChanged, EventHandler<ValueChangedEventArgs<T>>? changedEvent, out T finalValue)

Parameters

currentValue T

The current property value, which may be null for nullable types.

newValue T

The proposed new property value, which may be null for nullable types.

onChanging Func<ValueChangingEventArgs<T>, bool>

The virtual method invoked before the change, returning true to cancel.

changingEvent EventHandler<ValueChangingEventArgs<T>>

The pre-change event raised to allow modification or cancellation.

doWork Action<T>

The action that performs the actual work of setting the property (e.g., updating backing field, calling related methods).

onChanged Action<ValueChangedEventArgs<T>>

The virtual method invoked after the change.

changedEvent EventHandler<ValueChangedEventArgs<T>>

The post-change event raised to notify of the completed change.

finalValue T

The final value after the workflow, reflecting any modifications, which may be null for nullable types.

Returns

bool

True if the property was changed, false if cancelled.

Type Parameters

T

The type of the property value, which may be a nullable reference type (e.g., string ?).

Examples

string? current = _schemeName;
string? proposed = "Base";
Func<ValueChangingEventArgs<string?>, bool> onChanging = OnSchemeNameChanging;
EventHandler<ValueChangingEventArgs<string?>>? changingEvent = SchemeNameChanging;
Action<string?> doWork = value => _schemeName = value;
Action<ValueChangedEventArgs<string?>>? onChanged = OnSchemeNameChanged;
EventHandler<ValueChangedEventArgs<string?>>? changedEvent = SchemeNameChanged;
bool changed = CWPPropertyHelper.ChangeProperty(
    current, proposed, onChanging, changingEvent, doWork, onChanged, changedEvent, out string? final);

Exceptions

InvalidOperationException

Thrown if NewValue is null for non-nullable reference types after the workflow.