public AqlExpression Visit(Expression node)
        {
            switch (node)
            {
            case null:
                return(null);

            case ConstantExpression e:
                return(AqlConstantExpression.Create(e.Value));

            case ParameterExpression e:
                return(new AqlParameterExpression(e.Name));

            case UnaryExpression e:
                return(VisitUnary(e));

            case BinaryExpression e:
                return(VisitBinary(e));

            case MemberExpression e
                when e.NodeType == ExpressionType.MemberAccess:
                return(VisitMemberAccess(e));

            case MethodCallExpression e
                when e.NodeType == ExpressionType.Call:
                return(VisitCall(e));

            case NewArrayExpression e
                when e.NodeType == ExpressionType.NewArrayInit:
                return(VisitNewArrayInit(e));

            case NewExpression e:
                return(VisitNew(e));
            }

            throw new AqlParsingException(
                      $"Expression {node} cannot be converted to AQL expression"
                      );
        }
Example #2
0
        /// <summary>
        /// See the only usage in ExpressionConverter to understand
        /// </summary>
        public AqlJsonObjectExpression CallAddViaArgs(
            List <AqlExpression> arguments
            )
        {
            if (arguments.Count != 1 && arguments.Count != 2)
            {
                throw new ArgumentException("Unexpected number of arguments");
            }

            if (arguments[0].ExpressionType != AqlExpressionType.Constant)
            {
                throw new AqlParsingException(
                          "JSON object key cannot be an expression"
                          );
            }

            JsonValue keyValue = ((AqlConstantExpression)arguments[0]).Value;

            if (!keyValue.IsString || keyValue.IsNull)
            {
                throw new AqlParsingException(
                          "JSON object key has to be a non-null string"
                          );
            }

            string key = keyValue.AsString;

            AqlExpression value = new AqlConstantExpression(JsonValue.Null);

            if (arguments.Count == 2)
            {
                value = arguments[1];
            }

            return(Add(key, value));
        }