コード例 #1
0
        /// <summary>
        /// Parse scalar function
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private Expression ParseScalarFunction(ParameterExpression parameter,
                                               FilterParser.ExprContext context)
        {
            var scalarFunctionContext = context.scalarFunction();

            var expr = scalarFunctionContext.scalarTypeFunction() != null?
                       ParseScalarLambda(scalarFunctionContext.scalarTypeFunction()) :
                           ParseScalarLambda(scalarFunctionContext);

            var lhs = Expression.Invoke(expr,
                                        ParseParameterBinding(parameter, scalarFunctionContext.columnName()));
            var rhs = Expression.Constant(context.literal_value() != null ?
                                          ParseLiteralValue(context.literal_value()) : (JsonToken)JToken.FromObject(true));

            return(CreateBinaryExpression(context.COMPARISON_OPERATOR()?.GetText() ?? "=",
                                          lhs, rhs));
        }
コード例 #2
0
        /// <summary>
        /// Parse comparison expression
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private Expression ParseComparisonExpression(ParameterExpression parameter,
                                                     FilterParser.ExprContext context)
        {
            var        lhs = ParseParameterBinding(parameter, context.columnName(0));
            Expression rhs;

            if (context.columnName().Length > 1)
            {
                rhs = ParseParameterBinding(parameter, context.columnName(1));
            }
            else if (context.array_literal() != null)
            {
                rhs = Expression.Constant(context.array_literal().literal_value()
                                          .Select(ParseLiteralValue)
                                          .ToArray());
            }
            else
            {
                rhs = Expression.Constant(ParseLiteralValue(context.literal_value()));
            }
            return(CreateBinaryExpression(context.COMPARISON_OPERATOR().GetText(), lhs, rhs));
        }