-
Notifications
You must be signed in to change notification settings - Fork 2
/
PagedResult.cs
69 lines (67 loc) · 2.32 KB
/
PagedResult.cs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections.Generic;
namespace Paginator
{
/// <summary>
/// Packages the result of a request showing information
/// about the pagination request made including:
///
/// <list type="bullet">
/// <item>Current Page Number</item>
/// <item>Number of items returned in every page</item>
/// <item>Total number of pages holding all the items in the list</item>
/// <item>Total number of items in the data source matching your <c>Request</c></item>
/// <item>List array contaning (x) number</item>
/// </list>
/// </summary>
/// <typeparam name="T"></typeparam>
public class PagedResult<T>
{
/// <summary>
/// Constructor
/// </summary>
public PagedResult()
{
Items = new List<T>();
}
/// <summary>
/// Current page in pagination
/// </summary>
public int Page { get; set; }
/// <summary>
/// Total number of items in every page as per
/// pagination request. Defaults to 10.
/// </summary>
public int ItemsPerPage { get; set; }
/// <summary>
/// Number of pages used to paginate collection with
/// each page containing (x) items per page
/// </summary>
public int TotalPages { get; set; }
/// <summary>
/// Number of items matching your pagination request
/// </summary>
public int TotalItems { get; set; }
/// <summary>
/// Collection containing items in the current page.
/// </summary>
public IList<T> Items { get; set; }
/// <summary>
/// Calculates & returns the hashcode of the current object.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hash = 17;
// Suitable nullity checks etc, of course :)
hash = hash * 23 + Page.GetHashCode();
hash = hash * 23 + ItemsPerPage.GetHashCode();
hash = hash * 23 + TotalPages.GetHashCode();
hash = hash * 23 + TotalItems.GetHashCode();
hash = hash * 23 + Items.GetHashCode();
return hash;
}
}
}
}