/redistributable/openstack.net/src/corelib/Core/Compat/Tuples.cs

https://gitlab.com/rekby-archive/onlyoffice-CommunityServer · C# · 1280 lines · 808 code · 155 blank · 317 comment · 148 complexity · e05c62a0c022de4aa0edfd9bec42a740 MD5 · raw file

  1. //
  2. // Tuples.cs
  3. //
  4. // Authors:
  5. // Zoltan Varga (vargaz@gmail.com)
  6. // Marek Safar (marek.safar@gmail.com)
  7. //
  8. // Copyright (C) 2009 Novell
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET35
  30. using System;
  31. using System.Collections;
  32. using System.Collections.Generic;
  33. namespace net.openstack.Core
  34. {
  35. public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>
  36. {
  37. /// <summary>
  38. /// Initializes a new instance of the <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> class.
  39. /// </summary>
  40. /// <param name="item1">The value of the tuple's first component.</param>
  41. /// <param name="item2">The value of the tuple's second component.</param>
  42. /// <param name="item3">The value of the tuple's third component.</param>
  43. /// <param name="item4">The value of the tuple's fourth component.</param>
  44. /// <param name="item5">The value of the tuple's fifth component.</param>
  45. /// <param name="item6">The value of the tuple's sixth component.</param>
  46. /// <param name="item7">The value of the tuple's seventh component.</param>
  47. /// <param name="rest">Any generic <strong>Tuple</strong> object that contains the values of the tuple's remaining components.</param>
  48. /// <exception cref="ArgumentException"><paramref name="rest"/> is not a generic <strong>Tuple</strong> object.</exception>
  49. public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
  50. {
  51. this.item1 = item1;
  52. this.item2 = item2;
  53. this.item3 = item3;
  54. this.item4 = item4;
  55. this.item5 = item5;
  56. this.item6 = item6;
  57. this.item7 = item7;
  58. this.rest = rest;
  59. bool ok = true;
  60. if (!typeof (TRest).IsGenericType)
  61. ok = false;
  62. if (ok) {
  63. Type t = typeof (TRest).GetGenericTypeDefinition ();
  64. if (!(t == typeof (Tuple<>) || t == typeof (Tuple<,>) || t == typeof (Tuple<,,>) || t == typeof (Tuple<,,,>) || t == typeof (Tuple<,,,,>) || t == typeof (Tuple <,,,,,>) || t == typeof (Tuple<,,,,,,>) || t == typeof (Tuple<,,,,,,,>)))
  65. ok = false;
  66. }
  67. if (!ok)
  68. throw new ArgumentException ("rest", "The last element of an eight element tuple must be a Tuple.");
  69. }
  70. }
  71. /* The rest is generated by the script at the bottom */
  72. /// <summary>
  73. /// Represents a 1-tuple, or singleton.
  74. /// </summary>
  75. /// <typeparam name="T1">The type of the tuple's only component.</typeparam>
  76. [Serializable]
  77. public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable
  78. {
  79. T1 item1;
  80. /// <summary>
  81. /// Initializes a new instance of the <see cref="Tuple{T1}"/> class.
  82. /// </summary>
  83. /// <param name="item1">The value of the tuple's only component.</param>
  84. public Tuple (T1 item1)
  85. {
  86. this.item1 = item1;
  87. }
  88. /// <summary>
  89. /// Gets the value of the current <see cref="Tuple{T1}"/> object's only component.
  90. /// </summary>
  91. public T1 Item1 {
  92. get { return item1; }
  93. }
  94. /// <inheritdoc/>
  95. int IComparable.CompareTo (object obj)
  96. {
  97. return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
  98. }
  99. /// <inheritdoc/>
  100. int IStructuralComparable.CompareTo (object other, IComparer comparer)
  101. {
  102. var t = other as Tuple<T1>;
  103. if (t == null) {
  104. if (other == null) return 1;
  105. throw new ArgumentException ("other");
  106. }
  107. return comparer.Compare (item1, t.item1);
  108. }
  109. /// <inheritdoc/>
  110. public override bool Equals (object obj)
  111. {
  112. return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
  113. }
  114. /// <inheritdoc/>
  115. bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
  116. {
  117. var t = other as Tuple<T1>;
  118. if (t == null)
  119. return false;
  120. return comparer.Equals (item1, t.item1);
  121. }
  122. /// <inheritdoc/>
  123. public override int GetHashCode ()
  124. {
  125. return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
  126. }
  127. /// <inheritdoc/>
  128. int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
  129. {
  130. return comparer.GetHashCode (item1);
  131. }
  132. /// <inheritdoc/>
  133. public override string ToString ()
  134. {
  135. return String.Format ("({0})", item1);
  136. }
  137. }
  138. /// <summary>
  139. /// Represents a 2-tuple, or pair.
  140. /// </summary>
  141. /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
  142. /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
  143. [Serializable]
  144. public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable
  145. {
  146. T1 item1;
  147. T2 item2;
  148. /// <summary>
  149. /// Initializes a new instance of the <see cref="Tuple{T1, T2}"/> class.
  150. /// </summary>
  151. /// <param name="item1">The value of the tuple's first component.</param>
  152. /// <param name="item2">The value of the tuple's second component.</param>
  153. public Tuple (T1 item1, T2 item2)
  154. {
  155. this.item1 = item1;
  156. this.item2 = item2;
  157. }
  158. /// <summary>
  159. /// Gets the value of the current <see cref="Tuple{T1, T2}"/> object's first component.
  160. /// </summary>
  161. public T1 Item1 {
  162. get { return item1; }
  163. }
  164. /// <summary>
  165. /// Gets the value of the current <see cref="Tuple{T1, T2}"/> object's second component.
  166. /// </summary>
  167. public T2 Item2 {
  168. get { return item2; }
  169. }
  170. /// <inheritdoc/>
  171. int IComparable.CompareTo (object obj)
  172. {
  173. return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
  174. }
  175. /// <inheritdoc/>
  176. int IStructuralComparable.CompareTo (object other, IComparer comparer)
  177. {
  178. var t = other as Tuple<T1, T2>;
  179. if (t == null) {
  180. if (other == null) return 1;
  181. throw new ArgumentException ("other");
  182. }
  183. int res = comparer.Compare (item1, t.item1);
  184. if (res != 0) return res;
  185. return comparer.Compare (item2, t.item2);
  186. }
  187. /// <inheritdoc/>
  188. public override bool Equals (object obj)
  189. {
  190. return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
  191. }
  192. /// <inheritdoc/>
  193. bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
  194. {
  195. var t = other as Tuple<T1, T2>;
  196. if (t == null)
  197. return false;
  198. return comparer.Equals (item1, t.item1) &&
  199. comparer.Equals (item2, t.item2);
  200. }
  201. /// <inheritdoc/>
  202. public override int GetHashCode ()
  203. {
  204. return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
  205. }
  206. /// <inheritdoc/>
  207. int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
  208. {
  209. int h = comparer.GetHashCode (item1);
  210. h = (h << 5) - h + comparer.GetHashCode (item2);
  211. return h;
  212. }
  213. /// <inheritdoc/>
  214. public override string ToString ()
  215. {
  216. return String.Format ("({0}, {1})", item1, item2);
  217. }
  218. }
  219. /// <summary>
  220. /// Represents a 3-tuple, or triple.
  221. /// </summary>
  222. /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
  223. /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
  224. /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
  225. [Serializable]
  226. public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable
  227. {
  228. T1 item1;
  229. T2 item2;
  230. T3 item3;
  231. /// <summary>
  232. /// Initializes a new instance of the <see cref="Tuple{T1, T2, T3}"/> class.
  233. /// </summary>
  234. /// <param name="item1">The value of the tuple's first component.</param>
  235. /// <param name="item2">The value of the tuple's second component.</param>
  236. /// <param name="item3">The value of the tuple's third component.</param>
  237. public Tuple (T1 item1, T2 item2, T3 item3)
  238. {
  239. this.item1 = item1;
  240. this.item2 = item2;
  241. this.item3 = item3;
  242. }
  243. /// <summary>
  244. /// Gets the value of the current <see cref="Tuple{T1, T2, T3}"/> object's first component.
  245. /// </summary>
  246. public T1 Item1 {
  247. get { return item1; }
  248. }
  249. /// <summary>
  250. /// Gets the value of the current <see cref="Tuple{T1, T2, T3}"/> object's second component.
  251. /// </summary>
  252. public T2 Item2 {
  253. get { return item2; }
  254. }
  255. /// <summary>
  256. /// Gets the value of the current <see cref="Tuple{T1, T2, T3}"/> object's third component.
  257. /// </summary>
  258. public T3 Item3 {
  259. get { return item3; }
  260. }
  261. /// <inheritdoc/>
  262. int IComparable.CompareTo (object obj)
  263. {
  264. return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
  265. }
  266. /// <inheritdoc/>
  267. int IStructuralComparable.CompareTo (object other, IComparer comparer)
  268. {
  269. var t = other as Tuple<T1, T2, T3>;
  270. if (t == null) {
  271. if (other == null) return 1;
  272. throw new ArgumentException ("other");
  273. }
  274. int res = comparer.Compare (item1, t.item1);
  275. if (res != 0) return res;
  276. res = comparer.Compare (item2, t.item2);
  277. if (res != 0) return res;
  278. return comparer.Compare (item3, t.item3);
  279. }
  280. /// <inheritdoc/>
  281. public override bool Equals (object obj)
  282. {
  283. return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
  284. }
  285. /// <inheritdoc/>
  286. bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
  287. {
  288. var t = other as Tuple<T1, T2, T3>;
  289. if (t == null)
  290. return false;
  291. return comparer.Equals (item1, t.item1) &&
  292. comparer.Equals (item2, t.item2) &&
  293. comparer.Equals (item3, t.item3);
  294. }
  295. /// <inheritdoc/>
  296. public override int GetHashCode ()
  297. {
  298. return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
  299. }
  300. /// <inheritdoc/>
  301. int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
  302. {
  303. int h = comparer.GetHashCode (item1);
  304. h = (h << 5) - h + comparer.GetHashCode (item2);
  305. h = (h << 5) - h + comparer.GetHashCode (item3);
  306. return h;
  307. }
  308. /// <inheritdoc/>
  309. public override string ToString ()
  310. {
  311. return String.Format ("({0}, {1}, {2})", item1, item2, item3);
  312. }
  313. }
  314. /// <summary>
  315. /// Represents a 4-tuple, or quadruple.
  316. /// </summary>
  317. /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
  318. /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
  319. /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
  320. /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
  321. [Serializable]
  322. public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable
  323. {
  324. T1 item1;
  325. T2 item2;
  326. T3 item3;
  327. T4 item4;
  328. /// <summary>
  329. /// Initializes a new instance of the <see cref="Tuple{T1, T2, T3, T4}"/> class.
  330. /// </summary>
  331. /// <param name="item1">The value of the tuple's first component.</param>
  332. /// <param name="item2">The value of the tuple's second component.</param>
  333. /// <param name="item3">The value of the tuple's third component.</param>
  334. /// <param name="item4">The value of the tuple's fourth component.</param>
  335. public Tuple (T1 item1, T2 item2, T3 item3, T4 item4)
  336. {
  337. this.item1 = item1;
  338. this.item2 = item2;
  339. this.item3 = item3;
  340. this.item4 = item4;
  341. }
  342. /// <summary>
  343. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4}"/> object's first component.
  344. /// </summary>
  345. public T1 Item1 {
  346. get { return item1; }
  347. }
  348. /// <summary>
  349. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4}"/> object's second component.
  350. /// </summary>
  351. public T2 Item2 {
  352. get { return item2; }
  353. }
  354. /// <summary>
  355. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4}"/> object's third component.
  356. /// </summary>
  357. public T3 Item3 {
  358. get { return item3; }
  359. }
  360. /// <summary>
  361. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4}"/> object's fourth component.
  362. /// </summary>
  363. public T4 Item4 {
  364. get { return item4; }
  365. }
  366. /// <inheritdoc/>
  367. int IComparable.CompareTo (object obj)
  368. {
  369. return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
  370. }
  371. /// <inheritdoc/>
  372. int IStructuralComparable.CompareTo (object other, IComparer comparer)
  373. {
  374. var t = other as Tuple<T1, T2, T3, T4>;
  375. if (t == null) {
  376. if (other == null) return 1;
  377. throw new ArgumentException ("other");
  378. }
  379. int res = comparer.Compare (item1, t.item1);
  380. if (res != 0) return res;
  381. res = comparer.Compare (item2, t.item2);
  382. if (res != 0) return res;
  383. res = comparer.Compare (item3, t.item3);
  384. if (res != 0) return res;
  385. return comparer.Compare (item4, t.item4);
  386. }
  387. /// <inheritdoc/>
  388. public override bool Equals (object obj)
  389. {
  390. return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
  391. }
  392. /// <inheritdoc/>
  393. bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
  394. {
  395. var t = other as Tuple<T1, T2, T3, T4>;
  396. if (t == null)
  397. return false;
  398. return comparer.Equals (item1, t.item1) &&
  399. comparer.Equals (item2, t.item2) &&
  400. comparer.Equals (item3, t.item3) &&
  401. comparer.Equals (item4, t.item4);
  402. }
  403. /// <inheritdoc/>
  404. public override int GetHashCode ()
  405. {
  406. return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
  407. }
  408. /// <inheritdoc/>
  409. int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
  410. {
  411. int h = comparer.GetHashCode (item1);
  412. h = (h << 5) - h + comparer.GetHashCode (item2);
  413. h = (h << 5) - h + comparer.GetHashCode (item3);
  414. h = (h << 5) - h + comparer.GetHashCode (item4);
  415. return h;
  416. }
  417. /// <inheritdoc/>
  418. public override string ToString ()
  419. {
  420. return String.Format ("({0}, {1}, {2}, {3})", item1, item2, item3, item4);
  421. }
  422. }
  423. /// <summary>
  424. /// Represents a 5-tuple, or quintuple.
  425. /// </summary>
  426. /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
  427. /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
  428. /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
  429. /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
  430. /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
  431. [Serializable]
  432. public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable
  433. {
  434. T1 item1;
  435. T2 item2;
  436. T3 item3;
  437. T4 item4;
  438. T5 item5;
  439. /// <summary>
  440. /// Initializes a new instance of the <see cref="Tuple{T1, T2, T3, T4, T5}"/> class.
  441. /// </summary>
  442. /// <param name="item1">The value of the tuple's first component.</param>
  443. /// <param name="item2">The value of the tuple's second component.</param>
  444. /// <param name="item3">The value of the tuple's third component.</param>
  445. /// <param name="item4">The value of the tuple's fourth component.</param>
  446. /// <param name="item5">The value of the tuple's fifth component.</param>
  447. public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
  448. {
  449. this.item1 = item1;
  450. this.item2 = item2;
  451. this.item3 = item3;
  452. this.item4 = item4;
  453. this.item5 = item5;
  454. }
  455. /// <summary>
  456. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5}"/> object's first component.
  457. /// </summary>
  458. public T1 Item1 {
  459. get { return item1; }
  460. }
  461. /// <summary>
  462. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5}"/> object's second component.
  463. /// </summary>
  464. public T2 Item2 {
  465. get { return item2; }
  466. }
  467. /// <summary>
  468. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5}"/> object's third component.
  469. /// </summary>
  470. public T3 Item3 {
  471. get { return item3; }
  472. }
  473. /// <summary>
  474. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5}"/> object's fourth component.
  475. /// </summary>
  476. public T4 Item4 {
  477. get { return item4; }
  478. }
  479. /// <summary>
  480. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5}"/> object's fifth component.
  481. /// </summary>
  482. public T5 Item5 {
  483. get { return item5; }
  484. }
  485. /// <inheritdoc/>
  486. int IComparable.CompareTo (object obj)
  487. {
  488. return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
  489. }
  490. /// <inheritdoc/>
  491. int IStructuralComparable.CompareTo (object other, IComparer comparer)
  492. {
  493. var t = other as Tuple<T1, T2, T3, T4, T5>;
  494. if (t == null) {
  495. if (other == null) return 1;
  496. throw new ArgumentException ("other");
  497. }
  498. int res = comparer.Compare (item1, t.item1);
  499. if (res != 0) return res;
  500. res = comparer.Compare (item2, t.item2);
  501. if (res != 0) return res;
  502. res = comparer.Compare (item3, t.item3);
  503. if (res != 0) return res;
  504. res = comparer.Compare (item4, t.item4);
  505. if (res != 0) return res;
  506. return comparer.Compare (item5, t.item5);
  507. }
  508. /// <inheritdoc/>
  509. public override bool Equals (object obj)
  510. {
  511. return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
  512. }
  513. /// <inheritdoc/>
  514. bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
  515. {
  516. var t = other as Tuple<T1, T2, T3, T4, T5>;
  517. if (t == null)
  518. return false;
  519. return comparer.Equals (item1, t.item1) &&
  520. comparer.Equals (item2, t.item2) &&
  521. comparer.Equals (item3, t.item3) &&
  522. comparer.Equals (item4, t.item4) &&
  523. comparer.Equals (item5, t.item5);
  524. }
  525. /// <inheritdoc/>
  526. public override int GetHashCode ()
  527. {
  528. return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
  529. }
  530. /// <inheritdoc/>
  531. int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
  532. {
  533. int h = comparer.GetHashCode (item1);
  534. h = (h << 5) - h + comparer.GetHashCode (item2);
  535. h = (h << 5) - h + comparer.GetHashCode (item3);
  536. h = (h << 5) - h + comparer.GetHashCode (item4);
  537. h = (h << 5) - h + comparer.GetHashCode (item5);
  538. return h;
  539. }
  540. /// <inheritdoc/>
  541. public override string ToString ()
  542. {
  543. return String.Format ("({0}, {1}, {2}, {3}, {4})", item1, item2, item3, item4, item5);
  544. }
  545. }
  546. /// <summary>
  547. /// Represents a 6-tuple, or sextuple.
  548. /// </summary>
  549. /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
  550. /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
  551. /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
  552. /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
  553. /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
  554. /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
  555. [Serializable]
  556. public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable
  557. {
  558. T1 item1;
  559. T2 item2;
  560. T3 item3;
  561. T4 item4;
  562. T5 item5;
  563. T6 item6;
  564. /// <summary>
  565. /// Initializes a new instance of the <see cref="Tuple{T1, T2, T3, T4, T5, T6}"/> class.
  566. /// </summary>
  567. /// <param name="item1">The value of the tuple's first component.</param>
  568. /// <param name="item2">The value of the tuple's second component.</param>
  569. /// <param name="item3">The value of the tuple's third component.</param>
  570. /// <param name="item4">The value of the tuple's fourth component.</param>
  571. /// <param name="item5">The value of the tuple's fifth component.</param>
  572. /// <param name="item6">The value of the tuple's sixth component.</param>
  573. public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
  574. {
  575. this.item1 = item1;
  576. this.item2 = item2;
  577. this.item3 = item3;
  578. this.item4 = item4;
  579. this.item5 = item5;
  580. this.item6 = item6;
  581. }
  582. /// <summary>
  583. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6}"/> object's first component.
  584. /// </summary>
  585. public T1 Item1 {
  586. get { return item1; }
  587. }
  588. /// <summary>
  589. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6}"/> object's second component.
  590. /// </summary>
  591. public T2 Item2 {
  592. get { return item2; }
  593. }
  594. /// <summary>
  595. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6}"/> object's third component.
  596. /// </summary>
  597. public T3 Item3 {
  598. get { return item3; }
  599. }
  600. /// <summary>
  601. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6}"/> object's fourth component.
  602. /// </summary>
  603. public T4 Item4 {
  604. get { return item4; }
  605. }
  606. /// <summary>
  607. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6}"/> object's fifth component.
  608. /// </summary>
  609. public T5 Item5 {
  610. get { return item5; }
  611. }
  612. /// <summary>
  613. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6}"/> object's sixth component.
  614. /// </summary>
  615. public T6 Item6 {
  616. get { return item6; }
  617. }
  618. /// <inheritdoc/>
  619. int IComparable.CompareTo (object obj)
  620. {
  621. return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
  622. }
  623. /// <inheritdoc/>
  624. int IStructuralComparable.CompareTo (object other, IComparer comparer)
  625. {
  626. var t = other as Tuple<T1, T2, T3, T4, T5, T6>;
  627. if (t == null) {
  628. if (other == null) return 1;
  629. throw new ArgumentException ("other");
  630. }
  631. int res = comparer.Compare (item1, t.item1);
  632. if (res != 0) return res;
  633. res = comparer.Compare (item2, t.item2);
  634. if (res != 0) return res;
  635. res = comparer.Compare (item3, t.item3);
  636. if (res != 0) return res;
  637. res = comparer.Compare (item4, t.item4);
  638. if (res != 0) return res;
  639. res = comparer.Compare (item5, t.item5);
  640. if (res != 0) return res;
  641. return comparer.Compare (item6, t.item6);
  642. }
  643. /// <inheritdoc/>
  644. public override bool Equals (object obj)
  645. {
  646. return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
  647. }
  648. /// <inheritdoc/>
  649. bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
  650. {
  651. var t = other as Tuple<T1, T2, T3, T4, T5, T6>;
  652. if (t == null)
  653. return false;
  654. return comparer.Equals (item1, t.item1) &&
  655. comparer.Equals (item2, t.item2) &&
  656. comparer.Equals (item3, t.item3) &&
  657. comparer.Equals (item4, t.item4) &&
  658. comparer.Equals (item5, t.item5) &&
  659. comparer.Equals (item6, t.item6);
  660. }
  661. /// <inheritdoc/>
  662. public override int GetHashCode ()
  663. {
  664. return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
  665. }
  666. /// <inheritdoc/>
  667. int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
  668. {
  669. int h = comparer.GetHashCode (item1);
  670. h = (h << 5) - h + comparer.GetHashCode (item2);
  671. h = (h << 5) - h + comparer.GetHashCode (item3);
  672. h = (h << 5) - h + comparer.GetHashCode (item4);
  673. h = (h << 5) - h + comparer.GetHashCode (item5);
  674. h = (h << 5) - h + comparer.GetHashCode (item6);
  675. return h;
  676. }
  677. /// <inheritdoc/>
  678. public override string ToString ()
  679. {
  680. return String.Format ("({0}, {1}, {2}, {3}, {4}, {5})", item1, item2, item3, item4, item5, item6);
  681. }
  682. }
  683. /// <summary>
  684. /// Represents a 7-tuple, or septuple.
  685. /// </summary>
  686. /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
  687. /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
  688. /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
  689. /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
  690. /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
  691. /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
  692. /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
  693. [Serializable]
  694. public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable
  695. {
  696. T1 item1;
  697. T2 item2;
  698. T3 item3;
  699. T4 item4;
  700. T5 item5;
  701. T6 item6;
  702. T7 item7;
  703. /// <summary>
  704. /// Initializes a new instance of the <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7}"/> class.
  705. /// </summary>
  706. /// <param name="item1">The value of the tuple's first component.</param>
  707. /// <param name="item2">The value of the tuple's second component.</param>
  708. /// <param name="item3">The value of the tuple's third component.</param>
  709. /// <param name="item4">The value of the tuple's fourth component.</param>
  710. /// <param name="item5">The value of the tuple's fifth component.</param>
  711. /// <param name="item6">The value of the tuple's sixth component.</param>
  712. /// <param name="item7">The value of the tuple's seventh component.</param>
  713. public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
  714. {
  715. this.item1 = item1;
  716. this.item2 = item2;
  717. this.item3 = item3;
  718. this.item4 = item4;
  719. this.item5 = item5;
  720. this.item6 = item6;
  721. this.item7 = item7;
  722. }
  723. /// <summary>
  724. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7}"/> object's first component.
  725. /// </summary>
  726. public T1 Item1 {
  727. get { return item1; }
  728. }
  729. /// <summary>
  730. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7}"/> object's second component.
  731. /// </summary>
  732. public T2 Item2 {
  733. get { return item2; }
  734. }
  735. /// <summary>
  736. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7}"/> object's third component.
  737. /// </summary>
  738. public T3 Item3 {
  739. get { return item3; }
  740. }
  741. /// <summary>
  742. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7}"/> object's fourth component.
  743. /// </summary>
  744. public T4 Item4 {
  745. get { return item4; }
  746. }
  747. /// <summary>
  748. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7}"/> object's fifth component.
  749. /// </summary>
  750. public T5 Item5 {
  751. get { return item5; }
  752. }
  753. /// <summary>
  754. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7}"/> object's sixth component.
  755. /// </summary>
  756. public T6 Item6 {
  757. get { return item6; }
  758. }
  759. /// <summary>
  760. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7}"/> object's seventh component.
  761. /// </summary>
  762. public T7 Item7 {
  763. get { return item7; }
  764. }
  765. /// <inheritdoc/>
  766. int IComparable.CompareTo (object obj)
  767. {
  768. return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
  769. }
  770. /// <inheritdoc/>
  771. int IStructuralComparable.CompareTo (object other, IComparer comparer)
  772. {
  773. var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
  774. if (t == null) {
  775. if (other == null) return 1;
  776. throw new ArgumentException ("other");
  777. }
  778. int res = comparer.Compare (item1, t.item1);
  779. if (res != 0) return res;
  780. res = comparer.Compare (item2, t.item2);
  781. if (res != 0) return res;
  782. res = comparer.Compare (item3, t.item3);
  783. if (res != 0) return res;
  784. res = comparer.Compare (item4, t.item4);
  785. if (res != 0) return res;
  786. res = comparer.Compare (item5, t.item5);
  787. if (res != 0) return res;
  788. res = comparer.Compare (item6, t.item6);
  789. if (res != 0) return res;
  790. return comparer.Compare (item7, t.item7);
  791. }
  792. /// <inheritdoc/>
  793. public override bool Equals (object obj)
  794. {
  795. return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
  796. }
  797. /// <inheritdoc/>
  798. bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
  799. {
  800. var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
  801. if (t == null)
  802. return false;
  803. return comparer.Equals (item1, t.item1) &&
  804. comparer.Equals (item2, t.item2) &&
  805. comparer.Equals (item3, t.item3) &&
  806. comparer.Equals (item4, t.item4) &&
  807. comparer.Equals (item5, t.item5) &&
  808. comparer.Equals (item6, t.item6) &&
  809. comparer.Equals (item7, t.item7);
  810. }
  811. /// <inheritdoc/>
  812. public override int GetHashCode ()
  813. {
  814. return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
  815. }
  816. /// <inheritdoc/>
  817. int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
  818. {
  819. int h = comparer.GetHashCode (item1);
  820. h = (h << 5) - h + comparer.GetHashCode (item2);
  821. h = (h << 5) - h + comparer.GetHashCode (item3);
  822. h = (h << 5) - h + comparer.GetHashCode (item4);
  823. h = (h << 5) - h + comparer.GetHashCode (item5);
  824. h = (h << 5) - h + comparer.GetHashCode (item6);
  825. h = (h << 5) - h + comparer.GetHashCode (item7);
  826. return h;
  827. }
  828. /// <inheritdoc/>
  829. public override string ToString ()
  830. {
  831. return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6})", item1, item2, item3, item4, item5, item6, item7);
  832. }
  833. }
  834. /// <summary>
  835. /// Represents an <em>n</em>-tuple, where <em>n</em> is 8 or greater.
  836. /// </summary>
  837. /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
  838. /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
  839. /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
  840. /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
  841. /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
  842. /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
  843. /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
  844. /// <typeparam name="TRest">Any generic <strong>Tuple</strong> object that defines the types of the tuple's remaining components.</typeparam>
  845. [Serializable]
  846. public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable
  847. {
  848. T1 item1;
  849. T2 item2;
  850. T3 item3;
  851. T4 item4;
  852. T5 item5;
  853. T6 item6;
  854. T7 item7;
  855. TRest rest;
  856. /// <summary>
  857. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> object's first component.
  858. /// </summary>
  859. public T1 Item1 {
  860. get { return item1; }
  861. }
  862. /// <summary>
  863. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> object's second component.
  864. /// </summary>
  865. public T2 Item2 {
  866. get { return item2; }
  867. }
  868. /// <summary>
  869. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> object's third component.
  870. /// </summary>
  871. public T3 Item3 {
  872. get { return item3; }
  873. }
  874. /// <summary>
  875. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> object's fourth component.
  876. /// </summary>
  877. public T4 Item4 {
  878. get { return item4; }
  879. }
  880. /// <summary>
  881. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> object's fifth component.
  882. /// </summary>
  883. public T5 Item5 {
  884. get { return item5; }
  885. }
  886. /// <summary>
  887. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> object's sixth component.
  888. /// </summary>
  889. public T6 Item6 {
  890. get { return item6; }
  891. }
  892. /// <summary>
  893. /// Gets the value of the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> object's seventh component.
  894. /// </summary>
  895. public T7 Item7 {
  896. get { return item7; }
  897. }
  898. /// <summary>
  899. /// Gets the current <see cref="Tuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> object's remaining components.
  900. /// </summary>
  901. public TRest Rest {
  902. get { return rest; }
  903. }
  904. /// <inheritdoc/>
  905. int IComparable.CompareTo (object obj)
  906. {
  907. return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
  908. }
  909. /// <inheritdoc/>
  910. int IStructuralComparable.CompareTo (object other, IComparer comparer)
  911. {
  912. var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>;
  913. if (t == null) {
  914. if (other == null) return 1;
  915. throw new ArgumentException ("other");
  916. }
  917. int res = comparer.Compare (item1, t.item1);
  918. if (res != 0) return res;
  919. res = comparer.Compare (item2, t.item2);
  920. if (res != 0) return res;
  921. res = comparer.Compare (item3, t.item3);
  922. if (res != 0) return res;
  923. res = comparer.Compare (item4, t.item4);
  924. if (res != 0) return res;
  925. res = comparer.Compare (item5, t.item5);
  926. if (res != 0) return res;
  927. res = comparer.Compare (item6, t.item6);
  928. if (res != 0) return res;
  929. res = comparer.Compare (item7, t.item7);
  930. if (res != 0) return res;
  931. return comparer.Compare (rest, t.rest);
  932. }
  933. /// <inheritdoc/>
  934. public override bool Equals (object obj)
  935. {
  936. return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
  937. }
  938. /// <inheritdoc/>
  939. bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
  940. {
  941. var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>;
  942. if (t == null)
  943. return false;
  944. return comparer.Equals (item1, t.item1) &&
  945. comparer.Equals (item2, t.item2) &&
  946. comparer.Equals (item3, t.item3) &&
  947. comparer.Equals (item4, t.item4) &&
  948. comparer.Equals (item5, t.item5) &&
  949. comparer.Equals (item6, t.item6) &&
  950. comparer.Equals (item7, t.item7) &&
  951. comparer.Equals (rest, t.rest);
  952. }
  953. /// <inheritdoc/>
  954. public override int GetHashCode ()
  955. {
  956. return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
  957. }
  958. /// <inheritdoc/>
  959. int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
  960. {
  961. int h = comparer.GetHashCode (item1);
  962. h = (h << 5) - h + comparer.GetHashCode (item2);
  963. h = (h << 5) - h + comparer.GetHashCode (item3);
  964. h = (h << 5) - h + comparer.GetHashCode (item4);
  965. h = (h << 5) - h + comparer.GetHashCode (item5);
  966. h = (h << 5) - h + comparer.GetHashCode (item6);
  967. h = (h << 5) - h + comparer.GetHashCode (item7);
  968. h = (h << 5) - h + comparer.GetHashCode (rest);
  969. return h;
  970. }
  971. /// <inheritdoc/>
  972. public override string ToString ()
  973. {
  974. return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7})", item1, item2, item3, item4, item5, item6, item7, rest);
  975. }
  976. }
  977. }
  978. #endif
  979. #if FALSE
  980. //
  981. // generator script
  982. //
  983. using System;
  984. using System.Text;
  985. public class TupleGen
  986. {
  987. public static void Main () {
  988. for (int arity = 1; arity < 9; ++arity) {
  989. string type_name = GetTypeName (arity);
  990. Console.WriteLine ("\t[Serializable]");
  991. Console.Write ("\tpublic {0}class ", arity < 8 ? null : "partial ");
  992. Console.Write (type_name);
  993. Console.WriteLine (" : IStructuralEquatable, IStructuralComparable, IComparable");
  994. Console.WriteLine ("\t{");
  995. for (int i = 1; i <= arity; ++i)
  996. Console.WriteLine ("\t\t{0} {1};", GetItemTypeName (i), GetItemName (i));
  997. if (arity < 8) {
  998. Console.WriteLine ();
  999. Console.Write ("\t\tpublic Tuple (");
  1000. for (int i = 1; i <= arity; ++i) {
  1001. Console.Write ("{0} {1}", GetItemTypeName (i), GetItemName (i));
  1002. if (i < arity)
  1003. Console.Write (", ");
  1004. }
  1005. Console.WriteLine (")");
  1006. Console.WriteLine ("\t\t{");
  1007. for (int i = 1; i <= arity; ++i)
  1008. Console.WriteLine ("\t\t\t this.{0} = {0};", GetItemName (i));
  1009. Console.WriteLine ("\t\t}");
  1010. }
  1011. for (int i = 1; i <= arity; ++i) {
  1012. Console.WriteLine ();
  1013. Console.WriteLine ("\t\tpublic {0} {1} {{", GetItemTypeName (i),
  1014. System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase (GetItemName (i)));
  1015. Console.Write ("\t\t\tget { ");
  1016. Console.WriteLine ("return {0}; }}", GetItemName (i));
  1017. Console.WriteLine ("\t\t}");
  1018. }
  1019. Console.WriteLine ();
  1020. Console.WriteLine ("\t\tint IComparable.CompareTo (object obj)");
  1021. Console.WriteLine ("\t\t{");
  1022. Console.WriteLine ("\t\t\treturn ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);");
  1023. Console.WriteLine ("\t\t}");
  1024. Console.WriteLine ();
  1025. Console.WriteLine ("\t\tint IStructuralComparable.CompareTo (object other, IComparer comparer)");
  1026. Console.WriteLine ("\t\t{");
  1027. Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
  1028. Console.WriteLine ("\t\t\tif (t == null) {");
  1029. Console.WriteLine ("\t\t\t\tif (other == null) return 1;");
  1030. Console.WriteLine ("\t\t\t\tthrow new ArgumentException ("other");");
  1031. Console.WriteLine ("\t\t\t}");
  1032. Console.WriteLine ();
  1033. for (int i = 1; i < arity; ++i) {
  1034. Console.Write ("\t\t\t");
  1035. if (i == 1)
  1036. Console.Write ("int ");
  1037. Console.WriteLine ("res = comparer.Compare ({0}, t.{0});", GetItemName (i));
  1038. Console.WriteLine ("\t\t\tif (res != 0) return res;");
  1039. }
  1040. Console.WriteLine ("\t\t\treturn comparer.Compare ({0}, t.{0});", GetItemName (arity));
  1041. Console.WriteLine ("\t\t}");
  1042. Console.WriteLine ();
  1043. Console.WriteLine ("\t\tpublic override bool Equals (object obj)");
  1044. Console.WriteLine ("\t\t{");
  1045. Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);");
  1046. Console.WriteLine ("\t\t}");
  1047. Console.WriteLine ();
  1048. Console.WriteLine ("\t\tbool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)");
  1049. Console.WriteLine ("\t\t{");
  1050. Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
  1051. Console.WriteLine ("\t\t\tif (t == null)");
  1052. Console.WriteLine ("\t\t\t\treturn false;");
  1053. Console.WriteLine ();
  1054. Console.Write ("\t\t\treturn");
  1055. for (int i = 1; i <= arity; ++i) {
  1056. if (i == 1)
  1057. Console.Write (" ");
  1058. else
  1059. Console.Write ("\t\t\t\t");
  1060. Console.Write ("comparer.Equals ({0}, t.{0})", GetItemName (i));
  1061. if (i != arity)
  1062. Console.WriteLine (" &&");
  1063. else
  1064. Console.WriteLine (";");
  1065. }
  1066. Console.WriteLine ("\t\t}");
  1067. Console.WriteLine ();
  1068. Console.WriteLine ("\t\tpublic override int GetHashCode ()");
  1069. Console.WriteLine ("\t\t{");
  1070. Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);");
  1071. Console.WriteLine ("\t\t}");
  1072. Console.WriteLine ();
  1073. Console.WriteLine ("\t\tint IStructuralEquatable.GetHashCode (IEqualityComparer comparer)");
  1074. Console.WriteLine ("\t\t{");
  1075. if (arity == 1) {
  1076. Console.WriteLine ("\t\t\treturn comparer.GetHashCode ({0});", GetItemName (arity));
  1077. } else {
  1078. Console.WriteLine ("\t\t\tint h = comparer.GetHashCode ({0});", GetItemName (1));
  1079. for (int i = 2; i <= arity; ++i)
  1080. Console.WriteLine ("\t\t\th = (h << 5) - h + comparer.GetHashCode ({0});", GetItemName (i));
  1081. Console.WriteLine ("\t\t\treturn h;");
  1082. }
  1083. Console.WriteLine ("\t\t}");
  1084. Console.WriteLine ();
  1085. Console.WriteLine ("\t\tpublic override string ToString ()");
  1086. Console.WriteLine ("\t\t{");
  1087. Console.Write ("\t\t\treturn String.Format (\"(");
  1088. for (int i = 1; i <= arity; ++i) {
  1089. Console.Write ("{" + (i - 1) + "}");
  1090. if (i < arity)
  1091. Console.Write (", ");
  1092. }
  1093. Console.Write (")\", ");
  1094. for (int i = 1; i <= arity; ++i) {
  1095. Console.Write (GetItemName (i));
  1096. if (i < arity)
  1097. Console.Write (", ");
  1098. }
  1099. Console.WriteLine (");");
  1100. Console.WriteLine ("\t\t}");
  1101. Console.WriteLine ("\t}\n");
  1102. }
  1103. }
  1104. static string GetTypeName (int arity)
  1105. {
  1106. StringBuilder sb = new StringBuilder ();
  1107. sb.Append ("Tuple<");
  1108. for (int i = 1; i <= arity; ++i) {
  1109. sb.Append (GetItemTypeName (i));
  1110. if (i < arity)
  1111. sb.Append (", ");
  1112. }
  1113. sb.Append (">");
  1114. return sb.ToString ();
  1115. }
  1116. static string GetItemName (int arity)
  1117. {
  1118. return arity < 8 ? "item" + arity.ToString () : "rest";
  1119. }
  1120. static string GetItemTypeName (int arity)
  1121. {
  1122. return arity < 8 ? "T" + arity.ToString () : "TRest";
  1123. }
  1124. }
  1125. #endif