CommandContext.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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> : ICommandContext
  15. {
  16. /// <summary>
  17. /// Initializes a new instance with the specified <see cref="Command"/>,
  18. /// </summary>
  19. /// <param name="command"></param>
  20. /// <param name="binding"></param>
  21. /// <param name="data"></param>
  22. public CommandContext (Command command, TBindingType? binding, object? data = null)
  23. {
  24. Command = command;
  25. Binding = binding;
  26. Data = data;
  27. }
  28. /// <summary>
  29. /// The keyboard or mouse minding that was used to invoke the <see cref="Command"/>, if any.
  30. /// </summary>
  31. public TBindingType? Binding { get; set; }
  32. /// <inheritdoc />
  33. public Command Command { get; set; }
  34. /// <inheritdoc />
  35. public object? Data { get; set; }
  36. }