public TResult Execute <TResult>(Expression expression) { var dataConst = Expression.Constant(data); if (expression is ConstantExpression constExp && constExp.Value is PointlessLinqQueryable <T> quer) { dataConst = Expression.Constant(quer.data); } if (expression is MethodCallExpression mcExp) { PointlessLinqQueryable <T> quer2 = new PointlessLinqQueryable <T>(data); if (mcExp.Method == GetMethodInfo(Queryable.FirstOrDefault, quer2)) { var call = Expression.Call(null, GetMethodInfo(Enumerable.FirstOrDefault, data), dataConst); var lmb2 = Expression.Lambda <Func <TResult> >(call); var fun2 = lmb2.Compile(); return(fun2()); } } var convert = Expression.Convert(dataConst, typeof(TResult)); var lmb = Expression.Lambda <Func <TResult> >(convert); var fun = lmb.Compile(); return(fun()); }
public void CanQueryFirst() { var data = RandomData(100); var query = new PointlessLinqQueryable <LdapUser>(data); var result = query.FirstOrDefault(); result.Should().Be(data[0]); }
public void CanQueryAList() { var data = RandomData(100); var query = new PointlessLinqQueryable <LdapUser>(data); var result = query.ToList(); result.Should().HaveCount(100); }