Пример #1
0
        public static IEnumerable <T> Top <T>(IEnumerable <T> source, TopResult topResult)
        {
            double top = topResult.Amount;

            if (topResult.Percent)
            {
                //TODO: if source is infinite, this will freeze
                int size = source.Count();
                top = top * size / 100;
                top = Math.Round(top);
            }
            int returned = 0;

            foreach (var item in source)
            {
                if (returned >= top)
                {
                    break;
                }
                returned++;
                yield return(item);
            }
        }
Пример #2
0
        internal static IEnumerable <T> From <T>(IEnumerable <T> rows, Func <T, bool> predicate, TopResult top)
        {
            var result = Where(rows, predicate);

            if (top != null)
            {
                result = Top(result, top);
            }
            return(result);
        }