44
55namespace SimpleStateMachineNodeEditor . Helpers . Commands
66{
7- public class Command < TParameter , TResult > : ICommandWithUndoRedo , ICommand , ICloneable
7+ public class Command < TParameter , TResult > : ICommandWithUndoRedo , ICommand , ICloneable
88 {
99 private readonly Func < TParameter , TResult , TResult > _execute ;
1010 private readonly Func < TParameter , TResult , TResult > _unExecute ;
1111 public Action OnExecute { get ; set ; }
1212 public TParameter Parameters { get ; set ; }
1313 public TResult Result { get ; set ; }
1414 public object Clone ( )
15- {
15+ {
1616 return new Command < TParameter , TResult > ( _execute , _unExecute , OnExecute )
1717 {
1818 Parameters = this . Parameters ,
@@ -32,7 +32,7 @@ public bool CanExecute(object parameter)
3232 return true ;
3333 }
3434
35- public void Execute ( object parameter )
35+ public void Execute ( object parameter = default )
3636 {
3737 Parameters = parameter . Cast < TParameter > ( ) ;
3838
@@ -49,18 +49,18 @@ public void Execute(object parameter)
4949 OnExecute ? . Invoke ( ) ;
5050 }
5151
52- public void UnExecute ( )
53- {
54- this . _unExecute ( Parameters , Result ) ;
52+ void ICommandWithUndoRedo . ExecuteWithSubscribe ( )
53+ {
54+ this . Result = this . _execute ( this . Parameters , this . Result ) ;
5555
56- ICommandWithUndoRedo . AddInRedo ( this . Clone ( ) as ICommandWithUndoRedo ) ;
56+ ICommandWithUndoRedo . AddInUndo ( this . Clone ( ) as ICommandWithUndoRedo ) ;
5757 }
5858
59- public void ExecuteWithSubscribe ( )
59+ void ICommandWithUndoRedo . UnExecute ( )
6060 {
61- this . Result = this . _execute ( this . Parameters , this . Result ) ;
61+ this . _unExecute ( Parameters , Result ) ;
6262
63- ICommandWithUndoRedo . AddInUndo ( this . Clone ( ) as ICommandWithUndoRedo ) ;
63+ ICommandWithUndoRedo . AddInRedo ( this . Clone ( ) as ICommandWithUndoRedo ) ;
6464 }
6565
6666 public Command ( Func < TParameter , TResult , TResult > ExecuteWithSubscribe , Func < TParameter , TResult , TResult > unExecute , Action onExecute = null )
@@ -69,7 +69,7 @@ public Command(Func<TParameter, TResult, TResult> ExecuteWithSubscribe, Func<TPa
6969
7070 _unExecute = unExecute ;
7171
72- OnExecute += onExecute ;
72+ OnExecute += onExecute ;
7373 }
7474 }
7575}
0 commit comments