CancelEventArgs.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #nullable enable
  2. using System.ComponentModel;
  3. namespace Terminal.Gui;
  4. #pragma warning disable CS1711
  5. /// <summary>
  6. /// <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
  7. /// </summary>
  8. /// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
  9. /// <remarks>
  10. /// Events that use this class can be cancellable. Where applicable, the <see cref="CancelEventArgs.Cancel"/> property
  11. /// should be set to
  12. /// <see langword="true"/> to prevent the state change from occurring.
  13. /// </remarks>
  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. }