Exemplo n.º 1
0
        private IExpression CompileTerm()
        {
            IExpression term = this.CompileSimpleTerm();

            if (term == null)
            {
                return(null);
            }

            while (true)
            {
                if (this.TryCompile(TokenType.Operator, "."))
                {
                    term = new AttributeExpression(term, this.CompileName(true).Value);
                }
                else if (this.TryCompile(TokenType.Separator, "("))
                {
                    term = this.CompileCallExpression(term);
                }
                else if (TryCompile(TokenType.Separator, "["))
                {
                    term = this.CompileIndexedExpression(term);
                }
                else
                {
                    break;
                }
            }

            return(term);
        }
Exemplo n.º 2
0
 private Expression CreateItemAccessor(AttributeExpression aex)
 {
     return Expression.MakeIndex(
         _parameter,
         typeof(ISimpleDbItem).GetProperty("Item"),
         new[] { Expression.Constant(aex.Name) }
     );
 }
Exemplo n.º 3
0
        public static JToken ToJson(AttributeExpression ae)
        {
            var obj = (JObject)ToJson((Expression)ae);

            obj["type"] = "AttributeExpression";
            obj["ref"]  = ToJson((dynamic)ae.Ref);
            obj["name"] = ToJson((dynamic)ae.Name);
            return(obj);
        }
Exemplo n.º 4
0
        public void GetNativeMethod()
        {
            AttributeExpression expression  = new AttributeExpression(new ConstantExpression(1), "GetType");
            BindingEnvironment  environment = new BindingEnvironment();

            var result = expression.Evaluate(environment);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(MethodInfo));
        }
Exemplo n.º 5
0
        public void EvaluateAttributeExpressionOnClassProperty()
        {
            AttributeExpression expression  = new AttributeExpression(new NameExpression("Calculator"), "Value");
            BindingEnvironment  environment = new BindingEnvironment();

            environment.SetValue("Calculator", typeof(Calculator));

            object result = expression.Evaluate(environment);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result);
        }
        private AttributeExpression GetAttributeExpression()
        {
            AttributeExpression attribute = new AttributeExpression(this.LexicalParser.CurrentToken());

            string nextToken = this.LexicalParser.MoveToNextToken();

            if (nextToken == ".")
            {
                this.LexicalParser.MoveToNextToken();
                attribute.ChildExpressions.Add(GetAttributeExpression());
            }

            return(attribute);
        }
Exemplo n.º 7
0
        public void EvaluateAttributeExpressionOnNativeObjectProperty()
        {
            AttributeExpression expression  = new AttributeExpression(new NameExpression("adam"), "FirstName");
            BindingEnvironment  environment = new BindingEnvironment();

            environment.SetValue("adam", new Person()
            {
                FirstName = "Adam"
            });

            object result = expression.Evaluate(environment);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(string));
            Assert.AreEqual("Adam", result);
        }
Exemplo n.º 8
0
        public void EvaluateAttributeExpression()
        {
            AttributeExpression expression  = new AttributeExpression(new NameExpression("module"), "foo");
            BindingEnvironment  environment = new BindingEnvironment();
            BindingEnvironment  modenv      = new BindingEnvironment();

            modenv.SetValue("foo", "bar");
            environment.SetValue("module", modenv);

            object result = expression.Evaluate(environment);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(string));
            Assert.AreEqual("bar", result);
            Assert.IsNotNull(expression.Expression);
            Assert.AreEqual("foo", expression.Name);
        }
Exemplo n.º 9
0
        public void RaiseWhenEvaluateAttributeExpression()
        {
            AttributeExpression expression  = new AttributeExpression(new NameExpression("module"), "spam");
            BindingEnvironment  environment = new BindingEnvironment();
            BindingEnvironment  modenv      = new BindingEnvironment();

            environment.SetValue("module", modenv);

            try
            {
                expression.Evaluate(environment);
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(AttributeError));
                Assert.AreEqual("'module' object has no attribute 'spam'", ex.Message);
            }
        }
Exemplo n.º 10
0
        private static LinqExpression Evaluate(this AttributeExpression expr, System.Linq.Expressions.ParameterExpression arg)
        {
            if (expr == null)
            {
                throw new ArgumentNullException(nameof(expr));
            }

            if (expr.Path == null)
            {
                throw new ArgumentNullException(nameof(expr.Path));
            }

            if (arg == null)
            {
                throw new ArgumentNullException(nameof(arg));
            }

            var resourceAttrParameterExpr = LinqExpression.Parameter(typeof(RepresentationAttribute), "ra");
            var selection = expr.Path.Evaluate(resourceAttrParameterExpr);
            var andEqual  = GetAttributesAny(selection, arg, resourceAttrParameterExpr);

            return(andEqual);
        }
Exemplo n.º 11
0
 protected virtual Expression VisitSimpleDbAttribute(AttributeExpression nex)
 {
     return nex;
 }
Exemplo n.º 12
0
 protected override Expression VisitSimpleDbAttribute(AttributeExpression aex)
 {
     _attributes.Add(aex);
     return base.VisitSimpleDbAttribute(aex);
 }
Exemplo n.º 13
0
 protected override Expression VisitSimpleDbAttribute(AttributeExpression aex)
 {
     return CreateItemAccessor(aex);
 }