public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }
            if (methodCallExpression.Object == null)
            {
                throw new InvalidOperationException();
            }

            if (methodCallExpression.Object.Type == typeof (string))
            {
                expressionTreeVisitor.Visit(methodCallExpression.Object);
            }
            else
            {
                var expression = expressionTreeVisitor.Expression;

                expression.Append("TOSTRING(");
                expressionTreeVisitor.Visit(methodCallExpression.Object);
                expression.Append(")");
            }

            return methodCallExpression;
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append(" LIKE '%");

            var indexInsertStarted = expression.Length;

            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);

            var indexInsertEnded = expression.Length;

            expression.Append("%')");

            //Remove extra quote marks which have been added due to the string in the clause, these aren't needed as they have been added already in this case.
            expression.Remove(indexInsertStarted, 1);
            expression.Remove(indexInsertEnded - 2, 1);

            return methodCallExpression;
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("SUBSTR(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append(", ");
            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);

            if (methodCallExpression.Arguments.Count > 1)
            {
                expression.Append(", ");
                expressionTreeVisitor.Visit(methodCallExpression.Arguments[1]);
            }
            else if (methodCallExpression.Method.Name == "get_Chars")
            {
                // Called str[i], so return a single character at i
                expression.Append(", 1");
            }

            expression.Append(")");

            return methodCallExpression;
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var argument = methodCallExpression.Arguments[0];
            var methodCallArgument = argument as MethodCallExpression;

            if ((methodCallArgument != null) && SupportMethods.Contains(methodCallArgument.Method))
            {
                // Two method calls are reversing each other, so just skip them both

                return expressionTreeVisitor.Visit(methodCallArgument.Arguments[0]);
            }

            var expression = expressionTreeVisitor.Expression;

            if (methodCallExpression.Method.Name == "FromDateTime")
            {
                expression.Append("STR_TO_MILLIS(");
            }
            else
            {
                expression.Append("MILLIS_TO_STR(");
            }

            expressionTreeVisitor.Visit(argument);

            expression.Append(')');

            return methodCallExpression;
        }
Exemplo n.º 5
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }
            if (methodCallExpression.Object == null)
            {
                throw new InvalidOperationException();
            }

            if (methodCallExpression.Object.Type == typeof(string))
            {
                expressionTreeVisitor.Visit(methodCallExpression.Object);
            }
            else
            {
                var expression = expressionTreeVisitor.Expression;

                expression.Append("TOSTRING(");
                expressionTreeVisitor.Visit(methodCallExpression.Object);
                expression.Append(")");
            }

            return(methodCallExpression);
        }
