Пример #1
0
        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());
        }
Пример #2
0
        public void CanQueryFirst()
        {
            var data   = RandomData(100);
            var query  = new PointlessLinqQueryable <LdapUser>(data);
            var result = query.FirstOrDefault();

            result.Should().Be(data[0]);
        }
Пример #3
0
        public void CanQueryAList()
        {
            var data   = RandomData(100);
            var query  = new PointlessLinqQueryable <LdapUser>(data);
            var result = query.ToList();

            result.Should().HaveCount(100);
        }