Repository navigation
Expand file tree
/
Copy pathVirtualRequest.cs
More file actions
112 lines (94 loc) · 2.92 KB
/
Copy pathVirtualRequest.cs
File metadata and controls
112 lines (94 loc) · 2.92 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
// Copyright (c) 2011-2023 Roland Pheasant. All rights reserved.
// Roland Pheasant licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
// ReSharper disable once CheckNamespace
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(0, 25);
/// <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>
/// Gets the start index size comparer.
/// </summary>
/// <value>
/// The start index size comparer.
/// </value>
public static IEqualityComparer<IVirtualRequest?> StartIndexSizeComparer { get; } = new StartIndexSizeEqualityComparer();
/// <summary>
/// Gets the maximum number of items to return.
/// </summary>
public int Size { get; } = 25;
/// <summary>
/// Gets the first index in the virualised list.
/// </summary>
public int StartIndex { get; }
/// <inheritdoc />
public bool Equals(IVirtualRequest? other) => StartIndexSizeComparer.Equals(this, other);
/// <inheritdoc />
public override bool Equals(object? obj) => obj is IVirtualRequest item && Equals(item);
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
return (StartIndex * 397) ^ Size;
}
}
/// <inheritdoc />
public override string ToString() => $"StartIndex: {StartIndex}, Size: {Size}";
private sealed class StartIndexSizeEqualityComparer : IEqualityComparer<IVirtualRequest?>
{
public bool Equals(IVirtualRequest? x, IVirtualRequest? y)
{
if (ReferenceEquals(x, y))
{
return true;
}
if (x is null)
{
return false;
}
if (y is null)
{
return false;
}
if (x.GetType() != y.GetType())
{
return false;
}
return x.StartIndex == y.StartIndex && x.Size == y.Size;
}
public int GetHashCode(IVirtualRequest? obj)
{
if (obj is null)
{
return 0;
}
unchecked
{
return (obj.StartIndex * 397) ^ obj.Size;
}
}
}
}