Tuple.3.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. public sealed class Tuple<T1, T2, T3>
  3. {
  4. public Tuple(T1 item1, T2 item2, T3 item3)
  5. {
  6. this.item1 = item1;
  7. this.item2 = item2;
  8. this.item3 = item3;
  9. }
  10. public T1 Item1
  11. {
  12. get
  13. {
  14. return this.item1;
  15. }
  16. }
  17. public T2 Item2
  18. {
  19. get
  20. {
  21. return this.item2;
  22. }
  23. }
  24. public T3 Item3
  25. {
  26. get
  27. {
  28. return this.item3;
  29. }
  30. }
  31. public override int GetHashCode()
  32. {
  33. int num = 17;
  34. int num2 = num * 23;
  35. int num3;
  36. if (this.item1 == null)
  37. {
  38. num3 = 0;
  39. }
  40. else
  41. {
  42. T1 t = this.item1;
  43. num3 = t.GetHashCode();
  44. }
  45. num = num2 + num3;
  46. int num4 = num * 23;
  47. int num5;
  48. if (this.item2 == null)
  49. {
  50. num5 = 0;
  51. }
  52. else
  53. {
  54. T2 t2 = this.item2;
  55. num5 = t2.GetHashCode();
  56. }
  57. num = num4 + num5;
  58. int num6 = num * 23;
  59. int num7;
  60. if (this.item3 == null)
  61. {
  62. num7 = 0;
  63. }
  64. else
  65. {
  66. T3 t3 = this.item3;
  67. num7 = t3.GetHashCode();
  68. }
  69. return num6 + num7;
  70. }
  71. public override bool Equals(object o)
  72. {
  73. if (!(o is Tuple<T1, T2, T3>))
  74. {
  75. return false;
  76. }
  77. Tuple<T1, T2, T3> b = (Tuple<T1, T2, T3>)o;
  78. return this == b;
  79. }
  80. public static bool operator ==(Tuple<T1, T2, T3> a, Tuple<T1, T2, T3> b)
  81. {
  82. if (object.ReferenceEquals(a, null))
  83. {
  84. return object.ReferenceEquals(b, null);
  85. }
  86. if (a.item1 == null && b.item1 != null)
  87. {
  88. return false;
  89. }
  90. if (a.item2 == null && b.item2 != null)
  91. {
  92. return false;
  93. }
  94. if (a.item3 == null && b.item3 != null)
  95. {
  96. return false;
  97. }
  98. T1 t = a.item1;
  99. if (t.Equals(b.item1))
  100. {
  101. T2 t2 = a.item2;
  102. if (t2.Equals(b.item2))
  103. {
  104. T3 t3 = a.item3;
  105. return t3.Equals(b.item3);
  106. }
  107. }
  108. return false;
  109. }
  110. public static bool operator !=(Tuple<T1, T2, T3> a, Tuple<T1, T2, T3> b)
  111. {
  112. return !(a == b);
  113. }
  114. public void Unpack(Action<T1, T2, T3> unpackerDelegate)
  115. {
  116. unpackerDelegate(this.Item1, this.Item2, this.Item3);
  117. }
  118. private readonly T1 item1;
  119. private readonly T2 item2;
  120. private readonly T3 item3;
  121. }