ValueChangingEventArgs.cs 1.7 KB

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