@@ -16,48 +16,42 @@ protected CommandBase(ILogger logger = null)
16
16
{
17
17
Logger = logger ?? LogManager . GetLogger ( GetType ( ) . FullName ) ;
18
18
CanExecuteCondition = ( parameter => true ) ;
19
+ OnExecuteCondition = ( parameter => true ) ;
19
20
}
20
21
21
22
protected ILogger Logger { get ; }
22
23
protected abstract void OnExecute ( object parameter ) ;
23
24
24
25
protected Func < object , bool > CanExecuteCondition { get ; private set ; }
25
26
protected Func < object , bool > OnExecuteCondition { get ; private set ; }
26
- private bool RequireReEvaluationOnExecute => OnExecuteCondition != null ;
27
27
28
- protected void AddToCanExecuteEvaluation ( Func < object , bool > furtherCanExecuteEvaluation , bool requireReevaluation = false )
28
+ protected void AddToCanExecuteEvaluation ( Func < object , bool > furtherCanExecuteEvaluation , bool requireReevaluationAlso = false )
29
29
{
30
30
if ( furtherCanExecuteEvaluation == null )
31
31
{
32
32
return ;
33
33
}
34
34
35
- AddToCanExecuteEvaluation ( furtherCanExecuteEvaluation ) ;
35
+ var currentCanExecuteCondition = CanExecuteCondition ;
36
+ CanExecuteCondition = ( parameter ) =>
37
+ currentCanExecuteCondition ( parameter ) && furtherCanExecuteEvaluation ( parameter ) ;
36
38
37
- if ( requireReevaluation )
39
+ if ( requireReevaluationAlso )
38
40
{
39
41
AddToOnExecuteEvaluation ( furtherCanExecuteEvaluation ) ;
40
42
}
41
43
}
42
44
43
- private void AddToCanExecuteEvaluation ( Func < object , bool > furtherCanExecuteEvaluation )
44
- {
45
- var currentCanExecuteCondition = CanExecuteCondition ;
46
- CanExecuteCondition = ( parameter ) =>
47
- currentCanExecuteCondition ( parameter ) && furtherCanExecuteEvaluation ( parameter ) ;
48
- }
49
-
50
- private void AddToOnExecuteEvaluation ( Func < object , bool > furtherCanExecuteEvaluation )
45
+ protected void AddToOnExecuteEvaluation ( Func < object , bool > furtherCanExecuteEvaluation )
51
46
{
52
- if ( OnExecuteCondition == null )
53
- {
54
- OnExecuteCondition = furtherCanExecuteEvaluation ;
55
- }
56
- else
47
+ if ( furtherCanExecuteEvaluation == null )
57
48
{
58
- var currentOnExecute = OnExecuteCondition ;
59
- OnExecuteCondition = ( parameter ) => currentOnExecute ( parameter ) && furtherCanExecuteEvaluation ( parameter ) ;
49
+ return ;
60
50
}
51
+
52
+ var currentOnExecute = OnExecuteCondition ;
53
+ OnExecuteCondition = ( parameter ) =>
54
+ currentOnExecute ( parameter ) && furtherCanExecuteEvaluation ( parameter ) ;
61
55
}
62
56
63
57
public bool CanExecute ( object parameter )
@@ -83,12 +77,9 @@ public void Execute(object parameter)
83
77
{
84
78
try
85
79
{
86
- if ( RequireReEvaluationOnExecute )
80
+ if ( ! OnExecuteCondition ( parameter ) )
87
81
{
88
- if ( ! OnExecuteCondition ( parameter ) )
89
- {
90
- return ;
91
- }
82
+ return ;
92
83
}
93
84
94
85
OnExecute ( parameter ) ;
0 commit comments