CommandMethods.cs 700 B

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