/// <summary> /// 工厂方法 /// </summary> /// <param name="source"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="totalCount"></param> /// <returns></returns> public static PagerQueryResult <TOutputDto> Create(IEnumerable <TOutputDto> source, int pageIndex, int pageSize, int totalCount) { var instance = new PagerQueryResult <TOutputDto>(); //NbGuard.MakeSureBetweenInclusive(pageIndex, 1, int.MaxValue); //NbGuard.MakeSureBetweenInclusive(pageSize, 1, int.MaxValue); //NbGuard.MakeSureBetweenInclusive(totalCount, 0, int.MaxValue); if (source == null) { throw new ArgumentNullException("source"); } if (pageIndex < 0 || pageSize < 0) { // Check: check if pageSize > totalCount. // Check: check if int parameters < 0. throw new ArgumentException("非法的参数"); } foreach (var item in source) { instance.Result.Add(item); } instance.PageIndex = pageIndex; instance.PageSize = pageSize; instance.TotalCount = totalCount; return(instance); }
/// <summary> /// 返回空的结果 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public static PagerQueryResult <TOutputDto> CreateEmpty(int pageIndex, int pageSize) { var instance = new PagerQueryResult <TOutputDto>(); instance.PageIndex = pageIndex; instance.PageSize = pageSize; instance.TotalCount = 0; return(instance); }
/// <summary> /// 带分页的结果 /// </summary> /// <typeparam name="TOutputDto"></typeparam> /// <param name="source"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="totalCount"></param> /// <returns></returns> public static PagerQueryResult <TOutputDto> WithPage <TOutputDto>(this IEnumerable <TOutputDto> source, int pageIndex, int pageSize, int totalCount) { return(PagerQueryResult <TOutputDto> .Create(source, pageIndex, pageSize, totalCount)); }