Exemplo n.º 6
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("SUBSTR(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append(", ");
            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);

            if (methodCallExpression.Arguments.Count > 1)
            {
                expression.Append(", ");
                expressionTreeVisitor.Visit(methodCallExpression.Arguments[1]);
            }
            else if (methodCallExpression.Method.Name == "get_Chars")
            {
                // Called str[i], so return a single character at i
                expression.Append(", 1");
            }

            expression.Append(")");

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var argument           = methodCallExpression.Arguments[0];
            var methodCallArgument = argument as MethodCallExpression;

            if ((methodCallArgument != null) && SupportMethods.Contains(methodCallArgument.Method))
            {
                // Two method calls are reversing each other, so just skip them both

                return(expressionTreeVisitor.Visit(methodCallArgument.Arguments[0]));
            }

            var expression = expressionTreeVisitor.Expression;

            if (methodCallExpression.Method.Name == "FromDateTime")
            {
                expression.Append("STR_TO_MILLIS(");
            }
            else
            {
                expression.Append("MILLIS_TO_STR(");
            }

            expressionTreeVisitor.Visit(argument);

            expression.Append(')');

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }
            if (expressionTreeVisitor == null)
            {
                throw new ArgumentNullException("expressionTreeVisitor");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append(" LIKE ");

            var constantExpression = methodCallExpression.Arguments[0] as ConstantExpression;

            if ((constantExpression != null) && (constantExpression.Type == typeof(string)) &&
                (constantExpression.Value != null))
            {
                // This is a string constant, so we can build the literal in advance

                var newExpression = Expression.Constant(
                    (methodCallExpression.Method.Name != StartsWith ? "%" : "") +
                    constantExpression.Value +
                    (methodCallExpression.Method.Name != EndsWith ? "%" : ""));

                expressionTreeVisitor.Visit(newExpression);
            }
            else
            {
                // The argument is dynamic, so we must build the comparison in N1QL

                if (methodCallExpression.Method.Name != StartsWith)
                {
                    expression.Append("\"%\" || ");
                }

                expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);

                if (methodCallExpression.Method.Name != EndsWith)
                {
                    expression.Append(" || \"%\"");
                }
            }

            expression.Append(')');

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }
            if (expressionTreeVisitor == null)
            {
                throw new ArgumentNullException("expressionTreeVisitor");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append(" LIKE ");

            var constantExpression = methodCallExpression.Arguments[0] as ConstantExpression;
            if ((constantExpression != null) && (constantExpression.Type == typeof(string)) &&
                (constantExpression.Value != null))
            {
                // This is a string constant, so we can build the literal in advance

                var newExpression = Expression.Constant(
                    (methodCallExpression.Method.Name != StartsWith ? "%" : "") +
                    constantExpression.Value +
                    (methodCallExpression.Method.Name != EndsWith ? "%" : ""));

                expressionTreeVisitor.Visit(newExpression);
            }
            else
            {
                // The argument is dynamic, so we must build the comparison in N1QL

                if (methodCallExpression.Method.Name != StartsWith)
                {
                    expression.Append("'%' || ");
                }

                expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);

                if (methodCallExpression.Method.Name != EndsWith)
                {
                    expression.Append(" || '%'");
                }
            }

            expression.Append(')');

            return methodCallExpression;
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            string functionName;
            if (!SupportedMethodNames.TryGetValue(methodCallExpression.Method.Name, out functionName))
            {
                throw new NotSupportedException("Unsupported Math Method");
            }

            expression.AppendFormat("{0}(", functionName);

            for (var i=0; i<methodCallExpression.Arguments.Count; i++)
            {
                if (i > 0)
                {
                    expression.Append(", ");
                }

                expressionTreeVisitor.Visit(methodCallExpression.Arguments[i]);
            }

            expression.Append(')');

            return methodCallExpression;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Translate the given method call expression.
        /// </summary>
        /// <param name="methodCallExpression">Method call to be translated.  Must match the method provided to the constructor.</param>
        /// <param name="expressionTreeVisitor"><see cref="N1QlExpressionTreeVisitor"/> to use to visit parameters.</param>
        /// <returns>Original or altered expression.</returns>
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }
            if (expressionTreeVisitor == null)
            {
                throw new ArgumentNullException("expressionTreeVisitor");
            }
            if (methodCallExpression.Method != MethodInfo)
            {
                throw new ArgumentException("Cannot translate a method other than the one provided to the constructor.", "methodCallExpression");
            }

            expressionTreeVisitor.Expression.Append(N1QlFunctionName);
            expressionTreeVisitor.Expression.Append('(');

            for (var i = 0; i < methodCallExpression.Arguments.Count; i++)
            {
                if (i > 0)
                {
                    expressionTreeVisitor.Expression.Append(", ");
                }

                expressionTreeVisitor.Visit(methodCallExpression.Arguments[i]);
            }

            expressionTreeVisitor.Expression.Append(')');

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append('[');
            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);
            expression.Append(']');

            return methodCallExpression;
        }
Exemplo n.º 13
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append('[');
            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);
            expression.Append(']');

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);

            if (methodCallExpression.Arguments.Count > 1)
            {
                var constantExpression = methodCallExpression.Arguments[1] as ConstantExpression;
                if (constantExpression == null)
                {
                    throw new NotSupportedException("IsMissing and IsNotMissing propertyName parameter must be a constant");
                }

                expression.AppendFormat(".{0}",
                    N1QlHelpers.EscapeIdentifier(constantExpression.Value.ToString()));
            }

            expression.Append(methodCallExpression.Method.Name == "IsMissing" ? " IS MISSING" : " IS NOT MISSING");

            return methodCallExpression;
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);

            if (methodCallExpression.Arguments.Count > 1)
            {
                var constantExpression = methodCallExpression.Arguments[1] as ConstantExpression;
                if (constantExpression == null)
                {
                    throw new NotSupportedException("IsValued and IsNotValued propertyName parameter must be a constant");
                }

                expression.AppendFormat(".{0}",
                                        N1QlHelpers.EscapeIdentifier(constantExpression.Value.ToString()));
            }

            expression.Append(methodCallExpression.Method.Name == "IsValued" ? " IS VALUED" : " IS NOT VALUED");

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append('(');

            bool first = true;
            foreach (var argument in GetConcatenatedItems(methodCallExpression))
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    expression.Append(" || ");
                }

                expressionTreeVisitor.Visit(argument);
            }

            expression.Append(')');

            return methodCallExpression;
        }
