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<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<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.

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 = null;
string? proposed = "Base";
Func<ValueChangingEventArgs<string?>, bool> onChanging = args => false;
EventHandler<ValueChangingEventArgs<string?>>? changingEvent = null;
Action<ValueChangedEventArgs<string?>>? onChanged = args =>
    Console.WriteLine($"SchemeName changed to {args.NewValue ?? "none"}.");
EventHandler<ValueChangedEventArgs<string?>>? changedEvent = null;
bool changed = CWPPropertyHelper.ChangeProperty(
    current, proposed, onChanging, changingEvent, onChanged, changedEvent, out string? final);

Exceptions

InvalidOperationException

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