|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Linq.Expressions; |
| 5 | +using System.Reflection; |
| 6 | +using System.Text; |
| 7 | + |
| 8 | +namespace System.Linq |
| 9 | +{ |
| 10 | + public static class CassandraQueryable |
| 11 | + { |
| 12 | + public static IQueryable<TSource> Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, bool allowFiltering = false) |
| 13 | + { |
| 14 | + if (source == null) |
| 15 | + { |
| 16 | + throw new ArgumentNullException(nameof(source)); |
| 17 | + } |
| 18 | + if (predicate == null) |
| 19 | + { |
| 20 | + throw new ArgumentNullException(nameof(predicate)); |
| 21 | + } |
| 22 | + |
| 23 | + if (allowFiltering) |
| 24 | + { |
| 25 | + return source.Provider.CreateQuery<TSource>( |
| 26 | + Expression.Call( |
| 27 | + null, |
| 28 | + Casandra_Where_TSource_2(typeof(TSource)), |
| 29 | + source.Expression, Expression.Quote(predicate), Expression.Constant(allowFiltering) |
| 30 | + )); |
| 31 | + |
| 32 | + } |
| 33 | + |
| 34 | + return source.Provider.CreateQuery<TSource>( |
| 35 | + Expression.Call( |
| 36 | + null, |
| 37 | + Where_TSource_2(typeof(TSource)), |
| 38 | + source.Expression, Expression.Quote(predicate) |
| 39 | + )); |
| 40 | + } |
| 41 | + |
| 42 | + private static MethodInfo? s_Cassandra_Where_TSource_2; |
| 43 | + private static MethodInfo? s_Where_TSource_2; |
| 44 | + |
| 45 | + private static MethodInfo Casandra_Where_TSource_2(Type TSource) => |
| 46 | + (s_Cassandra_Where_TSource_2 ?? |
| 47 | + (s_Cassandra_Where_TSource_2 = new Func<IQueryable<object>, Expression<Func<object, bool>>, bool, IQueryable<object>>(CassandraQueryable.Where).GetMethodInfo().GetGenericMethodDefinition())) |
| 48 | + .MakeGenericMethod(TSource); |
| 49 | + |
| 50 | + private static MethodInfo Where_TSource_2(Type TSource) => |
| 51 | + (s_Where_TSource_2 ?? |
| 52 | + (s_Where_TSource_2 = new Func<IQueryable<object>, Expression<Func<object, bool>>, IQueryable<object>>(Queryable.Where).GetMethodInfo().GetGenericMethodDefinition())) |
| 53 | + .MakeGenericMethod(TSource); |
| 54 | + } |
| 55 | +} |
0 commit comments