Exemple #1
0
        public void To(Expression <Func <TContext, ICommand> > destinationExpression)
        {
            var contextParameter = destinationExpression.Parameters[0];
            var commandParameter = Expression.Parameter(typeof(ICommand));

            var assignCommand =
                Binder.ExpressionCompiler.Compile(
                    Expression.Lambda <Action <TContext, ICommand> >(
                        Expression.Assign(
                            destinationExpression.Body,
                            commandParameter),
                        contextParameter,
                        commandParameter));

            var getCommand = Binder.ExpressionCompiler.Compile(destinationExpression);
            var canExecute = Binder.ExpressionCompiler.Compile(_canExecuteExpression);
            var key        = _key ?? destinationExpression.GetTargetKey();

            _dependencies.Add(_canExecuteExpression);

            _binder.AddRule(ctx => assignCommand(ctx, new ActionCommand(ctx, _executeAction, canExecute, _hasParameter, _canExecuteCheckMode)), key, _debugContext.CreateContext(typeof(TContext).Name, key), true, true, Enumerable.Empty <LambdaExpression>());
            _binder.AddRule(ctx => UpdateCanExecuteOnCommand(getCommand(ctx)), key, _debugContext.CreateContext(typeof(TContext).Name, key + "_CanExecute"), true, false, _dependencies);
        }
 private void AddRule(Action <TContext> action, string key)
 {
     _binder.AddRule(_debugAction == null ? action : _debugAction + action, key, _debugContext.CreateContext(typeof(TContext).Name, key), _runOnAttach, _canOverride, _dependencies);
 }