CancelEventArgs.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.ComponentModel;
  2. namespace Terminal.Gui.App;
  3. #pragma warning disable CS1711
  4. /// <summary>
  5. /// Provides data for events that can be cancelled without a changeable result in a cancellable workflow in the Cancellable Work Pattern (CWP).
  6. /// </summary>
  7. /// <remarks>
  8. /// Used for workflows where a change (e.g., a simple property change) can be cancelled, but the
  9. /// value being changed is not directly modified by the event handlers.
  10. /// </remarks>
  11. /// <typeparam name="T">The type of the value that is being changed.</typeparam>
  12. /// <seealso cref="ValueChangingEventArgs{T}"/>
  13. /// <seealso cref="ResultEventArgs{T}"/>
  14. public class CancelEventArgs<T> : CancelEventArgs where T : notnull
  15. {
  16. /// <summary>Initializes a new instance of the <see cref="CancelEventArgs{T}"/> class.</summary>
  17. /// <param name="currentValue">The current (old) value of the property.</param>
  18. /// <param name="newValue">The value the property will be set to if the event is not cancelled.</param>
  19. /// <param name="cancel">Whether the event should be canceled or not.</param>
  20. /// <typeparam name="T">The type of the value for the change being canceled.</typeparam>
  21. public CancelEventArgs (ref readonly T currentValue, ref T newValue, bool cancel = false) : base (cancel)
  22. {
  23. CurrentValue = currentValue;
  24. NewValue = newValue;
  25. }
  26. /// <summary>
  27. /// Initializes a new instance of the <see cref="CancelEventArgs{T}"/> class.
  28. /// </summary>
  29. /// <param name="currentValue">The current (old) value of the property.</param>
  30. /// <param name="newValue">The value the property will be set to if the event is not cancelled.</param>
  31. protected CancelEventArgs (T currentValue, T newValue)
  32. {
  33. CurrentValue = currentValue;
  34. NewValue = newValue;
  35. }
  36. /// <summary>The current value of the property.</summary>
  37. public T CurrentValue { get; }
  38. /// <summary>The value the property will be set to if the event is not cancelled.</summary>
  39. public T NewValue { get; set; }
  40. }