public object Execute(object dataContext, ExpressionScope scope)
        {
            var expression = _expression.Execute(dataContext, scope);
            var indexes    = _indexes.Select(i => i.Execute(dataContext, scope));

            return(ObjectHelper.GetIndexProperty(expression, indexes));
        }
Exemple #2
0
        public object Execute(object dataContext, ExpressionScope scope)
        {
            object result;

            object invokeTarget = null;

            object[] invokeArguments = null;

            if (_invokeTarget != null)
            {
                invokeTarget = _invokeTarget.Execute(dataContext, scope);
            }

            if (_invokeArguments != null)
            {
                invokeArguments =
                    _invokeArguments.Select(i => (i != null) ? i.Execute(dataContext, scope) : null).ToArray();
            }

            // Вызов статического метода
            if (invokeTarget is Type)
            {
                ReflectionExtensions.InvokeMember((Type)invokeTarget, _methodName, invokeArguments, out result,
                                                  _genericArguments);
            }
            // Вызов метода динамического объекта
            else if (invokeTarget is IDynamicMetaObjectProvider)
            {
                // Получение свойства динамического объекта
                var methodDelegate = ObjectHelper.GetProperty(invokeTarget, _methodName) as Delegate;

                if (methodDelegate != null)
                {
                    result = ReflectionExtensions.FastDynamicInvoke(methodDelegate, invokeArguments);
                }
                else
                {
                    ReflectionExtensions.InvokeMember(invokeTarget, _methodName, invokeArguments, out result,
                                                      _genericArguments);
                }
            }
            // Вызов метода строготипизированного обычного объекта
            else
            {
                ReflectionExtensions.InvokeMember(invokeTarget, _methodName, invokeArguments, out result,
                                                  _genericArguments);
            }

            return(result);
        }
Exemple #3
0
        public object Execute(object dataContext, ExpressionScope scope)
        {
            var expression = _expression.Execute(dataContext, scope);

            foreach (var section in _sections)
            {
                var label = section.Key.Execute(dataContext, scope);

                if (Equals(label, expression))
                {
                    return(section.Value.Execute(dataContext, scope));
                }
            }

            return(null);
        }
        public object Execute(object dataContext, ExpressionScope scope)
        {
            object result;

            var expression = _expression.Execute(dataContext, scope);

            if (expression is Type)
            {
                result = ReflectionExtensions.GetMemberValue((Type)expression, _memberName);
            }
            else
            {
                result = ObjectHelper.GetProperty(expression, _memberName);
            }

            return(result);
        }
        public object Execute(object dataContext, ExpressionScope scope)
        {
            var expression = _expression.Execute(dataContext, scope);

            if (expression == null)
            {
                if (_type.IsValueType)
                {
                    expression = ReflectionExtensions.GetDefaultValue(_type);
                }
            }
            else
            {
                expression = Convert.ChangeType(expression, _type);
            }

            return(expression);
        }
Exemple #6
0
        private object ExecuteLambdaExpression(object dataContext, ExpressionScope scope, object[] arguments)
        {
            if (_body != null)
            {
                var lambdaScope = new ExpressionScope(scope);

                // Заполнение контекста параметрами функции

                if (arguments != null)
                {
                    for (var i = 0; i < arguments.Length && i < _parameters.Count; ++i)
                    {
                        lambdaScope.DeclareVariable(_parameters[i].Name, arguments[i]);
                    }
                }

                return(_body.Execute(dataContext, lambdaScope));
            }

            return(null);
        }
Exemple #7
0
 public object Execute(object dataContext, ExpressionScope scope)
 {
     return((bool)_condition.Execute(dataContext, scope)
         ? _whenTrue.Execute(dataContext, scope)
         : _whenFalse.Execute(dataContext, scope));
 }