Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
using System;
2
using System.Collections.Generic;
3
using System.Collections;
4
using System.Text;
5
 
6
namespace System
7
{
8
    internal interface ITuple
9
    {
10
        // Methods
11
        int GetHashCode(IEqualityComparer comparer);
12
        string ToString(StringBuilder sb);
13
 
14
        // Properties
15
        int Size { get; }
16
    }
17
 
18
 
19
    public interface IStructuralEquatable
20
    {
21
        // Methods
22
        bool Equals(object other, IEqualityComparer comparer);
23
        int GetHashCode(IEqualityComparer comparer);
24
    }
25
 
26
    public interface IStructuralComparable
27
    {
28
        // Methods
29
        int CompareTo(object other, IComparer comparer);
30
    }
31
 
32
    public static class Tuple
33
{
34
    // Methods
35
    internal static int CombineHashCodes(int h1, int h2)
36
    {
37
        return (((h1 << 5) + h1) ^ h2);
38
    }
39
 
40
    internal static int CombineHashCodes(int h1, int h2, int h3)
41
    {
42
        return CombineHashCodes(CombineHashCodes(h1, h2), h3);
43
    }
44
 
45
    internal static int CombineHashCodes(int h1, int h2, int h3, int h4)
46
    {
47
        return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4));
48
    }
49
 
50
    internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5)
51
    {
52
        return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5);
53
    }
54
 
55
    internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6)
56
    {
57
        return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6));
58
    }
59
 
60
    internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7)
61
    {
62
        return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7));
63
    }
64
 
65
    internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7, int h8)
66
    {
67
        return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7, h8));
68
    }
69
 
70
 
71
    public static Tuple<T1, T2, T3, T4, T5, T6, T7> Create<T1, T2, T3, T4, T5, T6, T7>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
72
    {
73
        return new Tuple<T1, T2, T3, T4, T5, T6, T7>(item1, item2, item3, item4, item5, item6, item7);
74
    }
75
 
76
}
77
 
78
 
