Пример #1
0
 public static IQueryable Where(this IQueryable source, string predicate, QueryResolver queryResolver)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (predicate == null)
     {
         throw new ArgumentNullException("predicate");
     }
     LambdaExpression expression = DynamicExpression.ParseLambda(source.ElementType, typeof(bool), predicate, queryResolver);
     return source.Provider.CreateQuery(Expression.Call(typeof(Queryable), "Where", new Type[] { source.ElementType }, new Expression[] { source.Expression, Expression.Quote(expression) }));
 }
Пример #2
0
 public ExpressionParser(ParameterExpression[] parameters, string expression, QueryResolver queryResolver)
 {
     if (expression == null)
     {
         throw new ArgumentNullException("expression");
     }
     if (keywords == null)
     {
         keywords = CreateKeywords();
     }
     this.queryResolver = queryResolver;
     this.symbols = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
     this.literals = new Dictionary<Expression, string>();
     if (parameters != null)
     {
         this.ProcessParameters(parameters);
     }
     this.text = expression;
     this.textLen = this.text.Length;
     this.SetTextPos(0);
     this.NextToken();
 }
Пример #3
0
 public static IQueryable OrderBy(this IQueryable source, string ordering, QueryResolver queryResolver)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (ordering == null)
     {
         throw new ArgumentNullException("ordering");
     }
     ParameterExpression[] parameters = new ParameterExpression[] { Expression.Parameter(source.ElementType, "") };
     IEnumerable<DynamicOrdering> enumerable = new ExpressionParser(parameters, ordering, queryResolver).ParseOrdering();
     Expression expression = source.Expression;
     string str = "OrderBy";
     string str2 = "OrderByDescending";
     foreach (DynamicOrdering ordering2 in enumerable)
     {
         expression = Expression.Call(typeof(Queryable), ordering2.Ascending ? str : str2, new Type[] { source.ElementType, ordering2.Selector.Type }, new Expression[] { expression, Expression.Quote(DynamicExpression.Lambda(ordering2.Selector, parameters)) });
         str = "ThenBy";
         str2 = "ThenByDescending";
     }
     return source.Provider.CreateQuery(expression);
 }
Пример #4
0
 public static LambdaExpression ParseLambda(Type itType, Type resultType, string expression, QueryResolver queryResolver)
 {
     return ParseLambda(new ParameterExpression[] { Expression.Parameter(itType, "") }, resultType, expression, queryResolver);
 }
Пример #5
0
 public static LambdaExpression ParseLambda(ParameterExpression[] parameters, Type resultType, string expression, QueryResolver queryResolver)
 {
     ExpressionParser parser = new ExpressionParser(parameters, expression, queryResolver);
     return Lambda(parser.Parse(resultType), parameters);
 }