ValueChangingEventArgs.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. namespace Terminal.Gui.App;
  2. /// <summary>
  3. /// Provides data for events that allow modification or cancellation of a property change in the Cancellable Work Pattern (CWP).
  4. /// </summary>
  5. /// <remarks>
  6. /// <para>
  7. /// Used in pre-change events raised by <see cref="CWPPropertyHelper.ChangeProperty{T}"/> to allow handlers to
  8. /// modify the proposed value or cancel the change, such as for <see cref="View.SchemeName"/> or
  9. /// <see cref="OrientationHelper"/>.
  10. /// </para>
  11. /// </remarks>
  12. /// <typeparam name="T">The type of the property value, which may be a nullable reference type (e.g., <see cref="string"/>?).</typeparam>
  13. /// <seealso cref="ValueChangedEventArgs{T}"/>
  14. /// <seealso cref="CWPPropertyHelper"/>
  15. public class ValueChangingEventArgs<T>
  16. {
  17. /// <summary>
  18. /// Gets the current value before the change.
  19. /// </summary>
  20. public T CurrentValue { get; }
  21. /// <summary>
  22. /// Gets or sets the proposed new value, which can be modified by event handlers.
  23. /// </summary>
  24. public T NewValue { get; set; }
  25. /// <summary>
  26. /// Gets or sets a value indicating whether the change has been handled. If true, the change is cancelled.
  27. /// </summary>
  28. public bool Handled { get; set; }
  29. /// <summary>
  30. /// Initializes a new instance of the <see cref="ValueChangingEventArgs{T}"/> class.
  31. /// </summary>
  32. /// <param name="currentValue">The current value before the change, which may be null for nullable types.</param>
  33. /// <param name="newValue">The proposed new value, which may be null for nullable types.</param>
  34. public ValueChangingEventArgs (T currentValue, T newValue)
  35. {
  36. CurrentValue = currentValue;
  37. NewValue = newValue;
  38. }
  39. }