CancelEventArgs.cs 2.0 KB

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