CheckConstantExpression() public static method

public static CheckConstantExpression ( string methodName, Expression argument, string parameterName ) : ConstantExpression
methodName string
argument System.Linq.Expressions.Expression
parameterName string
return System.Linq.Expressions.ConstantExpression
Esempio n. 1
0
        public Expression Transform(MethodCallExpression methodCallExpression)
        {
            ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression);

            if (methodCallExpression.Arguments.Count == 2)
            {
                return(new SqlFunctionExpression(typeof(bool), "FREETEXT", methodCallExpression.Arguments[0], methodCallExpression.Arguments[1]));
            }
            else if (methodCallExpression.Arguments.Count == 3)
            {
                MethodCallTransformerUtility.CheckConstantExpression(
                    methodCallExpression.Method.Name, methodCallExpression.Arguments[2], "language parameter");

                var compositeExpression = new SqlCompositeCustomTextGeneratorExpression(
                    typeof(string), new SqlCustomTextExpression("LANGUAGE ", typeof(string)), methodCallExpression.Arguments[2]);

                return(new SqlFunctionExpression(
                           typeof(bool), "FREETEXT", methodCallExpression.Arguments[0], methodCallExpression.Arguments[1], compositeExpression));
            }
            else
            {
                var message = string.Format(
                    "IndexOf function with {0} arguments is not supported. Expression: '{1}'",
                    methodCallExpression.Arguments.Count,
                    methodCallExpression);
                throw new NotSupportedException(message);
            }
        }
Esempio n. 2
0
        public Expression Transform(MethodCallExpression methodCallExpression)
        {
            MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 2, 3);
            MethodCallTransformerUtility.CheckStaticMethod(methodCallExpression);

            if (methodCallExpression.Arguments.Count == 2) // overload without language
            {
                return(new SqlFunctionExpression(typeof(bool), "CONTAINS", methodCallExpression.Arguments[0], methodCallExpression.Arguments[1]));
            }
            else
            {
                MethodCallTransformerUtility.CheckConstantExpression(methodCallExpression.Method.Name, methodCallExpression.Arguments[2], "language parameter");

                var compositeExpression = new SqlCompositeCustomTextGeneratorExpression(
                    typeof(string), new SqlCustomTextExpression("LANGUAGE ", typeof(string)), methodCallExpression.Arguments[2]);

                return(new SqlFunctionExpression(
                           typeof(bool), "CONTAINS", methodCallExpression.Arguments[0], methodCallExpression.Arguments[1], compositeExpression));
            }
        }
        public Expression Transform(MethodCallExpression methodCallExpression)
        {
            ArgumentUtility.CheckNotNull("methodCallExpression", methodCallExpression);

            MethodCallTransformerUtility.CheckArgumentCount(methodCallExpression, 2);
            MethodCallTransformerUtility.CheckInstanceMethod(methodCallExpression);
            MethodCallTransformerUtility.CheckConstantExpression("Insert", methodCallExpression.Arguments[0], "insertionIndex");

            var insertionIndexExpression = Expression.Add(methodCallExpression.Arguments[0], new SqlLiteralExpression(1));
            var testExpression           = Expression.Equal(new SqlLengthExpression(methodCallExpression.Object), insertionIndexExpression);

            var concatMethod   = typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) });
            var thenExpression = Expression.Add(methodCallExpression.Object, methodCallExpression.Arguments[1], concatMethod);

            var elseExpression = new SqlFunctionExpression(
                methodCallExpression.Type,
                "STUFF",
                methodCallExpression.Object,
                insertionIndexExpression,
                new SqlLiteralExpression(0),
                methodCallExpression.Arguments[1]);

            return(Expression.Condition(testExpression, thenExpression, elseExpression));
        }