CancelEventArgs.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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>The current value of the property.</summary>
  27. public T CurrentValue { get; }
  28. /// <summary>The value the property will be set to if the event is not cancelled.</summary>
  29. public T NewValue { get; set; }
  30. }
  31. /// <summary>
  32. /// <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
  33. /// </summary>
  34. /// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
  35. public class EventArgs<T> : EventArgs where T : notnull
  36. {
  37. /// <summary>Initializes a new instance of the <see cref="EventArgs{T}"/> class.</summary>
  38. /// <param name="currentValue">The current value of the property.</param>
  39. /// <typeparam name="T">The type of the value.</typeparam>
  40. public EventArgs (ref readonly T currentValue) { CurrentValue = currentValue; }
  41. /// <summary>The current value of the property.</summary>
  42. public T CurrentValue { get; }
  43. }
  44. #pragma warning disable CS1711