Exemplo n.º 17
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            string functionName;

            if (!SupportedMethodNames.TryGetValue(methodCallExpression.Method.Name, out functionName))
            {
                throw new NotSupportedException("Unsupported Math Method");
            }

            expression.AppendFormat("{0}(", functionName);

            for (var i = 0; i < methodCallExpression.Arguments.Count; i++)
            {
                if (i > 0)
                {
                    expression.Append(", ");
                }

                expressionTreeVisitor.Visit(methodCallExpression.Arguments[i]);
            }

            expression.Append(')');

            return(methodCallExpression);
        }
Exemplo n.º 18
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append('(');

            bool first = true;

            foreach (var argument in GetConcatenatedItems(methodCallExpression))
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    expression.Append(" || ");
                }

                expressionTreeVisitor.Visit(argument);
            }

            expression.Append(')');

            return(methodCallExpression);
        }
Exemplo n.º 19
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("SPLIT(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);

            if (methodCallExpression.Arguments[0].Type != typeof(char[]))
            {
                throw new NotSupportedException("String Split Operations Expect Character Array Parameters");
            }

            try
            {
                var lambda = Expression.Lambda <Func <char[]> >(methodCallExpression.Arguments[0]).Compile();
                var chars  = lambda.Invoke();

                if ((chars != null) && (chars.Length > 0))
                {
                    if (chars.Length > 1)
                    {
                        throw new NotSupportedException("Cannot Split With More Than One Character");
                    }

                    expression.Append(", ");

                    expressionTreeVisitor.Visit(Expression.Constant(chars[0], typeof(char)));
                }
            }
            catch (NotSupportedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new NotSupportedException("Unable To Parse Split Character Set.  Dynamic Expressions Are Not Supported", ex);
            }

            expression.Append(")");

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("SPLIT(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);

            if (methodCallExpression.Arguments[0].Type != typeof(char[]))
            {
                throw new NotSupportedException("String Split Operations Expect Character Array Parameters");
            }

            try
            {
                var lambda = Expression.Lambda<Func<char[]>>(methodCallExpression.Arguments[0]).Compile();
                var chars = lambda.Invoke();

                if ((chars != null) && (chars.Length > 0))
                {
                    if (chars.Length > 1)
                    {
                        throw new NotSupportedException("Cannot Split With More Than One Character");
                    }

                    expression.Append(", ");

                    expressionTreeVisitor.Visit(Expression.Constant(chars[0], typeof(char)));
                }
            }
            catch (NotSupportedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new NotSupportedException("Unable To Parse Split Character Set.  Dynamic Expressions Are Not Supported", ex);
            }

            expression.Append(")");

            return methodCallExpression;
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append(methodCallExpression.Method.Name == "TrimStart" ? "LTRIM(" :
                methodCallExpression.Method.Name == "TrimEnd" ? "RTRIM(" : "TRIM(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);

            if (methodCallExpression.Arguments.Count > 0)
            {
                if (methodCallExpression.Arguments[0].Type != typeof (char[]))
                {
                    throw new NotSupportedException("String Trim Operations Expect Character Array Parameters");
                }

                try
                {
                    var lambda = Expression.Lambda<Func<char[]>>(methodCallExpression.Arguments[0]).Compile();
                    var chars = lambda.Invoke();

                    if ((chars != null) && (chars.Length > 0))
                    {
                        expression.Append(", ");

                        expressionTreeVisitor.Visit(Expression.Constant(new String(chars), typeof (string)));
                    }
                }
                catch (NotSupportedException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new NotSupportedException("Unable To Parse Trim Character Set.  Dynamic Expressions Are Not Supported", ex);
                }
            }

            expression.Append(")");

            return methodCallExpression;
        }
Exemplo n.º 22
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append(methodCallExpression.Method.Name == "TrimStart" ? "LTRIM(" :
                              methodCallExpression.Method.Name == "TrimEnd" ? "RTRIM(" : "TRIM(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);

            if (methodCallExpression.Arguments.Count > 0)
            {
                if (methodCallExpression.Arguments[0].Type != typeof(char[]))
                {
                    throw new NotSupportedException("String Trim Operations Expect Character Array Parameters");
                }

                try
                {
                    var lambda = Expression.Lambda <Func <char[]> >(methodCallExpression.Arguments[0]).Compile();
                    var chars  = lambda.Invoke();

                    if ((chars != null) && (chars.Length > 0))
                    {
                        expression.Append(", ");

                        expressionTreeVisitor.Visit(Expression.Constant(new String(chars), typeof(string)));
                    }
                }
                catch (NotSupportedException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new NotSupportedException("Unable To Parse Trim Character Set.  Dynamic Expressions Are Not Supported", ex);
                }
            }

            expression.Append(")");

            return(methodCallExpression);
        }
        /// <summary>
        /// Translate the given method call expression.
        /// </summary>
        /// <param name="methodCallExpression">Method call to be translated.  Must match the method provided to the constructor.</param>
        /// <param name="expressionTreeVisitor"><see cref="N1QlExpressionTreeVisitor"/> to use to visit parameters.</param>
        /// <returns>Original or altered expression.</returns>
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }
            if (expressionTreeVisitor == null)
            {
                throw new ArgumentNullException("expressionTreeVisitor");
            }
            if (methodCallExpression.Method != MethodInfo)
            {
                throw new ArgumentException("Cannot translate a method other than the one provided to the constructor.", "methodCallExpression");
            }

            expressionTreeVisitor.Expression.Append(N1QlFunctionName);
            expressionTreeVisitor.Expression.Append('(');

            for (var i = 0; i < methodCallExpression.Arguments.Count; i++)
            {
                if (i > 0)
                {
                    expressionTreeVisitor.Expression.Append(", ");
                }

                var argument = methodCallExpression.Arguments[i];

                if (argument.Type == typeof(DateTime) && expressionTreeVisitor.QueryGenerationContext.IsUnixMillisecondsMember(argument))
                {
                    expressionTreeVisitor.Expression.Append("MILLIS_TO_STR(");
                    expressionTreeVisitor.Visit(methodCallExpression.Arguments[i]);
                    expressionTreeVisitor.Expression.Append(')');
                }
                else
                {
                    expressionTreeVisitor.Visit(methodCallExpression.Arguments[i]);
                }
            }

            expressionTreeVisitor.Expression.Append(')');

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            // Do not process ToArray, ToList, or AsEnumerable.  Instead just visit the list in the first argument.

            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            // Do not process ToArray, ToList, or AsEnumerable.  Instead just visit the list in the first argument.

            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);

            return methodCallExpression;
        }
