Mercurial > pub > bltoolkit
comparison Source/Common/Compatibility4.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 namespace System | |
2 { | |
3 using Collections; | |
4 using Collections.Generic; | |
5 using Text; | |
6 | |
7 public delegate void Action<T1,T2,T3,T4,T5> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); | |
8 public delegate void Action<T1,T2,T3,T4,T5,T6> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); | |
9 public delegate void Action<T1,T2,T3,T4,T5,T6,T7> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); | |
10 public delegate void Action<T1,T2,T3,T4,T5,T6,T7,T8> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); | |
11 public delegate void Action<T1,T2,T3,T4,T5,T6,T7,T8,T9> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); | |
12 public delegate void Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); | |
13 public delegate void Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11); | |
14 public delegate void Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12); | |
15 public delegate void Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13); | |
16 public delegate void Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14); | |
17 public delegate void Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15); | |
18 public delegate void Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); | |
19 | |
20 public delegate TResult Func<T1,T2,T3,T4,T5,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); | |
21 public delegate TResult Func<T1,T2,T3,T4,T5,T6,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); | |
22 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); | |
23 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,T8,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); | |
24 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); | |
25 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); | |
26 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11); | |
27 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12); | |
28 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13); | |
29 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14); | |
30 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,TResult> (T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15); | |
31 public delegate TResult Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); | |
32 | |
33 #region Tuple | |
34 | |
35 interface ITuple | |
36 { | |
37 int GetHashCode(IEqualityComparer comparer); | |
38 string ToString (StringBuilder sb); | |
39 | |
40 int Size { get; } | |
41 } | |
42 | |
43 public static class Tuple | |
44 { | |
45 internal static int CombineHashCodes(int h1, int h2) { return (((h1 << 5) + h1) ^ h2); } | |
46 internal static int CombineHashCodes(int h1, int h2, int h3) { return CombineHashCodes(CombineHashCodes(h1, h2), h3); } | |
47 internal static int CombineHashCodes(int h1, int h2, int h3, int h4) { return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4)); } | |
48 internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5) { return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5); } | |
49 internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6) { return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6)); } | |
50 internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7) { return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7)); } | |
51 internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7, int h8) { return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7, h8)); } | |
52 | |
53 public static Tuple<T1> Create<T1> (T1 item1) { return new Tuple<T1> (item1); } | |
54 public static Tuple<T1,T2> Create<T1,T2> (T1 item1, T2 item2) { return new Tuple<T1,T2> (item1, item2); } | |
55 public static Tuple<T1,T2,T3> Create<T1,T2,T3>(T1 item1, T2 item2, T3 item3) { return new Tuple<T1,T2,T3>(item1, item2, item3); } | |
56 | |
57 public static Tuple<T1,T2,T3,T4> Create<T1,T2,T3,T4>(T1 item1, T2 item2, T3 item3, T4 item4) | |
58 { | |
59 return new Tuple<T1,T2,T3,T4>(item1, item2, item3, item4); | |
60 } | |
61 | |
62 public static Tuple<T1,T2,T3,T4,T5> Create<T1,T2,T3,T4,T5>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) | |
63 { | |
64 return new Tuple<T1,T2,T3,T4,T5>(item1, item2, item3, item4, item5); | |
65 } | |
66 | |
67 public static Tuple<T1,T2,T3,T4,T5,T6> Create<T1,T2,T3,T4,T5,T6>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) | |
68 { | |
69 return new Tuple<T1,T2,T3,T4,T5,T6>(item1, item2, item3, item4, item5, item6); | |
70 } | |
71 | |
72 public static Tuple<T1,T2,T3,T4,T5,T6,T7> Create<T1,T2,T3,T4,T5,T6,T7>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) | |
73 { | |
74 return new Tuple<T1,T2,T3,T4,T5,T6,T7>(item1, item2, item3, item4, item5, item6, item7); | |
75 } | |
76 | |
77 public static Tuple<T1,T2,T3,T4,T5,T6,T7,Tuple<T8>> Create<T1,T2,T3,T4,T5,T6,T7,T8>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) | |
78 { | |
79 return new Tuple<T1,T2,T3,T4,T5,T6,T7,Tuple<T8>>(item1, item2, item3, item4, item5, item6, item7, new Tuple<T8>(item8)); | |
80 } | |
81 } | |
82 | |
83 [Serializable] | |
84 public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple | |
85 { | |
86 readonly T1 _item1; | |
87 | |
88 public Tuple(T1 item1) | |
89 { | |
90 _item1 = item1; | |
91 } | |
92 | |
93 public override bool Equals(object obj) | |
94 { | |
95 return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default); | |
96 } | |
97 | |
98 public override int GetHashCode() | |
99 { | |
100 return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default); | |
101 } | |
102 | |
103 int IStructuralComparable.CompareTo(object other, IComparer comparer) | |
104 { | |
105 if (other == null) | |
106 return 1; | |
107 | |
108 var tuple = other as Tuple<T1>; | |
109 | |
110 if (tuple == null) | |
111 throw new ArgumentException(string.Format("Type '{0}' is not a tuple", other.GetType()), "other"); | |
112 | |
113 return comparer.Compare(_item1, tuple._item1); | |
114 } | |
115 | |
116 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) | |
117 { | |
118 if (other == null) | |
119 return false; | |
120 | |
121 var tuple = other as Tuple<T1>; | |
122 | |
123 if (tuple == null) | |
124 return false; | |
125 | |
126 return comparer.Equals(_item1, tuple._item1); | |
127 } | |
128 | |
129 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) | |
130 { | |
131 return comparer.GetHashCode(_item1); | |
132 } | |
133 | |
134 int IComparable.CompareTo(object obj) | |
135 { | |
136 return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default); | |
137 } | |
138 | |
139 int ITuple.GetHashCode(IEqualityComparer comparer) | |
140 { | |
141 return ((IStructuralEquatable)this).GetHashCode(comparer); | |
142 } | |
143 | |
144 string ITuple.ToString(StringBuilder sb) | |
145 { | |
146 sb.Append(_item1).Append(")"); | |
147 return sb.ToString(); | |
148 } | |
149 | |
150 public override string ToString() | |
151 { | |
152 var sb = new StringBuilder(); | |
153 sb.Append("("); | |
154 return ((ITuple) this).ToString(sb); | |
155 } | |
156 | |
157 public T1 Item1 { get { return _item1; } } | |
158 | |
159 int ITuple.Size { get { return 2; } } | |
160 } | |
161 | |
162 [Serializable] | |
163 public class Tuple<T1,T2> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple | |
164 { | |
165 readonly T1 _item1; | |
166 readonly T2 _item2; | |
167 | |
168 public Tuple(T1 item1, T2 item2) | |
169 { | |
170 _item1 = item1; | |
171 _item2 = item2; | |
172 } | |
173 | |
174 public override bool Equals(object obj) | |
175 { | |
176 return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default); | |
177 } | |
178 | |
179 public override int GetHashCode() | |
180 { | |
181 return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default); | |
182 } | |
183 | |
184 int IStructuralComparable.CompareTo(object other, IComparer comparer) | |
185 { | |
186 if (other == null) | |
187 return 1; | |
188 | |
189 var tuple = other as Tuple<T1,T2>; | |
190 | |
191 if (tuple == null) | |
192 throw new ArgumentException(string.Format("Type '{0}' is not a tuple", other.GetType()), "other"); | |
193 | |
194 var num = comparer.Compare(_item1, tuple._item1); | |
195 if (num == 0) | |
196 return num; | |
197 return comparer.Compare(_item2, tuple._item2); | |
198 } | |
199 | |
200 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) | |
201 { | |
202 if (other == null) | |
203 return false; | |
204 | |
205 var tuple = other as Tuple<T1,T2>; | |
206 | |
207 if (tuple == null) | |
208 return false; | |
209 | |
210 return | |
211 comparer.Equals(_item1, tuple._item1) && | |
212 comparer.Equals(_item2, tuple._item2); | |
213 } | |
214 | |
215 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) | |
216 { | |
217 return Tuple.CombineHashCodes(comparer.GetHashCode(_item1), comparer.GetHashCode(_item2)); | |
218 } | |
219 | |
220 int IComparable.CompareTo(object obj) | |
221 { | |
222 return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default); | |
223 } | |
224 | |
225 int ITuple.GetHashCode(IEqualityComparer comparer) | |
226 { | |
227 return ((IStructuralEquatable)this).GetHashCode(comparer); | |
228 } | |
229 | |
230 string ITuple.ToString(StringBuilder sb) | |
231 { | |
232 sb | |
233 .Append(_item1).Append(", ") | |
234 .Append(_item2).Append(")"); | |
235 | |
236 return sb.ToString(); | |
237 } | |
238 | |
239 public override string ToString() | |
240 { | |
241 var sb = new StringBuilder(); | |
242 sb.Append("("); | |
243 return ((ITuple) this).ToString(sb); | |
244 } | |
245 | |
246 public T1 Item1 { get { return _item1; } } | |
247 public T2 Item2 { get { return _item2; } } | |
248 | |
249 int ITuple.Size { get { return 2; } } | |
250 } | |
251 | |
252 [Serializable] | |
253 public class Tuple<T1,T2,T3> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple | |
254 { | |
255 readonly T1 _item1; | |
256 readonly T2 _item2; | |
257 readonly T3 _item3; | |
258 | |
259 public Tuple(T1 item1, T2 item2, T3 item3) | |
260 { | |
261 _item1 = item1; | |
262 _item2 = item2; | |
263 _item3 = item3; | |
264 } | |
265 | |
266 public override bool Equals(object obj) | |
267 { | |
268 return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default); | |
269 } | |
270 | |
271 public override int GetHashCode() | |
272 { | |
273 return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default); | |
274 } | |
275 | |
276 int IStructuralComparable.CompareTo(object other, IComparer comparer) | |
277 { | |
278 if (other == null) | |
279 return 1; | |
280 | |
281 var tuple = other as Tuple<T1,T2,T3>; | |
282 | |
283 if (tuple == null) | |
284 throw new ArgumentException(string.Format("Type '{0}' is not a tuple", other.GetType()), "other"); | |
285 | |
286 int num; | |
287 | |
288 num = comparer.Compare(_item1, tuple._item1); if (num == 0) return num; | |
289 num = comparer.Compare(_item2, tuple._item2); if (num != 0) return num; | |
290 | |
291 return comparer.Compare(_item3, tuple._item3); | |
292 } | |
293 | |
294 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) | |
295 { | |
296 if (other == null) | |
297 return false; | |
298 | |
299 var tuple = other as Tuple<T1,T2,T3>; | |
300 | |
301 if (tuple == null) | |
302 return false; | |
303 | |
304 return | |
305 comparer.Equals(_item1, tuple._item1) && | |
306 comparer.Equals(_item2, tuple._item2) && | |
307 comparer.Equals(_item3, tuple._item3); | |
308 } | |
309 | |
310 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) | |
311 { | |
312 return | |
313 Tuple.CombineHashCodes( | |
314 comparer.GetHashCode(_item1), | |
315 comparer.GetHashCode(_item2), | |
316 comparer.GetHashCode(_item3)); | |
317 } | |
318 | |
319 int IComparable.CompareTo(object obj) | |
320 { | |
321 return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default); | |
322 } | |
323 | |
324 int ITuple.GetHashCode(IEqualityComparer comparer) | |
325 { | |
326 return ((IStructuralEquatable)this).GetHashCode(comparer); | |
327 } | |
328 | |
329 string ITuple.ToString(StringBuilder sb) | |
330 { | |
331 sb | |
332 .Append(_item1).Append(", ") | |
333 .Append(_item2).Append(", ") | |
334 .Append(_item3).Append(")"); | |
335 | |
336 return sb.ToString(); | |
337 } | |
338 | |
339 public override string ToString() | |
340 { | |
341 var sb = new StringBuilder(); | |
342 sb.Append("("); | |
343 return ((ITuple) this).ToString(sb); | |
344 } | |
345 | |
346 public T1 Item1 { get { return _item1; } } | |
347 public T2 Item2 { get { return _item2; } } | |
348 public T3 Item3 { get { return _item3; } } | |
349 | |
350 int ITuple.Size { get { return 3; } } | |
351 } | |
352 | |
353 [Serializable] | |
354 public class Tuple<T1,T2,T3,T4> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple | |
355 { | |
356 readonly T1 _item1; | |
357 readonly T2 _item2; | |
358 readonly T3 _item3; | |
359 readonly T4 _item4; | |
360 | |
361 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4) | |
362 { | |
363 _item1 = item1; | |
364 _item2 = item2; | |
365 _item3 = item3; | |
366 _item4 = item4; | |
367 } | |
368 | |
369 public override bool Equals(object obj) | |
370 { | |
371 return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default); | |
372 } | |
373 | |
374 public override int GetHashCode() | |
375 { | |
376 return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default); | |
377 } | |
378 | |
379 int IStructuralComparable.CompareTo(object other, IComparer comparer) | |
380 { | |
381 if (other == null) | |
382 return 1; | |
383 | |
384 var tuple = other as Tuple<T1,T2,T3,T4>; | |
385 | |
386 if (tuple == null) | |
387 throw new ArgumentException(string.Format("Type '{0}' is not a tuple", other.GetType()), "other"); | |
388 | |
389 int num; | |
390 | |
391 num = comparer.Compare(_item1, tuple._item1); if (num == 0) return num; | |
392 num = comparer.Compare(_item2, tuple._item2); if (num != 0) return num; | |
393 num = comparer.Compare(_item3, tuple._item3); if (num != 0) return num; | |
394 | |
395 return comparer.Compare(_item4, tuple._item4); | |
396 } | |
397 | |
398 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) | |
399 { | |
400 if (other == null) | |
401 return false; | |
402 | |
403 var tuple = other as Tuple<T1,T2,T3,T4>; | |
404 | |
405 if (tuple == null) | |
406 return false; | |
407 | |
408 return | |
409 comparer.Equals(_item1, tuple._item1) && | |
410 comparer.Equals(_item2, tuple._item2) && | |
411 comparer.Equals(_item3, tuple._item3) && | |
412 comparer.Equals(_item4, tuple._item4); | |
413 } | |
414 | |
415 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) | |
416 { | |
417 return | |
418 Tuple.CombineHashCodes( | |
419 comparer.GetHashCode(_item1), | |
420 comparer.GetHashCode(_item2), | |
421 comparer.GetHashCode(_item3), | |
422 comparer.GetHashCode(_item4)); | |
423 } | |
424 | |
425 int IComparable.CompareTo(object obj) | |
426 { | |
427 return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default); | |
428 } | |
429 | |
430 int ITuple.GetHashCode(IEqualityComparer comparer) | |
431 { | |
432 return ((IStructuralEquatable)this).GetHashCode(comparer); | |
433 } | |
434 | |
435 string ITuple.ToString(StringBuilder sb) | |
436 { | |
437 sb | |
438 .Append(_item1).Append(", ") | |
439 .Append(_item2).Append(", ") | |
440 .Append(_item3).Append(", ") | |
441 .Append(_item4).Append(")"); | |
442 | |
443 return sb.ToString(); | |
444 } | |
445 | |
446 public override string ToString() | |
447 { | |
448 var sb = new StringBuilder(); | |
449 sb.Append("("); | |
450 return ((ITuple) this).ToString(sb); | |
451 } | |
452 | |
453 public T1 Item1 { get { return _item1; } } | |
454 public T2 Item2 { get { return _item2; } } | |
455 public T3 Item3 { get { return _item3; } } | |
456 public T4 Item4 { get { return _item4; } } | |
457 | |
458 int ITuple.Size { get { return 4; } } | |
459 } | |
460 | |
461 [Serializable] | |
462 public class Tuple<T1,T2,T3,T4,T5> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple | |
463 { | |
464 readonly T1 _item1; | |
465 readonly T2 _item2; | |
466 readonly T3 _item3; | |
467 readonly T4 _item4; | |
468 readonly T5 _item5; | |
469 | |
470 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) | |
471 { | |
472 _item1 = item1; | |
473 _item2 = item2; | |
474 _item3 = item3; | |
475 _item4 = item4; | |
476 _item5 = item5; | |
477 } | |
478 | |
479 public override bool Equals(object obj) | |
480 { | |
481 return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default); | |
482 } | |
483 | |
484 public override int GetHashCode() | |
485 { | |
486 return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default); | |
487 } | |
488 | |
489 int IStructuralComparable.CompareTo(object other, IComparer comparer) | |
490 { | |
491 if (other == null) | |
492 return 1; | |
493 | |
494 var tuple = other as Tuple<T1,T2,T3,T4,T5>; | |
495 | |
496 if (tuple == null) | |
497 throw new ArgumentException(string.Format("Type '{0}' is not a tuple", other.GetType()), "other"); | |
498 | |
499 int num; | |
500 | |
501 num = comparer.Compare(_item1, tuple._item1); if (num == 0) return num; | |
502 num = comparer.Compare(_item2, tuple._item2); if (num != 0) return num; | |
503 num = comparer.Compare(_item3, tuple._item3); if (num != 0) return num; | |
504 num = comparer.Compare(_item4, tuple._item4); if (num != 0) return num; | |
505 | |
506 return comparer.Compare(_item5, tuple._item5); | |
507 } | |
508 | |
509 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) | |
510 { | |
511 if (other == null) | |
512 return false; | |
513 | |
514 var tuple = other as Tuple<T1,T2,T3,T4,T5>; | |
515 | |
516 if (tuple == null) | |
517 return false; | |
518 | |
519 return | |
520 comparer.Equals(_item1, tuple._item1) && | |
521 comparer.Equals(_item2, tuple._item2) && | |
522 comparer.Equals(_item3, tuple._item3) && | |
523 comparer.Equals(_item4, tuple._item4) && | |
524 comparer.Equals(_item5, tuple._item5); | |
525 } | |
526 | |
527 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) | |
528 { | |
529 return | |
530 Tuple.CombineHashCodes( | |
531 comparer.GetHashCode(_item1), | |
532 comparer.GetHashCode(_item2), | |
533 comparer.GetHashCode(_item3), | |
534 comparer.GetHashCode(_item4), | |
535 comparer.GetHashCode(_item5)); | |
536 } | |
537 | |
538 int IComparable.CompareTo(object obj) | |
539 { | |
540 return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default); | |
541 } | |
542 | |
543 int ITuple.GetHashCode(IEqualityComparer comparer) | |
544 { | |
545 return ((IStructuralEquatable)this).GetHashCode(comparer); | |
546 } | |
547 | |
548 string ITuple.ToString(StringBuilder sb) | |
549 { | |
550 sb | |
551 .Append(_item1).Append(", ") | |
552 .Append(_item2).Append(", ") | |
553 .Append(_item3).Append(", ") | |
554 .Append(_item4).Append(", ") | |
555 .Append(_item5).Append(")"); | |
556 | |
557 return sb.ToString(); | |
558 } | |
559 | |
560 public override string ToString() | |
561 { | |
562 var sb = new StringBuilder(); | |
563 sb.Append("("); | |
564 return ((ITuple) this).ToString(sb); | |
565 } | |
566 | |
567 public T1 Item1 { get { return _item1; } } | |
568 public T2 Item2 { get { return _item2; } } | |
569 public T3 Item3 { get { return _item3; } } | |
570 public T4 Item4 { get { return _item4; } } | |
571 public T5 Item5 { get { return _item5; } } | |
572 | |
573 int ITuple.Size { get { return 5; } } | |
574 } | |
575 | |
576 [Serializable] | |
577 public class Tuple<T1,T2,T3,T4,T5,T6> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple | |
578 { | |
579 readonly T1 _item1; | |
580 readonly T2 _item2; | |
581 readonly T3 _item3; | |
582 readonly T4 _item4; | |
583 readonly T5 _item5; | |
584 readonly T6 _item6; | |
585 | |
586 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) | |
587 { | |
588 _item1 = item1; | |
589 _item2 = item2; | |
590 _item3 = item3; | |
591 _item4 = item4; | |
592 _item5 = item5; | |
593 _item6 = item6; | |
594 } | |
595 | |
596 public override bool Equals(object obj) | |
597 { | |
598 return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default); | |
599 } | |
600 | |
601 public override int GetHashCode() | |
602 { | |
603 return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default); | |
604 } | |
605 | |
606 int IStructuralComparable.CompareTo(object other, IComparer comparer) | |
607 { | |
608 if (other == null) | |
609 return 1; | |
610 | |
611 var tuple = other as Tuple<T1,T2,T3,T4,T5,T6>; | |
612 | |
613 if (tuple == null) | |
614 throw new ArgumentException(string.Format("Type '{0}' is not a tuple", other.GetType()), "other"); | |
615 | |
616 int num; | |
617 | |
618 num = comparer.Compare(_item1, tuple._item1); if (num == 0) return num; | |
619 num = comparer.Compare(_item2, tuple._item2); if (num != 0) return num; | |
620 num = comparer.Compare(_item3, tuple._item3); if (num != 0) return num; | |
621 num = comparer.Compare(_item4, tuple._item4); if (num != 0) return num; | |
622 num = comparer.Compare(_item5, tuple._item5); if (num != 0) return num; | |
623 | |
624 return comparer.Compare(_item6, tuple._item6); | |
625 } | |
626 | |
627 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) | |
628 { | |
629 if (other == null) | |
630 return false; | |
631 | |
632 var tuple = other as Tuple<T1,T2,T3,T4,T5,T6>; | |
633 | |
634 if (tuple == null) | |
635 return false; | |
636 | |
637 return | |
638 comparer.Equals(_item1, tuple._item1) && | |
639 comparer.Equals(_item2, tuple._item2) && | |
640 comparer.Equals(_item3, tuple._item3) && | |
641 comparer.Equals(_item4, tuple._item4) && | |
642 comparer.Equals(_item5, tuple._item5) && | |
643 comparer.Equals(_item6, tuple._item6); | |
644 } | |
645 | |
646 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) | |
647 { | |
648 return | |
649 Tuple.CombineHashCodes( | |
650 comparer.GetHashCode(_item1), | |
651 comparer.GetHashCode(_item2), | |
652 comparer.GetHashCode(_item3), | |
653 comparer.GetHashCode(_item4), | |
654 comparer.GetHashCode(_item5), | |
655 comparer.GetHashCode(_item6)); | |
656 } | |
657 | |
658 int IComparable.CompareTo(object obj) | |
659 { | |
660 return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default); | |
661 } | |
662 | |
663 int ITuple.GetHashCode(IEqualityComparer comparer) | |
664 { | |
665 return ((IStructuralEquatable)this).GetHashCode(comparer); | |
666 } | |
667 | |
668 string ITuple.ToString(StringBuilder sb) | |
669 { | |
670 sb | |
671 .Append(_item1).Append(", ") | |
672 .Append(_item2).Append(", ") | |
673 .Append(_item3).Append(", ") | |
674 .Append(_item4).Append(", ") | |
675 .Append(_item5).Append(", ") | |
676 .Append(_item6).Append(")"); | |
677 | |
678 return sb.ToString(); | |
679 } | |
680 | |
681 public override string ToString() | |
682 { | |
683 var sb = new StringBuilder(); | |
684 sb.Append("("); | |
685 return ((ITuple) this).ToString(sb); | |
686 } | |
687 | |
688 public T1 Item1 { get { return _item1; } } | |
689 public T2 Item2 { get { return _item2; } } | |
690 public T3 Item3 { get { return _item3; } } | |
691 public T4 Item4 { get { return _item4; } } | |
692 public T5 Item5 { get { return _item5; } } | |
693 public T6 Item6 { get { return _item6; } } | |
694 | |
695 int ITuple.Size { get { return 6; } } | |
696 } | |
697 | |
698 [Serializable] | |
699 public class Tuple<T1,T2,T3,T4,T5,T6,T7> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple | |
700 { | |
701 readonly T1 _item1; | |
702 readonly T2 _item2; | |
703 readonly T3 _item3; | |
704 readonly T4 _item4; | |
705 readonly T5 _item5; | |
706 readonly T6 _item6; | |
707 readonly T7 _item7; | |
708 | |
709 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) | |
710 { | |
711 _item1 = item1; | |
712 _item2 = item2; | |
713 _item3 = item3; | |
714 _item4 = item4; | |
715 _item5 = item5; | |
716 _item6 = item6; | |
717 _item7 = item7; | |
718 } | |
719 | |
720 public override bool Equals(object obj) | |
721 { | |
722 return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default); | |
723 } | |
724 | |
725 public override int GetHashCode() | |
726 { | |
727 return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default); | |
728 } | |
729 | |
730 int IStructuralComparable.CompareTo(object other, IComparer comparer) | |
731 { | |
732 if (other == null) | |
733 return 1; | |
734 | |
735 var tuple = other as Tuple<T1,T2,T3,T4,T5,T6,T7>; | |
736 | |
737 if (tuple == null) | |
738 throw new ArgumentException(string.Format("Type '{0}' is not a tuple", other.GetType()), "other"); | |
739 | |
740 int num; | |
741 | |
742 num = comparer.Compare(_item1, tuple._item1); if (num == 0) return num; | |
743 num = comparer.Compare(_item2, tuple._item2); if (num != 0) return num; | |
744 num = comparer.Compare(_item3, tuple._item3); if (num != 0) return num; | |
745 num = comparer.Compare(_item4, tuple._item4); if (num != 0) return num; | |
746 num = comparer.Compare(_item5, tuple._item5); if (num != 0) return num; | |
747 num = comparer.Compare(_item6, tuple._item6); if (num != 0) return num; | |
748 | |
749 return comparer.Compare(_item7, tuple._item7); | |
750 } | |
751 | |
752 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) | |
753 { | |
754 if (other == null) | |
755 return false; | |
756 | |
757 var tuple = other as Tuple<T1,T2,T3,T4,T5,T6,T7>; | |
758 | |
759 if (tuple == null) | |
760 return false; | |
761 | |
762 return | |
763 comparer.Equals(_item1, tuple._item1) && | |
764 comparer.Equals(_item2, tuple._item2) && | |
765 comparer.Equals(_item3, tuple._item3) && | |
766 comparer.Equals(_item4, tuple._item4) && | |
767 comparer.Equals(_item5, tuple._item5) && | |
768 comparer.Equals(_item6, tuple._item6) && | |
769 comparer.Equals(_item7, tuple._item7); | |
770 } | |
771 | |
772 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) | |
773 { | |
774 return | |
775 Tuple.CombineHashCodes( | |
776 comparer.GetHashCode(_item1), | |
777 comparer.GetHashCode(_item2), | |
778 comparer.GetHashCode(_item3), | |
779 comparer.GetHashCode(_item4), | |
780 comparer.GetHashCode(_item5), | |
781 comparer.GetHashCode(_item6), | |
782 comparer.GetHashCode(_item7)); | |
783 } | |
784 | |
785 int IComparable.CompareTo(object obj) | |
786 { | |
787 return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default); | |
788 } | |
789 | |
790 int ITuple.GetHashCode(IEqualityComparer comparer) | |
791 { | |
792 return ((IStructuralEquatable)this).GetHashCode(comparer); | |
793 } | |
794 | |
795 string ITuple.ToString(StringBuilder sb) | |
796 { | |
797 sb | |
798 .Append(_item1).Append(", ") | |
799 .Append(_item2).Append(", ") | |
800 .Append(_item3).Append(", ") | |
801 .Append(_item4).Append(", ") | |
802 .Append(_item5).Append(", ") | |
803 .Append(_item6).Append(", ") | |
804 .Append(_item7).Append(")"); | |
805 | |
806 return sb.ToString(); | |
807 } | |
808 | |
809 public override string ToString() | |
810 { | |
811 var sb = new StringBuilder(); | |
812 sb.Append("("); | |
813 return ((ITuple) this).ToString(sb); | |
814 } | |
815 | |
816 public T1 Item1 { get { return _item1; } } | |
817 public T2 Item2 { get { return _item2; } } | |
818 public T3 Item3 { get { return _item3; } } | |
819 public T4 Item4 { get { return _item4; } } | |
820 public T5 Item5 { get { return _item5; } } | |
821 public T6 Item6 { get { return _item6; } } | |
822 public T7 Item7 { get { return _item7; } } | |
823 | |
824 int ITuple.Size { get { return 7; } } | |
825 } | |
826 | |
827 [Serializable] | |
828 public class Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple | |
829 { | |
830 readonly T1 _item1; | |
831 readonly T2 _item2; | |
832 readonly T3 _item3; | |
833 readonly T4 _item4; | |
834 readonly T5 _item5; | |
835 readonly T6 _item6; | |
836 readonly T7 _item7; | |
837 readonly TRest _rest; | |
838 | |
839 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest) | |
840 { | |
841 if (!(rest is ITuple)) | |
842 throw new ArgumentException("Argument 'rest' is not a tuple", "rest"); | |
843 | |
844 _item1 = item1; | |
845 _item2 = item2; | |
846 _item3 = item3; | |
847 _item4 = item4; | |
848 _item5 = item5; | |
849 _item6 = item6; | |
850 _item7 = item7; | |
851 _rest = rest; | |
852 } | |
853 | |
854 public override bool Equals(object obj) | |
855 { | |
856 return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default); | |
857 } | |
858 | |
859 public override int GetHashCode() | |
860 { | |
861 return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default); | |
862 } | |
863 | |
864 int IStructuralComparable.CompareTo(object other, IComparer comparer) | |
865 { | |
866 if (other == null) | |
867 return 1; | |
868 | |
869 var tuple = other as Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>; | |
870 | |
871 if (tuple == null) | |
872 throw new ArgumentException(string.Format("Type '{0}' is not a tuple", other.GetType()), "other"); | |
873 | |
874 int num; | |
875 | |
876 num = comparer.Compare(_item1, tuple._item1); if (num == 0) return num; | |
877 num = comparer.Compare(_item2, tuple._item2); if (num != 0) return num; | |
878 num = comparer.Compare(_item3, tuple._item3); if (num != 0) return num; | |
879 num = comparer.Compare(_item4, tuple._item4); if (num != 0) return num; | |
880 num = comparer.Compare(_item5, tuple._item5); if (num != 0) return num; | |
881 num = comparer.Compare(_item6, tuple._item6); if (num != 0) return num; | |
882 num = comparer.Compare(_item7, tuple._item7); if (num != 0) return num; | |
883 | |
884 return comparer.Compare(_rest, tuple._rest); | |
885 } | |
886 | |
887 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) | |
888 { | |
889 if (other == null) | |
890 return false; | |
891 | |
892 var tuple = other as Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>; | |
893 | |
894 if (tuple == null) | |
895 return false; | |
896 | |
897 return | |
898 comparer.Equals(_item1, tuple._item1) && | |
899 comparer.Equals(_item2, tuple._item2) && | |
900 comparer.Equals(_item3, tuple._item3) && | |
901 comparer.Equals(_item4, tuple._item4) && | |
902 comparer.Equals(_item5, tuple._item5) && | |
903 comparer.Equals(_item6, tuple._item6) && | |
904 comparer.Equals(_item7, tuple._item7) && | |
905 comparer.Equals(_rest, tuple._rest); | |
906 } | |
907 | |
908 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) | |
909 { | |
910 var rest = (ITuple)_rest; | |
911 | |
912 if (rest.Size >= 8) | |
913 return rest.GetHashCode(comparer); | |
914 | |
915 switch (8 - rest.Size) | |
916 { | |
917 case 1: return Tuple.CombineHashCodes(comparer.GetHashCode(_item7), rest.GetHashCode(comparer)); | |
918 case 2: return Tuple.CombineHashCodes(comparer.GetHashCode(_item6), comparer.GetHashCode(_item7), rest.GetHashCode(comparer)); | |
919 case 3: return Tuple.CombineHashCodes(comparer.GetHashCode(_item5), comparer.GetHashCode(_item6), comparer.GetHashCode(_item7), rest.GetHashCode(comparer)); | |
920 case 4: return Tuple.CombineHashCodes(comparer.GetHashCode(_item4), comparer.GetHashCode(_item5), comparer.GetHashCode(_item6), comparer.GetHashCode(_item7), rest.GetHashCode(comparer)); | |
921 case 5: return Tuple.CombineHashCodes(comparer.GetHashCode(_item3), comparer.GetHashCode(_item4), comparer.GetHashCode(_item5), comparer.GetHashCode(_item6), comparer.GetHashCode(_item7), rest.GetHashCode(comparer)); | |
922 case 6: return Tuple.CombineHashCodes(comparer.GetHashCode(_item2), comparer.GetHashCode(_item3), comparer.GetHashCode(_item4), comparer.GetHashCode(_item5), comparer.GetHashCode(_item6), comparer.GetHashCode(_item7), rest.GetHashCode(comparer)); | |
923 case 7: return Tuple.CombineHashCodes(comparer.GetHashCode(_item1), comparer.GetHashCode(_item2), comparer.GetHashCode(_item3), comparer.GetHashCode(_item4), comparer.GetHashCode(_item5), comparer.GetHashCode(_item6), comparer.GetHashCode(_item7), rest.GetHashCode(comparer)); | |
924 } | |
925 | |
926 return -1; | |
927 } | |
928 | |
929 int IComparable.CompareTo(object obj) | |
930 { | |
931 return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default); | |
932 } | |
933 | |
934 int ITuple.GetHashCode(IEqualityComparer comparer) | |
935 { | |
936 return ((IStructuralEquatable)this).GetHashCode(comparer); | |
937 } | |
938 | |
939 string ITuple.ToString(StringBuilder sb) | |
940 { | |
941 sb | |
942 .Append(_item1).Append(", ") | |
943 .Append(_item2).Append(", ") | |
944 .Append(_item3).Append(", ") | |
945 .Append(_item4).Append(", ") | |
946 .Append(_item5).Append(", ") | |
947 .Append(_item6).Append(", ") | |
948 .Append(_item7).Append(", "); | |
949 | |
950 return ((ITuple)_rest).ToString(sb); | |
951 } | |
952 | |
953 public override string ToString() | |
954 { | |
955 var sb = new StringBuilder(); | |
956 sb.Append("("); | |
957 return ((ITuple)this).ToString(sb); | |
958 } | |
959 | |
960 public T1 Item1 { get { return _item1; } } | |
961 public T2 Item2 { get { return _item2; } } | |
962 public T3 Item3 { get { return _item3; } } | |
963 public T4 Item4 { get { return _item4; } } | |
964 public T5 Item5 { get { return _item5; } } | |
965 public T6 Item6 { get { return _item6; } } | |
966 public T7 Item7 { get { return _item7; } } | |
967 public TRest Rest { get { return _rest; } } | |
968 | |
969 int ITuple.Size { get { return 7 + ((ITuple)_rest).Size; } } | |
970 } | |
971 | |
972 #endregion | |
973 | |
974 namespace Collections | |
975 { | |
976 public interface IStructuralEquatable | |
977 { | |
978 bool Equals (object other, IEqualityComparer comparer); | |
979 int GetHashCode(IEqualityComparer comparer); | |
980 } | |
981 | |
982 public interface IStructuralComparable | |
983 { | |
984 int CompareTo(object other, IComparer comparer); | |
985 } | |
986 } | |
987 } |