Remotion.Linq.SqlBackend.SqlPreparation.MethodCallTransformers.MethodCallTransformerUtility.CheckConstantExpression C# (CSharp) Method

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
    public static ConstantExpression CheckConstantExpression (string methodName, Expression argument, string parameterName)
    {
      var argumentAsConstantExpression = argument as ConstantExpression;
      if (argumentAsConstantExpression == null)
      {
        var message = string.Format (
            "Only expressions that can be evaluated locally can be used as an argument for {0} ('{1}'). Expression: '{2}'", 
            methodName, 
            parameterName,
            FormattingExpressionTreeVisitor.Format (argument));
        throw new NotSupportedException (message);
      }
      return argumentAsConstantExpression;
    }

Usage Example

Beispiel #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);
            }
        }
All Usage Examples Of Remotion.Linq.SqlBackend.SqlPreparation.MethodCallTransformers.MethodCallTransformerUtility::CheckConstantExpression