分页构造函数
我在看一个开源分页。 在下边第一段代码是扩展方法,最后一行用了构造函数;第二个是构造函数
问题:对构造函数不太清楚,只看到定义了一些int 属性, 没看到List<T>对象; AddRange(items) 这是一个List的方法,对象都没有,怎么直接就写AddRange(items)
/* ASP.NET MvcPager 分页组件 Copyright:2009-2011 陕西省延安市吴起县 杨涛\Webdiyer (http://www.webdiyer.com) Source code released under Ms-PL license */using System.Linq;namespace Webdiyer.WebControls.Mvc{ public static class PageLinqExtensions { public static PagedList<T> ToPagedList<T> ( this IQueryable<T> allItems, int pageIndex, int pageSize ) { if (pageIndex < 1) pageIndex = 1; var itemIndex = (pageIndex-1) * pageSize; var pageOfItems = allItems.Skip(itemIndex).Take(pageSize); var totalItemCount = allItems.Count(); return new PagedList<T>(pageOfItems, pageIndex, pageSize, totalItemCount); } }}/* ASP.NET MvcPager 分页组件 Copyright:2009-2011 陕西省延安市吴起县 杨涛\Webdiyer (http://www.webdiyer.com) Source code released under Ms-PL license */using System;using System.Collections.Generic;namespace Webdiyer.WebControls.Mvc{ public class PagedList<T> : List<T>,IPagedList { public PagedList(IEnumerable<T> items, int pageIndex, int pageSize, int totalItemCount) { AddRange(items); TotalItemCount = totalItemCount; CurrentPageIndex = pageIndex; PageSize = pageSize; } public int CurrentPageIndex { get; set; } public int PageSize { get; set; } public int TotalItemCount { get; set; } public int TotalPageCount { get { return (int)Math.Ceiling(TotalItemCount / (double)PageSize); } } public int StartRecordIndex { get { return (CurrentPageIndex - 1) * PageSize + 1; } } public int EndRecordIndex { get { return TotalItemCount > CurrentPageIndex * PageSize ? CurrentPageIndex * PageSize : TotalItemCount; } } }}