Exemplo n.º 26
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append(methodCallExpression.Method.Name == "ToLower" ? "LOWER(" : "UPPER(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append(")");

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append(methodCallExpression.Method.Name == "ToLower" ? "LOWER(" : "UPPER(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append(")");

            return methodCallExpression;
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException(nameof(methodCallExpression));
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("OBJECT_VALUES(");
            expressionTreeVisitor.Visit(methodCallExpression.Object);
            expression.Append(')');

            return(methodCallExpression);
        }
Exemplo n.º 29
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }
            if (expressionTreeVisitor == null)
            {
                throw new ArgumentNullException("expressionTreeVisitor");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("META(");
            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);
            expression.Append(").id");

            return(methodCallExpression);
        }
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }
            if (expressionTreeVisitor == null)
            {
                throw new ArgumentNullException("expressionTreeVisitor");
            }

            var expression = expressionTreeVisitor.Expression;

            expression.Append("META(");
            expressionTreeVisitor.Visit(methodCallExpression.Arguments[0]);
            expression.Append(").id");

            return methodCallExpression;
        }
Exemplo n.º 31
0
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }

            if (methodCallExpression.Arguments[0] is ConstantExpression keyExpression)
            {
                var expression = expressionTreeVisitor.Expression;

                expressionTreeVisitor.Visit(methodCallExpression.Object);
                expression.Append('.');
                expression.Append(N1QlHelpers.EscapeIdentifier(keyExpression.Value.ToString()));
            }
            else
            {
                throw new NotSupportedException("Dictionary keys must be constants");
            }

            return(methodCallExpression);
        }
        /// <summary>
        /// Translate the given method call expression.
        /// </summary>
        /// <param name="methodCallExpression">Method call to be translated.  Must match the method provided to the constructor.</param>
        /// <param name="expressionTreeVisitor"><see cref="N1QlExpressionTreeVisitor"/> to use to visit parameters.</param>
        /// <returns>Original or altered expression.</returns>
        public Expression Translate(MethodCallExpression methodCallExpression, N1QlExpressionTreeVisitor expressionTreeVisitor)
        {
            if (methodCallExpression == null)
            {
                throw new ArgumentNullException("methodCallExpression");
            }
            if (expressionTreeVisitor == null)
            {
                throw new ArgumentNullException("expressionTreeVisitor");
            }
            if (methodCallExpression.Method != MethodInfo)
            {
                throw new ArgumentException("Cannot translate a method other than the one provided to the constructor.", "methodCallExpression");
            }

            expressionTreeVisitor.Expression.Append(N1QlFunctionName);
            expressionTreeVisitor.Expression.Append('(');

            for (var i = 0; i < methodCallExpression.Arguments.Count; i++)
            {
                if (i > 0)
                {
                    expressionTreeVisitor.Expression.Append(", ");
                }

                expressionTreeVisitor.Visit(methodCallExpression.Arguments[i]);
            }

            expressionTreeVisitor.Expression.Append(')');

            return methodCallExpression;
        }