CommandContext.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. #pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved
  4. /// <summary>
  5. /// Provides context for a <see cref="Command"/> that is being invoked.
  6. /// </summary>
  7. /// <remarks>
  8. /// <para>
  9. /// To define a <see cref="Command"/> that is invoked with context,
  10. /// use <see cref="View.AddCommand(Command,Func{CommandContext,System.Nullable{bool}})"/>.
  11. /// </para>
  12. /// </remarks>
  13. #pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved
  14. public record struct CommandContext<TBindingType>
  15. {
  16. /// <summary>
  17. /// Initializes a new instance of <see cref="CommandContext"/> with the specified <see cref="Command"/>,
  18. /// </summary>
  19. /// <param name="command"></param>
  20. /// <param name="key"></param>
  21. /// <param name="binding"></param>
  22. /// <param name="data"></param>
  23. public CommandContext (Command command, TBindingType? binding, object? data = null)
  24. {
  25. Command = command;
  26. Binding = binding;
  27. Data = data;
  28. }
  29. /// <summary>
  30. /// The <see cref="Command"/> that is being invoked.
  31. /// </summary>
  32. public Command Command { get; set; }
  33. /// <summary>
  34. /// The keyboard or mouse minding that was used to invoke the <see cref="Command"/>, if any.
  35. /// </summary>
  36. public TBindingType? Binding { get; set; }
  37. /// <summary>
  38. /// Arbitrary data.
  39. /// </summary>
  40. public object? Data { get; set; }
  41. }