-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathValueTupleEqualityComparer.cs
214 lines (205 loc) · 12.8 KB
/
ValueTupleEqualityComparer.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Gapotchenko.FX
// Copyright © Gapotchenko and Contributors
//
// File introduced by: Oleksiy Gapotchenko
// Year of introduction: 2023
namespace Gapotchenko.FX.Tuples;
/// <summary>
/// Provides equality comparison functionality for value tuples.
/// </summary>
public static class ValueTupleEqualityComparer
{
/// <summary>
/// Creates a value tuple equality comparer for <see cref="ValueTuple{T1}"/> with the specified equality comparer for its component.
/// </summary>
/// <typeparam name="T1">The type of the value tuple's first component.</typeparam>
/// <param name="comparer1">
/// The <see cref="IEqualityComparer{T}"/> to use when comparing the value tuple's first component,
/// or <see langword="null"/> to use the default equality comparer for <typeparamref name="T1"/> type.
/// </param>
/// <returns>An instance of value tuple equality comparer.</returns>
public static IEqualityComparer<ValueTuple<T1>> Create<T1>(IEqualityComparer<T1>? comparer1) =>
comparer1 is null
? EqualityComparer<ValueTuple<T1>>.Default
: new ValueTupleEqualityComparer<T1>(comparer1);
/// <summary>
/// Creates a value tuple equality comparer for <see cref="ValueTuple{T1, T2}"/> with the specified equality comparers for its components.
/// </summary>
/// <inheritdoc cref="Create{T1}(IEqualityComparer{T1}?)"/>
/// <typeparam name="T1"><inheritdoc/></typeparam>
/// <typeparam name="T2">The type of the value tuple's second component.</typeparam>
/// <param name="comparer1"><inheritdoc/></param>
/// <param name="comparer2">
/// The <see cref="IEqualityComparer{T}"/> to use when comparing the value tuple's second component,
/// or <see langword="null"/> to use the default equality comparer for <typeparamref name="T2"/> type.
/// </param>
public static IEqualityComparer<(T1, T2)> Create<T1, T2>(IEqualityComparer<T1>? comparer1, IEqualityComparer<T2>? comparer2) =>
comparer1 is null && comparer2 is null
? EqualityComparer<(T1, T2)>.Default
: new ValueTupleEqualityComparer<T1, T2>(comparer1, comparer2);
/// <summary>
/// Creates a value tuple equality comparer for <see cref="ValueTuple{T1, T2, T3}"/> with the specified equality comparers for its components.
/// </summary>
/// <inheritdoc cref="Create{T1, T2}(IEqualityComparer{T1}?, IEqualityComparer{T2}?)"/>
/// <typeparam name="T1"><inheritdoc/></typeparam>
/// <typeparam name="T2"><inheritdoc/></typeparam>
/// <typeparam name="T3">The type of the value tuple's third component.</typeparam>
/// <param name="comparer1"><inheritdoc/></param>
/// <param name="comparer2"><inheritdoc/></param>
/// <param name="comparer3">
/// The <see cref="IEqualityComparer{T}"/> to use when comparing the value tuple's third component,
/// or <see langword="null"/> to use the default equality comparer for <typeparamref name="T3"/> type.
/// </param>
public static IEqualityComparer<(T1, T2, T3)> Create<T1, T2, T3>(
IEqualityComparer<T1>? comparer1,
IEqualityComparer<T2>? comparer2,
IEqualityComparer<T3>? comparer3) =>
comparer1 is null && comparer2 is null && comparer3 is null
? EqualityComparer<(T1, T2, T3)>.Default
: new ValueTupleEqualityComparer<T1, T2, T3>(comparer1, comparer2, comparer3);
/// <summary>
/// Creates a value tuple equality comparer for <see cref="ValueTuple{T1, T2, T3, T4}"/> with the specified equality comparers for its components.
/// </summary>
/// <inheritdoc cref="Create{T1, T2, T3}(IEqualityComparer{T1}?, IEqualityComparer{T2}?, IEqualityComparer{T3}?)"/>
/// <typeparam name="T1"><inheritdoc/></typeparam>
/// <typeparam name="T2"><inheritdoc/></typeparam>
/// <typeparam name="T3"><inheritdoc/></typeparam>
/// <typeparam name="T4">The type of the value tuple's fourth component.</typeparam>
/// <param name="comparer1"><inheritdoc/></param>
/// <param name="comparer2"><inheritdoc/></param>
/// <param name="comparer3"><inheritdoc/></param>
/// <param name="comparer4">
/// The <see cref="IEqualityComparer{T}"/> to use when comparing the value tuple's fourth component,
/// or <see langword="null"/> to use the default equality comparer for <typeparamref name="T4"/> type.
/// </param>
public static IEqualityComparer<(T1, T2, T3, T4)> Create<T1, T2, T3, T4>(
IEqualityComparer<T1>? comparer1,
IEqualityComparer<T2>? comparer2,
IEqualityComparer<T3>? comparer3,
IEqualityComparer<T4>? comparer4) =>
comparer1 is null && comparer2 is null && comparer3 is null && comparer4 is null
? EqualityComparer<(T1, T2, T3, T4)>.Default
: new ValueTupleEqualityComparer<T1, T2, T3, T4>(comparer1, comparer2, comparer3, comparer4);
/// <summary>
/// Creates a value tuple equality comparer for <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> with the specified equality comparers for its components.
/// </summary>
/// <inheritdoc cref="Create{T1, T2, T3, T4}(IEqualityComparer{T1}?, IEqualityComparer{T2}?, IEqualityComparer{T3}?, IEqualityComparer{T4}?)"/>
/// <typeparam name="T1"><inheritdoc/></typeparam>
/// <typeparam name="T2"><inheritdoc/></typeparam>
/// <typeparam name="T3"><inheritdoc/></typeparam>
/// <typeparam name="T4"><inheritdoc/></typeparam>
/// <typeparam name="T5">The type of the value tuple's fifth component.</typeparam>
/// <param name="comparer1"><inheritdoc/></param>
/// <param name="comparer2"><inheritdoc/></param>
/// <param name="comparer3"><inheritdoc/></param>
/// <param name="comparer4"><inheritdoc/></param>
/// <param name="comparer5">
/// The <see cref="IEqualityComparer{T}"/> to use when comparing the value tuple's fifth component,
/// or <see langword="null"/> to use the default equality comparer for <typeparamref name="T5"/> type.
/// </param>
public static IEqualityComparer<(T1, T2, T3, T4, T5)> Create<T1, T2, T3, T4, T5>(
IEqualityComparer<T1>? comparer1,
IEqualityComparer<T2>? comparer2,
IEqualityComparer<T3>? comparer3,
IEqualityComparer<T4>? comparer4,
IEqualityComparer<T5>? comparer5) =>
comparer1 is null && comparer2 is null && comparer3 is null && comparer4 is null && comparer5 is null
? EqualityComparer<(T1, T2, T3, T4, T5)>.Default
: new ValueTupleEqualityComparer<T1, T2, T3, T4, T5>(comparer1, comparer2, comparer3, comparer4, comparer5);
/// <summary>
/// Creates a value tuple equality comparer for <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> with the specified equality comparers for its components.
/// </summary>
/// <inheritdoc cref="Create{T1, T2, T3, T4, T5}(IEqualityComparer{T1}?, IEqualityComparer{T2}?, IEqualityComparer{T3}?, IEqualityComparer{T4}?, IEqualityComparer{T5}?)"/>
/// <typeparam name="T1"><inheritdoc/></typeparam>
/// <typeparam name="T2"><inheritdoc/></typeparam>
/// <typeparam name="T3"><inheritdoc/></typeparam>
/// <typeparam name="T4"><inheritdoc/></typeparam>
/// <typeparam name="T5"><inheritdoc/></typeparam>
/// <typeparam name="T6">The type of the value tuple's sixth component.</typeparam>
/// <param name="comparer1"><inheritdoc/></param>
/// <param name="comparer2"><inheritdoc/></param>
/// <param name="comparer3"><inheritdoc/></param>
/// <param name="comparer4"><inheritdoc/></param>
/// <param name="comparer5"><inheritdoc/></param>
/// <param name="comparer6">
/// The <see cref="IEqualityComparer{T}"/> to use when comparing the value tuple's sixth component,
/// or <see langword="null"/> to use the default equality comparer for <typeparamref name="T6"/> type.
/// </param>
public static IEqualityComparer<(T1, T2, T3, T4, T5, T6)> Create<T1, T2, T3, T4, T5, T6>(
IEqualityComparer<T1>? comparer1,
IEqualityComparer<T2>? comparer2,
IEqualityComparer<T3>? comparer3,
IEqualityComparer<T4>? comparer4,
IEqualityComparer<T5>? comparer5,
IEqualityComparer<T6>? comparer6) =>
comparer1 is null && comparer2 is null && comparer3 is null && comparer4 is null && comparer5 is null && comparer6 is null
? EqualityComparer<(T1, T2, T3, T4, T5, T6)>.Default
: new ValueTupleEqualityComparer<T1, T2, T3, T4, T5, T6>(comparer1, comparer2, comparer3, comparer4, comparer5, comparer6);
/// <summary>
/// Creates a value tuple equality comparer for <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> with the specified equality comparers for its components.
/// </summary>
/// <inheritdoc cref="Create{T1, T2, T3, T4, T5, T6}(IEqualityComparer{T1}?, IEqualityComparer{T2}?, IEqualityComparer{T3}?, IEqualityComparer{T4}?, IEqualityComparer{T5}?, IEqualityComparer{T6}?)"/>
/// <typeparam name="T1"><inheritdoc/></typeparam>
/// <typeparam name="T2"><inheritdoc/></typeparam>
/// <typeparam name="T3"><inheritdoc/></typeparam>
/// <typeparam name="T4"><inheritdoc/></typeparam>
/// <typeparam name="T5"><inheritdoc/></typeparam>
/// <typeparam name="T6"><inheritdoc/></typeparam>
/// <typeparam name="T7">The type of the value tuple's seventh component.</typeparam>
/// <param name="comparer1"><inheritdoc/></param>
/// <param name="comparer2"><inheritdoc/></param>
/// <param name="comparer3"><inheritdoc/></param>
/// <param name="comparer4"><inheritdoc/></param>
/// <param name="comparer5"><inheritdoc/></param>
/// <param name="comparer6"><inheritdoc/></param>
/// <param name="comparer7">
/// The <see cref="IEqualityComparer{T}"/> to use when comparing the value tuple's seventh component,
/// or <see langword="null"/> to use the default equality comparer for <typeparamref name="T7"/> type.
/// </param>
public static IEqualityComparer<(T1, T2, T3, T4, T5, T6, T7)> Create<T1, T2, T3, T4, T5, T6, T7>(
IEqualityComparer<T1>? comparer1,
IEqualityComparer<T2>? comparer2,
IEqualityComparer<T3>? comparer3,
IEqualityComparer<T4>? comparer4,
IEqualityComparer<T5>? comparer5,
IEqualityComparer<T6>? comparer6,
IEqualityComparer<T7>? comparer7) =>
comparer1 is null && comparer2 is null && comparer3 is null && comparer4 is null && comparer5 is null && comparer6 is null && comparer7 is null
? EqualityComparer<(T1, T2, T3, T4, T5, T6, T7)>.Default
: new ValueTupleEqualityComparer<T1, T2, T3, T4, T5, T6, T7>(comparer1, comparer2, comparer3, comparer4, comparer5, comparer6, comparer7);
/// <summary>
/// Creates an equality comparer for value tuple with eight components with specified equality comparers for the components.
/// </summary>
/// <inheritdoc cref="Create{T1, T2, T3, T4, T5, T6, T7}(IEqualityComparer{T1}?, IEqualityComparer{T2}?, IEqualityComparer{T3}?, IEqualityComparer{T4}?, IEqualityComparer{T5}?, IEqualityComparer{T6}?, IEqualityComparer{T7}?)"/>
/// <typeparam name="T1"><inheritdoc/></typeparam>
/// <typeparam name="T2"><inheritdoc/></typeparam>
/// <typeparam name="T3"><inheritdoc/></typeparam>
/// <typeparam name="T4"><inheritdoc/></typeparam>
/// <typeparam name="T5"><inheritdoc/></typeparam>
/// <typeparam name="T6"><inheritdoc/></typeparam>
/// <typeparam name="T7"><inheritdoc/></typeparam>
/// <typeparam name="T8">The type of the value tuple's eighth component.</typeparam>
/// <param name="comparer1"><inheritdoc/></param>
/// <param name="comparer2"><inheritdoc/></param>
/// <param name="comparer3"><inheritdoc/></param>
/// <param name="comparer4"><inheritdoc/></param>
/// <param name="comparer5"><inheritdoc/></param>
/// <param name="comparer6"><inheritdoc/></param>
/// <param name="comparer7"><inheritdoc/></param>
/// <param name="comparer8">
/// The <see cref="IEqualityComparer{T}"/> to use when comparing the value tuple's eighth component,
/// or <see langword="null"/> to use the default equality comparer for <typeparamref name="T8"/> type.
/// </param>
public static IEqualityComparer<(T1, T2, T3, T4, T5, T6, T7, T8)> Create<T1, T2, T3, T4, T5, T6, T7, T8>(
IEqualityComparer<T1>? comparer1,
IEqualityComparer<T2>? comparer2,
IEqualityComparer<T3>? comparer3,
IEqualityComparer<T4>? comparer4,
IEqualityComparer<T5>? comparer5,
IEqualityComparer<T6>? comparer6,
IEqualityComparer<T7>? comparer7,
IEqualityComparer<T8>? comparer8) =>
comparer1 is null && comparer2 is null && comparer3 is null && comparer4 is null && comparer5 is null && comparer6 is null && comparer7 is null && comparer8 is null
? EqualityComparer<(T1, T2, T3, T4, T5, T6, T7, T8)>.Default
: new ValueTupleEqualityComparer<T1, T2, T3, T4, T5, T6, T7, T8>(comparer1, comparer2, comparer3, comparer4, comparer5, comparer6, comparer7, comparer8);
}