using System; using System.Collections.Generic; using System.Linq; namespace AGSS.Utilities; public static class LINQ { /// /// 从给定的序列中分页获取元素。 /// /// 序列中的元素类型。 /// 要从中分页的源序列。 /// 请求的页码,从0开始。 /// 每页包含的元素数量。 /// 返回指定页码和页大小对应的子序列。 /// 如果source为null。 /// 如果pageIndex是负数或者pageSize是非正数。 public static IEnumerable Paginate(this IEnumerable source, int pageIndex, int pageSize) { if (source == null) throw new ArgumentNullException(nameof(source)); if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex), "Page index must be non-negative."); if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize), "Page size must be positive."); return source.Skip(pageIndex * pageSize).Take(pageSize); } }