コード例 #1
0
        public static IEnumerable <T> FindAsImmutability <T>(
            this LiteCollection <T> me,
            Query query,
            int skip  = 0,
            int limit = int.MaxValue)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            var type = typeof(T);

            var engine = (LazyLoad <LiteEngine>)EngineFields.SafeGetOrAdd(
                type,
                () => me.GetType().GetField("_engine", BindingFlags.Instance | BindingFlags.NonPublic))
                         .GetValue(me);

            var includes = (List <string>)IncludingFields.SafeGetOrAdd(
                type,
                () => me.GetType().GetField("_includes", BindingFlags.Instance | BindingFlags.NonPublic))
                           .GetValue(me);

            var docs = engine.Value.Find(me.Name, query, includes.ToArray(), skip, limit);

            foreach (var doc in docs)
            {
                yield return(ToImmutability <T>(doc));
            }
        }
コード例 #2
0
        public static IEnumerable <T> FindAsImmutability <T>(
            this LiteCollection <T> me,
            Expression <Func <T, bool> > predicate,
            int skip  = 0,
            int limit = int.MaxValue)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            var type = typeof(T);

            var visitor = VisitorFields.SafeGetOrAdd(
                type,
                () => me.GetType().GetField("_visitor", BindingFlags.Instance | BindingFlags.NonPublic))
                          .GetValue(me);

            var visit = VisitMethods.SafeGetOrAdd(type, () => visitor.GetType().GetMethod("Visit"));

            return(FindAsImmutability(me, (Query)visit.Invoke(visitor, new object[] { predicate }), skip, limit));
        }