123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- public sealed class Tuple<T1, T2>
- {
- public Tuple(T1 item1, T2 item2)
- {
- this.item1 = item1;
- this.item2 = item2;
- }
- public T1 Item1
- {
- get
- {
- return this.item1;
- }
- }
- public T2 Item2
- {
- get
- {
- return this.item2;
- }
- }
- public override string ToString()
- {
- return string.Format("Tuple({0}, {1})", this.Item1, this.Item2);
- }
- public override int GetHashCode()
- {
- int num = 17;
- int num2 = num * 23;
- int num3;
- if (this.item1 == null)
- {
- num3 = 0;
- }
- else
- {
- T1 t = this.item1;
- num3 = t.GetHashCode();
- }
- num = num2 + num3;
- int num4 = num * 23;
- int num5;
- if (this.item2 == null)
- {
- num5 = 0;
- }
- else
- {
- T2 t2 = this.item2;
- num5 = t2.GetHashCode();
- }
- return num4 + num5;
- }
- public override bool Equals(object o)
- {
- if (!(o is Tuple<T1, T2>))
- {
- return false;
- }
- Tuple<T1, T2> b = (Tuple<T1, T2>)o;
- return this == b;
- }
- public bool Equals(Tuple<T1, T2> other)
- {
- return this == other;
- }
- public static bool operator ==(Tuple<T1, T2> a, Tuple<T1, T2> b)
- {
- if (object.ReferenceEquals(a, null))
- {
- return object.ReferenceEquals(b, null);
- }
- if (a.item1 == null && b.item1 != null)
- {
- return false;
- }
- if (a.item2 == null && b.item2 != null)
- {
- return false;
- }
- T1 t = a.item1;
- bool result;
- if (t.Equals(b.item1))
- {
- T2 t2 = a.item2;
- result = t2.Equals(b.item2);
- }
- else
- {
- result = false;
- }
- return result;
- }
- public static bool operator !=(Tuple<T1, T2> a, Tuple<T1, T2> b)
- {
- return !(a == b);
- }
- public void Unpack(Action<T1, T2> unpackerDelegate)
- {
- unpackerDelegate(this.Item1, this.Item2);
- }
- private readonly T1 item1;
- private readonly T2 item2;
- }
|