79
[Serializable]
80
public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable, ITuple
81
{
82
    // Fields
83
    private readonly T1 m_Item1;
84
    private readonly T2 m_Item2;
85
    private readonly T3 m_Item3;
86
    private readonly T4 m_Item4;
87
    private readonly T5 m_Item5;
88
    private readonly T6 m_Item6;
89
    private readonly T7 m_Item7;
90
 
91
    // Methods
92
    public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
93
    {
94
        this.m_Item1 = item1;
95
        this.m_Item2 = item2;
96
        this.m_Item3 = item3;
97
        this.m_Item4 = item4;
98
        this.m_Item5 = item5;
99
        this.m_Item6 = item6;
100
        this.m_Item7 = item7;
101
    }
102
 
103
    public override bool Equals(object obj)
104
    {
105
        return ((IStructuralEquatable) this).Equals(obj, EqualityComparer<object>.Default);
106
    }
107
 
108
    public override int GetHashCode()
109
    {
110
        return ((IStructuralEquatable) this).GetHashCode(EqualityComparer<object>.Default);
111
    }
112
 
113
    int IStructuralComparable.CompareTo(object other, IComparer comparer)
114
    {
115
        if (other == null)
116
        {
117
            return 1;
118
        }
119
        Tuple<T1, T2, T3, T4, T5, T6, T7> tuple = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
120
        if (tuple == null)
121
        {
122
            throw new ArgumentException("ArgumentException_TupleIncorrectType");
123
        }
124
        int num = 0;
125
        num = comparer.Compare(this.m_Item1, tuple.m_Item1);
126
        if (num != 0)
127
        {
128
            return num;
129
        }
130
        num = comparer.Compare(this.m_Item2, tuple.m_Item2);
131
        if (num != 0)
132
        {
133
            return num;
134
        }
135
        num = comparer.Compare(this.m_Item3, tuple.m_Item3);
136
        if (num != 0)
137
        {
138
            return num;
139
        }
140
        num = comparer.Compare(this.m_Item4, tuple.m_Item4);
141
        if (num != 0)
142
        {
143
            return num;
144
        }
145
        num = comparer.Compare(this.m_Item5, tuple.m_Item5);
146
        if (num != 0)
147
        {
148
            return num;
149
        }
150
        num = comparer.Compare(this.m_Item6, tuple.m_Item6);
151
        if (num != 0)
152
        {
153
            return num;
154
        }
155
        return comparer.Compare(this.m_Item7, tuple.m_Item7);
156
    }
157
 
158
    bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
159
    {
160
        if (other == null)
161
        {
162
            return false;
163
        }
164
        Tuple<T1, T2, T3, T4, T5, T6, T7> tuple = other as Tuple<T1, T2, T3, T4, T5, T6, T7>;
165
        if (tuple == null)
166
        {
167
            return false;
168
        }
169
        return ((((comparer.Equals(this.m_Item1, tuple.m_Item1) && comparer.Equals(this.m_Item2, tuple.m_Item2)) && (comparer.Equals(this.m_Item3, tuple.m_Item3) && comparer.Equals(this.m_Item4, tuple.m_Item4))) && (comparer.Equals(this.m_Item5, tuple.m_Item5) && comparer.Equals(this.m_Item6, tuple.m_Item6))) && comparer.Equals(this.m_Item7, tuple.m_Item7));
170
    }
171
 
172
    int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
173
    {
174
        return Tuple.CombineHashCodes(comparer.GetHashCode(this.m_Item1), comparer.GetHashCode(this.m_Item2), comparer.GetHashCode(this.m_Item3), comparer.GetHashCode(this.m_Item4), comparer.GetHashCode(this.m_Item5), comparer.GetHashCode(this.m_Item6), comparer.GetHashCode(this.m_Item7));
175
    }
176
 
177
    int IComparable.CompareTo(object obj)
178
    {
179
        return ((IStructuralComparable) this).CompareTo(obj, Comparer<object>.Default);
180
    }
181
 
182
    int ITuple.GetHashCode(IEqualityComparer comparer)
183
    {
184
        return ((IStructuralEquatable) this).GetHashCode(comparer);
185
    }
186
 
187
    string ITuple.ToString(StringBuilder sb)
188
    {
189
        sb.Append(this.m_Item1);
190
        sb.Append(", ");
191
        sb.Append(this.m_Item2);
192
        sb.Append(", ");
193
        sb.Append(this.m_Item3);
194
        sb.Append(", ");
195
        sb.Append(this.m_Item4);
196
        sb.Append(", ");
197
        sb.Append(this.m_Item5);
198
        sb.Append(", ");
199
        sb.Append(this.m_Item6);
200
        sb.Append(", ");
201
        sb.Append(this.m_Item7);
202
        sb.Append(")");
203
        return sb.ToString();
204
    }
205
 
206
    public override string ToString()
207
    {
208
        StringBuilder sb = new StringBuilder();
209
        sb.Append("(");
210
        return ((ITuple) this).ToString(sb);
211
    }
212
 
213
    // Properties
214
    public T1 Item1
215
    {
216
        get
217
        {
218
            return this.m_Item1;
219
        }
220
    }
221
 
222
    public T2 Item2
223
    {
224
        get
225
        {
226
            return this.m_Item2;
227
        }
228
    }
229
 
230
    public T3 Item3
231
    {
232
        get
233
        {
234
            return this.m_Item3;
235
        }
236
    }
237
 
238
    public T4 Item4
239
    {
240
        get
241
        {
242
            return this.m_Item4;
243
        }
244
    }
245
 
246
    public T5 Item5
247
    {
248
        get
249
        {
250
            return this.m_Item5;
251
        }
252
    }
253
 
254
    public T6 Item6
255
    {
256
        get
257
        {
258
            return this.m_Item6;
259
        }
260
    }
261
 
262
    public T7 Item7
263
    {
264
        get
265
        {
266
            return this.m_Item7;
267
        }
268
    }
269
 
270
    int ITuple.Size
271
    {
272
        get
273
        {
274
            return 7;
275
        }
276
    }
277
}
278
 
279
}