using System; using System.Windows.Input; namespace ToolKit { public class CommandPersonnal : ICommand { private readonly Action _execute; private readonly Func _canExecute; public event EventHandler CanExecuteChanged; public CommandPersonnal(Action execute, Func canExecute = null) { _execute = execute; _canExecute = canExecute ?? (_ => true); } public bool CanExecute(object parameter) { return _canExecute == null || _canExecute((T)parameter); } public void Execute(object parameter) { _execute((T)parameter); } public void RefreshCommand() => CanExecuteChanged?.Invoke(this, EventArgs.Empty); } public class CommandPersonnal : CommandPersonnal { public CommandPersonnal(Action execute, Func canExecute = null) : base( new Action(o => execute()), canExecute != null ? new Func(o => canExecute()) : null ) { } } }