5 // Zoltan Varga (vargaz@gmail.com)
7 // Copyright (C) 2009 Novell
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
36 public class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable
47 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest) {
58 if (!typeof (TRest).IsGenericType)
61 Type t = typeof (TRest).GetGenericTypeDefinition ();
62 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<,,,,,,,>)))
66 throw new ArgumentException ("The last element of an eight element tuple must be a Tuple.");
117 int IComparable.CompareTo (object other) { throw new NotImplementedException (); }
118 int IStructuralComparable.CompareTo (object other, IComparer comparer) { throw new NotImplementedException (); }
119 bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer) { throw new NotImplementedException (); }
120 int IStructuralEquatable.GetHashCode (IEqualityComparer comparer) { throw new NotImplementedException (); }
123 public override string ToString () {
124 // FIXME: Merge the items from rest into the parent
125 return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7})", Item1, Item2, Item3, Item4, Item5, Item6, Item7, Rest);
129 /* The rest is generated by the script at the bottom */
131 public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable
135 public Tuple (T1 item1) {
143 [MonoTODO] int IComparable.CompareTo (object other) { throw new NotImplementedException (); }
144 [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) { throw new NotImplementedException (); }
145 [MonoTODO] bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer) { throw new NotImplementedException (); }
146 [MonoTODO] int IStructuralEquatable.GetHashCode (IEqualityComparer comparer) { throw new NotImplementedException (); }
147 public override string ToString () {
148 return String.Format ("({0})", Item1);
152 public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable
157 public Tuple (T1 item1, T2 item2) {
171 [MonoTODO] int IComparable.CompareTo (object other) { throw new NotImplementedException (); }
172 [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) { throw new NotImplementedException (); }
173 [MonoTODO] bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer) { throw new NotImplementedException (); }
174 [MonoTODO] int IStructuralEquatable.GetHashCode (IEqualityComparer comparer) { throw new NotImplementedException (); }
175 public override string ToString () {
176 return String.Format ("({0}, {1})", Item1, Item2);
180 public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable
186 public Tuple (T1 item1, T2 item2, T3 item3) {
206 [MonoTODO] int IComparable.CompareTo (object other) { throw new NotImplementedException (); }
207 [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) { throw new NotImplementedException (); }
208 [MonoTODO] bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer) { throw new NotImplementedException (); }
209 [MonoTODO] int IStructuralEquatable.GetHashCode (IEqualityComparer comparer) { throw new NotImplementedException (); }
210 public override string ToString () {
211 return String.Format ("({0}, {1}, {2})", Item1, Item2, Item3);
215 public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable
222 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4) {
248 [MonoTODO] int IComparable.CompareTo (object other) { throw new NotImplementedException (); }
249 [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) { throw new NotImplementedException (); }
250 [MonoTODO] bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer) { throw new NotImplementedException (); }
251 [MonoTODO] int IStructuralEquatable.GetHashCode (IEqualityComparer comparer) { throw new NotImplementedException (); }
252 public override string ToString () {
253 return String.Format ("({0}, {1}, {2}, {3})", Item1, Item2, Item3, Item4);
257 public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable
265 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) {
297 [MonoTODO] int IComparable.CompareTo (object other) { throw new NotImplementedException (); }
298 [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) { throw new NotImplementedException (); }
299 [MonoTODO] bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer) { throw new NotImplementedException (); }
300 [MonoTODO] int IStructuralEquatable.GetHashCode (IEqualityComparer comparer) { throw new NotImplementedException (); }
301 public override string ToString () {
302 return String.Format ("({0}, {1}, {2}, {3}, {4})", Item1, Item2, Item3, Item4, Item5);
306 public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable
315 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) {
353 [MonoTODO] int IComparable.CompareTo (object other) { throw new NotImplementedException (); }
354 [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) { throw new NotImplementedException (); }
355 [MonoTODO] bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer) { throw new NotImplementedException (); }
356 [MonoTODO] int IStructuralEquatable.GetHashCode (IEqualityComparer comparer) { throw new NotImplementedException (); }
357 public override string ToString () {
358 return String.Format ("({0}, {1}, {2}, {3}, {4}, {5})", Item1, Item2, Item3, Item4, Item5, Item6);
362 public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable
372 public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) {
416 [MonoTODO] int IComparable.CompareTo (object other) { throw new NotImplementedException (); }
417 [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) { throw new NotImplementedException (); }
418 [MonoTODO] bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer) { throw new NotImplementedException (); }
419 [MonoTODO] int IStructuralEquatable.GetHashCode (IEqualityComparer comparer) { throw new NotImplementedException (); }
420 public override string ToString () {
421 return String.Format ("({0}, {1}, {2}, {3}, {4}, {5}, {6})", Item1, Item2, Item3, Item4, Item5, Item6, Item7);
438 public class TupleGen
440 public static void Main () {
441 for (int arity = 1; arity < 8; ++arity) {
442 Console.Write ("\tpublic class Tuple<");
443 for (int i = 1; i <= arity; ++i) {
444 Console.Write (String.Format ("T{0}", i));
446 Console.Write (", ");
448 Console.WriteLine ("> : IStructuralEquatable, IStructuralComparable, IComparable");
449 Console.WriteLine ("\t{");
450 for (int i = 1; i <= arity; ++i)
451 Console.WriteLine (String.Format ("\t\tT{0} item{0};", i));
452 Console.WriteLine ();
453 Console.Write ("\t\tpublic Tuple (");
454 for (int i = 1; i <= arity; ++i) {
455 Console.Write (String.Format ("T{0} item{0}", i));
457 Console.Write (", ");
459 Console.WriteLine (") {");
460 for (int i = 1; i <= arity; ++i)
461 Console.WriteLine (String.Format ("\t\t\t this.item{0} = item{0};", i));
462 Console.WriteLine ("\t\t}");
464 for (int i = 1; i <= arity; ++i) {
465 Console.WriteLine (String.Format ("\t\tpublic T{0} Item{0} {{", i));
466 Console.WriteLine ("\t\t\tget {");
467 Console.WriteLine (String.Format ("\t\t\t\treturn item{0};", i));
468 Console.WriteLine ("\t\t\t}");
469 Console.WriteLine ("\t\t}");
472 Console.WriteLine ("\t\t[MonoTODO] int IComparable.CompareTo (object other) { throw new NotImplementedException (); }");
473 Console.WriteLine ("\t\t[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) { throw new NotImplementedException (); }");
474 Console.WriteLine ("\t\t[MonoTODO] bool IStructuralEquatable.Equals (object other, IEqualityComparer comparer) { throw new NotImplementedException (); }");
475 Console.WriteLine ("\t\t[MonoTODO] int IStructuralEquatable.GetHashCode (IEqualityComparer comparer) { throw new NotImplementedException (); }");
477 Console.WriteLine ("\t\tpublic override string ToString () {");
478 Console.Write ("\t\t\treturn String.Format (\"(");
479 for (int i = 1; i <= arity; ++i) {
480 Console.Write ("{" + (i - 1) + "}");
482 Console.Write (", ");
484 Console.Write (")\", ");
485 for (int i = 1; i <= arity; ++i) {
486 Console.Write ("Item" + i);
488 Console.Write (", ");
490 Console.WriteLine (");");
491 Console.WriteLine ("\t\t}");
493 Console.WriteLine ("\t}\n");