-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathPagedList.cs
More file actions
30 lines (20 loc) · 798 Bytes
/
PagedList.cs
File metadata and controls
30 lines (20 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections;
namespace PaginationEF;
public class PagedList<T> : IReadOnlyList<T>
{
private readonly IList<T> subset;
public PagedList(IEnumerable<T> items, int count, int pageNumber, int pageSize)
{
PageNumber = pageNumber;
TotalPages = (int)Math.Ceiling(count / (double)pageSize);
subset = items as IList<T> ?? new List<T>(items);
}
public int PageNumber { get; }
public int TotalPages { get; }
public bool IsFirstPage => PageNumber == 1;
public bool IsLastPage => PageNumber == TotalPages;
public int Count => subset.Count;
public T this[int index] => subset[index];
public IEnumerator<T> GetEnumerator() => subset.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => subset.GetEnumerator();
}