using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Serein.Workbench.Avalonia.Commands { /// /// 流程控制命令 /// internal class MyCommand : CommandBase { private readonly Action _execute; private readonly Func _canExecute; /// /// 构造函数接收执行动作和是否可执行的条件 /// /// /// /// public MyCommand(Action execute, Func canExecute = null) { _execute = execute ?? throw new ArgumentNullException(nameof(execute)); _canExecute = canExecute; } /// /// 重写 CanExecute 方法,基于 _canExecute 委托的结果来判断命令是否可执行 /// /// /// public override bool CanExecute(object parameter) { return _canExecute?.Invoke() ?? true; } /// /// 重写 Execute 方法,执行具体的命令逻辑 /// /// public override void Execute(object parameter) { _execute(); } } }