CancelEventArgs.cs 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #nullable enable
  2. using System.ComponentModel;
  3. namespace Terminal.Gui;
  4. /// <summary>
  5. /// <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
  6. /// </summary>
  7. /// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
  8. /// <remarks>
  9. /// Events that use this class can be cancellable. Where applicable, the <see cref="CancelEventArgs.Cancel"/> property
  10. /// should be set to
  11. /// <see langword="true"/> to prevent the state change from occurring.
  12. /// </remarks>
  13. public class CancelEventArgs<T> : CancelEventArgs where T : notnull
  14. {
  15. /// <summary>Initializes a new instance of the <see cref="CancelEventArgs{T}"/> class.</summary>
  16. /// <param name="currentValue">The current (old) value of the property.</param>
  17. /// <param name="newValue">The value the property will be set to if the event is not cancelled.</param>
  18. /// <param name="cancel">Whether the event should be canceled or not.</param>
  19. /// <typeparam name="T">The type of the value for the change being canceled.</typeparam>
  20. public CancelEventArgs (ref readonly T currentValue, ref T newValue, bool cancel = false) : base (cancel)
  21. {
  22. CurrentValue = currentValue;
  23. NewValue = newValue;
  24. }
  25. /// <summary>The value the property will be set to if the event is not cancelled.</summary>
  26. public T NewValue { get; set; }
  27. /// <summary>The current value of the property.</summary>
  28. public T CurrentValue { get; }
  29. }
  30. /// <summary>
  31. /// <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
  32. /// </summary>
  33. /// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
  34. /// <remarks>
  35. /// Events that use this class can be cancellable. Where applicable, the <see cref="CancelEventArgs.Cancel"/> property
  36. /// should be set to
  37. /// <see langword="true"/> to prevent the state change from occurring.
  38. /// </remarks>
  39. public class EventArgs<T> : EventArgs where T : notnull
  40. {
  41. /// <summary>Initializes a new instance of the <see cref="EventArgs{T}"/> class.</summary>
  42. /// <param name="currentValue">The current value of the property.</param>
  43. /// <typeparam name="T">The type of the value.</typeparam>
  44. public EventArgs (ref readonly T currentValue) : base ()
  45. {
  46. CurrentValue = currentValue;
  47. }
  48. /// <summary>The current value of the property.</summary>
  49. public T CurrentValue { get; }
  50. }
  51. /// <summary>
  52. /// <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
  53. /// </summary>
  54. /// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
  55. /// <remarks>
  56. /// Events that use this class can be cancellable. Where applicable, the <see cref="CancelEventArgs.Cancel"/> property
  57. /// should be set to
  58. /// <see langword="true"/> to prevent the state change from occurring.
  59. /// </remarks>
  60. public class CancelEventArgsStruct<T> : CancelEventArgs where T : notnull
  61. {
  62. /// <summary>Initializes a new instance of the <see cref="CancelEventArgs{T}"/> class.</summary>
  63. /// <param name="currentValue">The current (old) value of the property.</param>
  64. /// <param name="newValue">The value the property will be set to if the event is not cancelled.</param>
  65. /// <param name="cancel">Whether the event should be canceled or not.</param>
  66. /// <typeparam name="T">The type of the value for the change being canceled.</typeparam>
  67. public CancelEventArgsStruct (T currentValue, T newValue, bool cancel = false) : base (cancel)
  68. {
  69. CurrentValue = currentValue;
  70. NewValue = newValue;
  71. }
  72. /// <summary>The value the property will be set to if the event is not cancelled.</summary>
  73. public T NewValue { get; set; }
  74. /// <summary>The current value of the property.</summary>
  75. public T CurrentValue { get; }
  76. }