4
4
5
5
namespace SimpleStateMachineNodeEditor . Helpers . Commands
6
6
{
7
- public class Command < TParameter , TResult > : ICommandWithUndoRedo , ICommand , ICloneable
7
+ public class Command < TParameter , TResult > : ICommandWithUndoRedo , ICommand , ICloneable
8
8
{
9
9
private readonly Func < TParameter , TResult , TResult > _execute ;
10
10
private readonly Func < TParameter , TResult , TResult > _unExecute ;
11
11
public Action OnExecute { get ; set ; }
12
12
public TParameter Parameters { get ; set ; }
13
13
public TResult Result { get ; set ; }
14
14
public object Clone ( )
15
- {
15
+ {
16
16
return new Command < TParameter , TResult > ( _execute , _unExecute , OnExecute )
17
17
{
18
18
Parameters = this . Parameters ,
@@ -32,7 +32,7 @@ public bool CanExecute(object parameter)
32
32
return true ;
33
33
}
34
34
35
- public void Execute ( object parameter )
35
+ public void Execute ( object parameter = default )
36
36
{
37
37
Parameters = parameter . Cast < TParameter > ( ) ;
38
38
@@ -49,18 +49,18 @@ public void Execute(object parameter)
49
49
OnExecute ? . Invoke ( ) ;
50
50
}
51
51
52
- public void UnExecute ( )
53
- {
54
- this . _unExecute ( Parameters , Result ) ;
52
+ void ICommandWithUndoRedo . ExecuteWithSubscribe ( )
53
+ {
54
+ this . Result = this . _execute ( this . Parameters , this . Result ) ;
55
55
56
- ICommandWithUndoRedo . AddInRedo ( this . Clone ( ) as ICommandWithUndoRedo ) ;
56
+ ICommandWithUndoRedo . AddInUndo ( this . Clone ( ) as ICommandWithUndoRedo ) ;
57
57
}
58
58
59
- public void ExecuteWithSubscribe ( )
59
+ void ICommandWithUndoRedo . UnExecute ( )
60
60
{
61
- this . Result = this . _execute ( this . Parameters , this . Result ) ;
61
+ this . _unExecute ( Parameters , Result ) ;
62
62
63
- ICommandWithUndoRedo . AddInUndo ( this . Clone ( ) as ICommandWithUndoRedo ) ;
63
+ ICommandWithUndoRedo . AddInRedo ( this . Clone ( ) as ICommandWithUndoRedo ) ;
64
64
}
65
65
66
66
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
69
69
70
70
_unExecute = unExecute ;
71
71
72
- OnExecute += onExecute ;
72
+ OnExecute += onExecute ;
73
73
}
74
74
}
75
75
}
0 commit comments