CancelEventArgs.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  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. }