CommandMethods.cs 875 B

123456789101112131415161718192021222324252627282930
  1. using System.Threading.Tasks;
  2. using PixiEditor.AvaloniaUI.Models.Commands.Commands;
  3. using PixiEditor.AvaloniaUI.Models.Commands.Evaluators;
  4. namespace PixiEditor.AvaloniaUI.Models.Commands;
  5. internal class CommandMethods
  6. {
  7. public CanExecuteEvaluator CanExecuteEvaluator => _canExecute;
  8. private readonly Command _command;
  9. private readonly Action<object> _execute;
  10. private readonly CanExecuteEvaluator _canExecute;
  11. public CommandMethods(Command command, Action<object> execute, CanExecuteEvaluator canExecute)
  12. {
  13. _execute = execute;
  14. _canExecute = canExecute;
  15. _command = command;
  16. }
  17. public void Execute(object parameter)
  18. {
  19. if (CanExecute(parameter))
  20. {
  21. _execute(parameter);
  22. }
  23. }
  24. public bool CanExecute(object parameter) => _canExecute.CallEvaluate(_command, parameter);
  25. }