private Expression ResolveSymbolNode(SymbolNode node, Expression memberExpression, Type expectedType) { if (memberExpression == null) { throw new ArgumentNullException(nameof(memberExpression)); } if (memberExpression == this.thisParam) { if (node.Name == "this") { return(this.thisParam); } if (node.Name == "true") { return(Expression.Constant(true)); } if (node.Name == "false") { return(Expression.Constant(false)); } if (node.Name == "null") { return(Expression.Constant(null, expectedType ?? typeof(object))); } ParameterExpression parameter; if (this.parameters.TryGetValue(node.Name, out parameter)) { return(parameter); } } return(MakePropertyAccess(node, memberExpression)); }
private static Expression ResolveDictionaryAccess(SymbolNode node, Expression memberExpression, Type dictionaryType) { var key = node.Name; var method = QueryFunctionMapping.SafeGetMethod.MakeGenericMethod(dictionaryType.GetGenericArguments()); return(Expression.Call(method, memberExpression, Expression.Constant(key))); }
public LambdaNode(IEnumerable<NodeBase> children) : base(NodeType.Lambda, children) { if (Children.Count != 2) throw new PomonaExpressionSyntaxException("Error parsing lambda expression"); if (Children[0].NodeType != NodeType.Symbol) throw new PomonaExpressionSyntaxException("Left side of lambda expression needs to be a symbol."); argument = Children[0] as SymbolNode; body = Children[1]; }
private Expression MakePropertyAccess(SymbolNode currentNode, Expression target, string expressionPath = null) { expressionPath = expressionPath ?? currentNode.Name; StructuredProperty prop; if (!this.propertyResolver.TryResolveProperty(target.Type, expressionPath, out prop)) { throw CreateParseException(currentNode, "Property not recognized."); } if (!prop.Flags.HasFlag(PropertyFlags.AllowsFiltering) || !prop.AccessMode.HasFlag(HttpMethod.Get)) { throw CreateParseException(currentNode, $"Property {prop.JsonName} is not allowed for query.", errorReason: QueryParseErrorReason.MemberNotAllowedInQuery, memberName: prop.JsonName); } return(prop.CreateGetterExpression(target)); }