コード例 #1
0
        /// <summary>
        /// build specification from rsql query
        /// </summary>
        /// <param name="queryCollection"></param>
        /// <returns></returns>
        private Expression <Func <T, bool> > Build(IQueryCollection queryCollection)
        {
            var result = QueryExpressionHelper.True <T>();

            if (queryCollection.TryGetValue(_autumnSettings.QueryField, out var query))
            {
                result = GetOrRegistryQuery(query, _autumnSettings);
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// visit a comparison expression
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Expression <Func <T, bool> > VisitComparison(QueryParser.ComparisonContext context)
        {
            var comparator = context.comparator().GetText().ToLowerInvariant();

            switch (comparator)
            {
            case "=is-null=":
            case "=nil=":
                return(QueryExpressionHelper.GetIsNullExpression <T>(_parameter, context, _namingStrategy));

            case "==":
            case "=eq=":
                return(QueryExpressionHelper.GetEqExpression <T>(_parameter, context, _namingStrategy));

            case "!=":
            case "=neq=":
                return(QueryExpressionHelper.GetNeqExpression <T>(_parameter, context, _namingStrategy));

            case "<":
            case "=lt=":
                return(QueryExpressionHelper.GetLtExpression <T>(_parameter, context, _namingStrategy));

            case "<=":
            case "=le=":
                return(QueryExpressionHelper.GetLeExpression <T>(_parameter, context, _namingStrategy));

            case ">":
            case "=gt=":
                return(QueryExpressionHelper.GetGtExpression <T>(_parameter, context, _namingStrategy));

            case ">=":
            case "=ge=":
                return(QueryExpressionHelper.GetGeExpression <T>(_parameter, context, _namingStrategy));

            case "=in=":
                return(QueryExpressionHelper.GetInExpression <T>(_parameter, context, _namingStrategy));

            case "=out=":
            case "=nin=":
                return(QueryExpressionHelper.GetOutExpression <T>(_parameter, context, _namingStrategy));

            default:
                throw new QueryComparisonUnknownComparatorException(context);
            }
        }
コード例 #3
0
 private static Expression <Func <T, bool> > GetOrRegistryQuery(string query, AutumnSettings autumnSettings)
 {
     lock (QueryExpressionHelper.QueriesCache)
     {
         if (string.IsNullOrWhiteSpace(query))
         {
             return(QueryExpressionHelper.True <T>());
         }
         var hash = Hash($"{typeof(T).FullName}?{query}");
         if (QueryExpressionHelper.QueriesCache.TryGetValue(hash, out Expression <Func <T, bool> > result))
         {
             return(result);
         }
         var antlrInputStream  = new AntlrInputStream(query);
         var lexer             = new QueryLexer(antlrInputStream);
         var commonTokenStream = new CommonTokenStream(lexer);
         var parser            = new QueryParser(commonTokenStream);
         var eval    = parser.or();
         var visitor = new DefaultQueryVisitor <T>(autumnSettings.NamingStrategy);
         result = visitor.VisitOr(eval);
         QueryExpressionHelper.QueriesCache.Set(hash, result);
         return(result);
     }
 }
コード例 #4
0
 /// <summary>
 /// visit a and expression
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public override Expression <Func <T, bool> > VisitAnd(QueryParser.AndContext context)
 {
     return(QueryExpressionHelper.GetAndExpression(this, context));
 }