Repository navigation
Expand file tree
/
Copy pathVirtualRequest.cs
More file actions
145 lines (123 loc) · 4.39 KB
/
Copy pathVirtualRequest.cs
File metadata and controls
145 lines (123 loc) · 4.39 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
namespace DynamicData
{
/// <summary>
/// A request object for virtualisation
/// </summary>
public class VirtualRequest : IEquatable<IVirtualRequest>, IVirtualRequest
{
/// <summary>
/// The default request value
/// </summary>
public static readonly VirtualRequest Default = new VirtualRequest(0, 25);
private readonly int _size = 25;
private readonly int _startIndex;
/// <summary>
/// Initializes a new instance of the <see cref="VirtualRequest"/> class.
/// </summary>
/// <param name="startIndex">The start index.</param>
/// <param name="size">The size.</param>
public VirtualRequest(int startIndex, int size)
{
_size = size;
_startIndex = startIndex;
}
/// <summary>
/// Initializes a new instance of the <see cref="VirtualRequest"/> class.
/// </summary>
public VirtualRequest()
{
}
/// <summary>
/// The maximumn number of items to return
/// </summary>
public int Size
{
get { return _size; }
}
/// <summary>
/// The first index in the virualised list
/// </summary>
public int StartIndex
{
get { return _startIndex; }
}
#region Equality members
private sealed class StartIndexSizeEqualityComparer : IEqualityComparer<IVirtualRequest>
{
public bool Equals(IVirtualRequest x, IVirtualRequest y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.GetType() != y.GetType()) return false;
return x.StartIndex == y.StartIndex && x.Size == y.Size;
}
public int GetHashCode(IVirtualRequest obj)
{
unchecked
{
return (obj.StartIndex*397) ^ obj.Size;
}
}
}
private static readonly IEqualityComparer<IVirtualRequest> StartIndexSizeComparerInstance = new StartIndexSizeEqualityComparer();
/// <summary>
/// Gets the start index size comparer.
/// </summary>
/// <value>
/// The start index size comparer.
/// </value>
public static IEqualityComparer<IVirtualRequest> StartIndexSizeComparer
{
get { return StartIndexSizeComparerInstance; }
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <returns>
/// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
/// </returns>
/// <param name="other">An object to compare with this object.</param>
public bool Equals(IVirtualRequest other)
{
return StartIndexSizeComparerInstance.Equals(this, other);
}
/// <summary>
/// Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
/// </summary>
/// <returns>
/// true if the specified object is equal to the current object; otherwise, false.
/// </returns>
/// <param name="obj">The object to compare with the current object. </param>
public override bool Equals(object obj)
{
return Equals((IVirtualRequest) obj);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object" />.
/// </returns>
public override int GetHashCode()
{
unchecked
{
return (_startIndex*397) ^ _size;
}
}
#endregion
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
return string.Format("StartIndex: {0}, Size: {1}", _startIndex, _size);
}
}
}