5 // Zoltan Varga (vargaz@gmail.com)
6 // Marek Safar (marek.safar@gmail.com)
8 // Copyright (C) 2009 Novell
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 #if MOONLIGHT || NET_4_0 || BOOTSTRAP_NET_4_0
33 using System.Collections;
34 using System.Collections.Generic;
38 public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>
40 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
52 if (!typeof (TRest).IsGenericType)
55 Type t = typeof (TRest).GetGenericTypeDefinition ();
56 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<,,,,,,,>)))
60 throw new ArgumentException ("The last element of an eight element tuple must be a Tuple.");
64 /* The rest is generated by the script at the bottom */
67 public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable
71 public Tuple (T1 item1)
80 int IComparable.CompareTo (object obj)
82 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
85 int IStructuralComparable.CompareTo (object other, IComparer comparer)
87 var t = other as Tuple<T1>;
89 if (other == null) return 1;
90 throw new ArgumentException ();
93 return comparer.Compare (item1, t.item1);
96 public override bool Equals (object obj)
98 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
101 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
103 var t = other as Tuple<T1>;
105 if (other == null) return false;
106 throw new ArgumentException ();
109 return comparer.Equals (item1, t.item1);
112 public override int GetHashCode ()
114 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
117 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
119 return comparer.GetHashCode (item1);
122 public override string ToString ()
124 return String.Format ("({0})", item1);
129 public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable
134 public Tuple (T1 item1, T2 item2)
141 get { return item1; }
145 get { return item2; }
148 int IComparable.CompareTo (object obj)
150 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
153 int IStructuralComparable.CompareTo (object other, IComparer comparer)
155 var t = other as Tuple<T1, T2>;
157 if (other == null) return 1;
158 throw new ArgumentException ();
161 int res = comparer.Compare (item1, t.item1);
162 if (res != 0) return res;
163 return comparer.Compare (item2, t.item2);
166 public override bool Equals (object obj)
168 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
171 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
173 var t = other as Tuple<T1, T2>;
175 if (other == null) return false;
176 throw new ArgumentException ();
179 return comparer.Equals (item1, t.item1) &&
180 comparer.Equals (item2, t.item2);
183 public override int GetHashCode ()
185 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
188 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
190 int h = comparer.GetHashCode (item1);
191 h = (h << 5) - h + comparer.GetHashCode (item2);
195 public override string ToString ()
197 return String.Format ("({0}, {1})", item1, item2);
202 public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable
208 public Tuple (T1 item1, T2 item2, T3 item3)
216 get { return item1; }
220 get { return item2; }
224 get { return item3; }
227 int IComparable.CompareTo (object obj)
229 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
232 int IStructuralComparable.CompareTo (object other, IComparer comparer)
234 var t = other as Tuple<T1, T2, T3>;
236 if (other == null) return 1;
237 throw new ArgumentException ();
240 int res = comparer.Compare (item1, t.item1);
241 if (res != 0) return res;
242 res = comparer.Compare (item2, t.item2);
243 if (res != 0) return res;
244 return comparer.Compare (item3, t.item3);
247 public override bool Equals (object obj)
249 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
252 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
254 var t = other as Tuple<T1, T2, T3>;
256 if (other == null) return false;
257 throw new ArgumentException ();
260 return comparer.Equals (item1, t.item1) &&
261 comparer.Equals (item2, t.item2) &&
262 comparer.Equals (item3, t.item3);
265 public override int GetHashCode ()
267 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
270 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
272 int h = comparer.GetHashCode (item1);
273 h = (h << 5) - h + comparer.GetHashCode (item2);
274 h = (h << 5) - h + comparer.GetHashCode (item3);
278 public override string ToString ()
280 return String.Format ("({0}, {1}, {2})", item1, item2, item3);
285 public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable
292 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4)
301 get { return item1; }
305 get { return item2; }
309 get { return item3; }
313 get { return item4; }
316 int IComparable.CompareTo (object obj)
318 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
321 int IStructuralComparable.CompareTo (object other, IComparer comparer)
323 var t = other as Tuple<T1, T2, T3, T4>;
325 if (other == null) return 1;
326 throw new ArgumentException ();
329 int res = comparer.Compare (item1, t.item1);
330 if (res != 0) return res;
331 res = comparer.Compare (item2, t.item2);
332 if (res != 0) return res;
333 res = comparer.Compare (item3, t.item3);
334 if (res != 0) return res;
335 return comparer.Compare (item4, t.item4);
338 public override bool Equals (object obj)
340 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
343 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
345 var t = other as Tuple<T1, T2, T3, T4>;
347 if (other == null) return false;
348 throw new ArgumentException ();
351 return comparer.Equals (item1, t.item1) &&
352 comparer.Equals (item2, t.item2) &&
353 comparer.Equals (item3, t.item3) &&
354 comparer.Equals (item4, t.item4);
357 public override int GetHashCode ()
359 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
362 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
364 int h = comparer.GetHashCode (item1);
365 h = (h << 5) - h + comparer.GetHashCode (item2);
366 h = (h << 5) - h + comparer.GetHashCode (item3);
367 h = (h << 5) - h + comparer.GetHashCode (item4);
371 public override string ToString ()
373 return String.Format ("({0}, {1}, {2}, {3})", item1, item2, item3, item4);
378 public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable
386 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
396 get { return item1; }
400 get { return item2; }
404 get { return item3; }
408 get { return item4; }
412 get { return item5; }
415 int IComparable.CompareTo (object obj)
417 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
420 int IStructuralComparable.CompareTo (object other, IComparer comparer)
422 var t = other as Tuple<T1, T2, T3, T4, T5>;
424 if (other == null) return 1;
425 throw new ArgumentException ();
428 int res = comparer.Compare (item1, t.item1);
429 if (res != 0) return res;
430 res = comparer.Compare (item2, t.item2);
431 if (res != 0) return res;
432 res = comparer.Compare (item3, t.item3);
433 if (res != 0) return res;
434 res = comparer.Compare (item4, t.item4);
435 if (res != 0) return res;
436 return comparer.Compare (item5, t.item5);
439 public override bool Equals (object obj)
441 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
444 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
446 var t = other as Tuple<T1, T2, T3, T4, T5>;
448 if (other == null) return false;
449 throw new ArgumentException ();
452 return comparer.Equals (item1, t.item1) &&
453 comparer.Equals (item2, t.item2) &&
454 comparer.Equals (item3, t.item3) &&
455 comparer.Equals (item4, t.item4) &&
456 comparer.Equals (item5, t.item5);
459 public override int GetHashCode ()
461 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
464 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
466 int h = comparer.GetHashCode (item1);
467 h = (h << 5) - h + comparer.GetHashCode (item2);
468 h = (h << 5) - h + comparer.GetHashCode (item3);
469 h = (h << 5) - h + comparer.GetHashCode (item4);
470 h = (h << 5) - h + comparer.GetHashCode (item5);
474 public override string ToString ()
476 return String.Format ("({0}, {1}, {2}, {3}, {4})", item1, item2, item3, item4, item5);
481 public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable
490 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
501 get { return item1; }
505 get { return item2; }
509 get { return item3; }
513 get { return item4; }
517 get { return item5; }
521 get { return item6; }
524 int IComparable.CompareTo (object obj)
526 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
529 int IStructuralComparable.CompareTo (object other, IComparer comparer)
531 var t = other as Tuple<T1, T2, T3, T4, T5, T6>;
533 if (other == null) return 1;
534 throw new ArgumentException ();
537 int res = comparer.Compare (item1, t.item1);
538 if (res != 0) return res;
539 res = comparer.Compare (item2, t.item2);
540 if (res != 0) return res;
541 res = comparer.Compare (item3, t.item3);
542 if (res != 0) return res;
543 res = comparer.Compare (item4, t.item4);
544 if (res != 0) return res;
545 res = comparer.Compare (item5, t.item5);
546 if (res != 0) return res;
547 return comparer.Compare (item6, t.item6);
550 public override bool Equals (object obj)
552 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
555 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
557 var t = other as Tuple<T1, T2, T3, T4, T5, T6>;
559 if (other == null) return false;
560 throw new ArgumentException ();
563 return comparer.Equals (item1, t.item1) &&
564 comparer.Equals (item2, t.item2) &&
565 comparer.Equals (item3, t.item3) &&
566 comparer.Equals (item4, t.item4) &&
567 comparer.Equals (item5, t.item5) &&
568 comparer.Equals (item6, t.item6);
571 public override int GetHashCode ()
573 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
576 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
578 int h = comparer.GetHashCode (item1);
579 h = (h << 5) - h + comparer.GetHashCode (item2);
580 h = (h << 5) - h + comparer.GetHashCode (item3);
581 h = (h << 5) - h + comparer.GetHashCode (item4);
582 h = (h << 5) - h + comparer.GetHashCode (item5);
583 h = (h << 5) - h + comparer.GetHashCode (item6);
587 public override string ToString ()
589 return String.Format ("({0}, {1}, {2}, {3}, {4}, {5})", item1, item2, item3, item4, item5, item6);
594 public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable
604 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
616 get { return item1; }
620 get { return item2; }
624 get { return item3; }
628 get { return item4; }
632 get { return item5; }
636 get { return item6; }
640 get { return item7; }
643 int IComparable.CompareTo (object obj)
645 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
648 int IStructuralComparable.CompareTo (object other, IComparer comparer)
650 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
652 if (other == null) return 1;
653 throw new ArgumentException ();
656 int res = comparer.Compare (item1, t.item1);
657 if (res != 0) return res;
658 res = comparer.Compare (item2, t.item2);
659 if (res != 0) return res;
660 res = comparer.Compare (item3, t.item3);
661 if (res != 0) return res;
662 res = comparer.Compare (item4, t.item4);
663 if (res != 0) return res;
664 res = comparer.Compare (item5, t.item5);
665 if (res != 0) return res;
666 res = comparer.Compare (item6, t.item6);
667 if (res != 0) return res;
668 return comparer.Compare (item7, t.item7);
671 public override bool Equals (object obj)
673 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
676 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
678 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
680 if (other == null) return false;
681 throw new ArgumentException ();
684 return comparer.Equals (item1, t.item1) &&
685 comparer.Equals (item2, t.item2) &&
686 comparer.Equals (item3, t.item3) &&
687 comparer.Equals (item4, t.item4) &&
688 comparer.Equals (item5, t.item5) &&
689 comparer.Equals (item6, t.item6) &&
690 comparer.Equals (item7, t.item7);
693 public override int GetHashCode ()
695 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
698 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
700 int h = comparer.GetHashCode (item1);
701 h = (h << 5) - h + comparer.GetHashCode (item2);
702 h = (h << 5) - h + comparer.GetHashCode (item3);
703 h = (h << 5) - h + comparer.GetHashCode (item4);
704 h = (h << 5) - h + comparer.GetHashCode (item5);
705 h = (h << 5) - h + comparer.GetHashCode (item6);
706 h = (h << 5) - h + comparer.GetHashCode (item7);
710 public override string ToString ()
712 return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6})", item1, item2, item3, item4, item5, item6, item7);
717 public partial class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable
729 get { return item1; }
733 get { return item2; }
737 get { return item3; }
741 get { return item4; }
745 get { return item5; }
749 get { return item6; }
753 get { return item7; }
760 int IComparable.CompareTo (object obj)
762 return ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);
765 int IStructuralComparable.CompareTo (object other, IComparer comparer)
767 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>;
769 if (other == null) return 1;
770 throw new ArgumentException ();
773 int res = comparer.Compare (item1, t.item1);
774 if (res != 0) return res;
775 res = comparer.Compare (item2, t.item2);
776 if (res != 0) return res;
777 res = comparer.Compare (item3, t.item3);
778 if (res != 0) return res;
779 res = comparer.Compare (item4, t.item4);
780 if (res != 0) return res;
781 res = comparer.Compare (item5, t.item5);
782 if (res != 0) return res;
783 res = comparer.Compare (item6, t.item6);
784 if (res != 0) return res;
785 res = comparer.Compare (item7, t.item7);
786 if (res != 0) return res;
787 return comparer.Compare (rest, t.rest);
790 public override bool Equals (object obj)
792 return ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);
795 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)
797 var t = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>;
799 if (other == null) return false;
800 throw new ArgumentException ();
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 comparer.Equals (rest, t.rest);
813 public override int GetHashCode ()
815 return ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);
818 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer)
820 int h = comparer.GetHashCode (item1);
821 h = (h << 5) - h + comparer.GetHashCode (item2);
822 h = (h << 5) - h + comparer.GetHashCode (item3);
823 h = (h << 5) - h + comparer.GetHashCode (item4);
824 h = (h << 5) - h + comparer.GetHashCode (item5);
825 h = (h << 5) - h + comparer.GetHashCode (item6);
826 h = (h << 5) - h + comparer.GetHashCode (item7);
827 h = (h << 5) - h + comparer.GetHashCode (rest);
831 public override string ToString ()
833 return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7})", item1, item2, item3, item4, item5, item6, item7, rest);
850 public class TupleGen
852 public static void Main () {
853 for (int arity = 1; arity < 9; ++arity) {
854 string type_name = GetTypeName (arity);
856 Console.WriteLine ("\t[Serializable]");
857 Console.Write ("\tpublic {0}class ", arity < 8 ? null : "partial ");
858 Console.Write (type_name);
859 Console.WriteLine (" : IStructuralEquatable, IStructuralComparable, IComparable");
860 Console.WriteLine ("\t{");
861 for (int i = 1; i <= arity; ++i)
862 Console.WriteLine ("\t\t{0} {1};", GetItemTypeName (i), GetItemName (i));
865 Console.WriteLine ();
866 Console.Write ("\t\tpublic Tuple (");
867 for (int i = 1; i <= arity; ++i) {
868 Console.Write ("{0} {1}", GetItemTypeName (i), GetItemName (i));
870 Console.Write (", ");
872 Console.WriteLine (")");
873 Console.WriteLine ("\t\t{");
874 for (int i = 1; i <= arity; ++i)
875 Console.WriteLine ("\t\t\t this.{0} = {0};", GetItemName (i));
876 Console.WriteLine ("\t\t}");
879 for (int i = 1; i <= arity; ++i) {
880 Console.WriteLine ();
881 Console.WriteLine ("\t\tpublic {0} {1} {{", GetItemTypeName (i),
882 System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase (GetItemName (i)));
883 Console.Write ("\t\t\tget { ");
884 Console.WriteLine ("return {0}; }}", GetItemName (i));
885 Console.WriteLine ("\t\t}");
888 Console.WriteLine ();
889 Console.WriteLine ("\t\tint IComparable.CompareTo (object obj)");
890 Console.WriteLine ("\t\t{");
891 Console.WriteLine ("\t\t\treturn ((IStructuralComparable) this).CompareTo (obj, Comparer<object>.Default);");
892 Console.WriteLine ("\t\t}");
894 Console.WriteLine ();
895 Console.WriteLine ("\t\tint IStructuralComparable.CompareTo (object other, IComparer comparer)");
896 Console.WriteLine ("\t\t{");
897 Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
898 Console.WriteLine ("\t\t\tif (t == null) {");
899 Console.WriteLine ("\t\t\t\tif (other == null) return 1;");
900 Console.WriteLine ("\t\t\t\tthrow new ArgumentException ();");
901 Console.WriteLine ("\t\t\t}");
902 Console.WriteLine ();
904 for (int i = 1; i < arity; ++i) {
905 Console.Write ("\t\t\t");
907 Console.Write ("int ");
909 Console.WriteLine ("res = comparer.Compare ({0}, t.{0});", GetItemName (i));
910 Console.WriteLine ("\t\t\tif (res != 0) return res;");
912 Console.WriteLine ("\t\t\treturn comparer.Compare ({0}, t.{0});", GetItemName (arity));
913 Console.WriteLine ("\t\t}");
915 Console.WriteLine ();
916 Console.WriteLine ("\t\tpublic override bool Equals (object obj)");
917 Console.WriteLine ("\t\t{");
918 Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).Equals (obj, EqualityComparer<object>.Default);");
919 Console.WriteLine ("\t\t}");
921 Console.WriteLine ();
922 Console.WriteLine ("\t\tbool IStructuralEquatable.Equals (object other, IEqualityComparer comparer)");
923 Console.WriteLine ("\t\t{");
924 Console.WriteLine ("\t\t\tvar t = other as {0};", type_name);
925 Console.WriteLine ("\t\t\tif (t == null) {");
926 Console.WriteLine ("\t\t\t\tif (other == null) return false;");
927 Console.WriteLine ("\t\t\t\tthrow new ArgumentException ();");
928 Console.WriteLine ("\t\t\t}");
929 Console.WriteLine ();
930 Console.Write ("\t\t\treturn");
932 for (int i = 1; i <= arity; ++i) {
936 Console.Write ("\t\t\t\t");
938 Console.Write ("comparer.Equals ({0}, t.{0})", GetItemName (i));
940 Console.WriteLine (" &&");
942 Console.WriteLine (";");
944 Console.WriteLine ("\t\t}");
946 Console.WriteLine ();
947 Console.WriteLine ("\t\tpublic override int GetHashCode ()");
948 Console.WriteLine ("\t\t{");
949 Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).GetHashCode (EqualityComparer<object>.Default);");
950 Console.WriteLine ("\t\t}");
952 Console.WriteLine ();
953 Console.WriteLine ("\t\tint IStructuralEquatable.GetHashCode (IEqualityComparer comparer)");
954 Console.WriteLine ("\t\t{");
956 Console.WriteLine ("\t\t\treturn comparer.GetHashCode ({0});", GetItemName (arity));
958 Console.WriteLine ("\t\t\tint h = comparer.GetHashCode ({0});", GetItemName (1));
959 for (int i = 2; i <= arity; ++i)
960 Console.WriteLine ("\t\t\th = (h << 5) - h + comparer.GetHashCode ({0});", GetItemName (i));
961 Console.WriteLine ("\t\t\treturn h;");
964 Console.WriteLine ("\t\t}");
966 Console.WriteLine ();
967 Console.WriteLine ("\t\tpublic override string ToString ()");
968 Console.WriteLine ("\t\t{");
969 Console.Write ("\t\t\treturn String.Format (\"(");
970 for (int i = 1; i <= arity; ++i) {
971 Console.Write ("{" + (i - 1) + "}");
973 Console.Write (", ");
975 Console.Write (")\", ");
976 for (int i = 1; i <= arity; ++i) {
977 Console.Write (GetItemName (i));
979 Console.Write (", ");
981 Console.WriteLine (");");
982 Console.WriteLine ("\t\t}");
984 Console.WriteLine ("\t}\n");
988 static string GetTypeName (int arity)
990 StringBuilder sb = new StringBuilder ();
991 sb.Append ("Tuple<");
992 for (int i = 1; i <= arity; ++i) {
993 sb.Append (GetItemTypeName (i));
999 return sb.ToString ();
1002 static string GetItemName (int arity)
1004 return arity < 8 ? "item" + arity.ToString () : "rest";
1007 static string GetItemTypeName (int arity)
1009 return arity < 8 ? "T" + arity.ToString () : "TRest";