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); }
private Expression CreateItemAccessor(AttributeExpression aex) { return Expression.MakeIndex( _parameter, typeof(ISimpleDbItem).GetProperty("Item"), new[] { Expression.Constant(aex.Name) } ); }
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); }
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)); }
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); }
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); }
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); }
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); } }
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); }
protected virtual Expression VisitSimpleDbAttribute(AttributeExpression nex) { return nex; }
protected override Expression VisitSimpleDbAttribute(AttributeExpression aex) { _attributes.Add(aex); return base.VisitSimpleDbAttribute(aex); }
protected override Expression VisitSimpleDbAttribute(AttributeExpression aex) { return CreateItemAccessor(aex); }