Merge remote branch 'upstream/master'
[mono.git] / mcs / class / IKVM.Reflection / Emit / Tokens.cs
1 /*
2   Copyright (C) 2008 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24
25 namespace IKVM.Reflection.Emit
26 {
27         public struct EventToken
28         {
29                 public static readonly EventToken Empty;
30                 private readonly int token;
31
32                 internal EventToken(int token)
33                 {
34                         this.token = token;
35                 }
36
37                 public int Token
38                 {
39                         get { return token; }
40                 }
41
42                 public override bool Equals(object obj)
43                 {
44                         return obj as EventToken? == this;
45                 }
46
47                 public override int GetHashCode()
48                 {
49                         return token;
50                 }
51
52                 public bool Equals(EventToken other)
53                 {
54                         return this == other;
55                 }
56
57                 public static bool operator ==(EventToken et1, EventToken et2)
58                 {
59                         return et1.token == et2.token;
60                 }
61
62                 public static bool operator !=(EventToken et1, EventToken et2)
63                 {
64                         return et1.token != et2.token;
65                 }
66         }
67
68         public struct FieldToken
69         {
70                 public static readonly FieldToken Empty;
71                 private readonly int token;
72
73                 internal FieldToken(int token)
74                 {
75                         this.token = token;
76                 }
77
78                 internal bool IsPseudoToken
79                 {
80                         get { return token < 0; }
81                 }
82
83                 public int Token
84                 {
85                         get { return token; }
86                 }
87
88                 public override bool Equals(object obj)
89                 {
90                         return obj as FieldToken? == this;
91                 }
92
93                 public override int GetHashCode()
94                 {
95                         return token;
96                 }
97
98                 public bool Equals(FieldToken other)
99                 {
100                         return this == other;
101                 }
102
103                 public static bool operator ==(FieldToken ft1, FieldToken ft2)
104                 {
105                         return ft1.token == ft2.token;
106                 }
107
108                 public static bool operator !=(FieldToken ft1, FieldToken ft2)
109                 {
110                         return ft1.token != ft2.token;
111                 }
112         }
113
114         public struct MethodToken
115         {
116                 public static readonly MethodToken Empty;
117                 private readonly int token;
118
119                 internal MethodToken(int token)
120                 {
121                         this.token = token;
122                 }
123
124                 internal bool IsPseudoToken
125                 {
126                         get { return token < 0; }
127                 }
128
129                 public int Token
130                 {
131                         get { return token; }
132                 }
133
134                 public override bool Equals(object obj)
135                 {
136                         return obj as MethodToken? == this;
137                 }
138
139                 public override int GetHashCode()
140                 {
141                         return token;
142                 }
143
144                 public bool Equals(MethodToken other)
145                 {
146                         return this == other;
147                 }
148
149                 public static bool operator ==(MethodToken mt1, MethodToken mt2)
150                 {
151                         return mt1.token == mt2.token;
152                 }
153
154                 public static bool operator !=(MethodToken mt1, MethodToken mt2)
155                 {
156                         return mt1.token != mt2.token;
157                 }
158         }
159
160         public struct SignatureToken
161         {
162                 public static readonly SignatureToken Empty;
163                 private readonly int token;
164
165                 internal SignatureToken(int token)
166                 {
167                         this.token = token;
168                 }
169
170                 public int Token
171                 {
172                         get { return token; }
173                 }
174
175                 public override bool Equals(object obj)
176                 {
177                         return obj as SignatureToken? == this;
178                 }
179
180                 public override int GetHashCode()
181                 {
182                         return token;
183                 }
184
185                 public bool Equals(SignatureToken other)
186                 {
187                         return this == other;
188                 }
189
190                 public static bool operator ==(SignatureToken st1, SignatureToken st2)
191                 {
192                         return st1.token == st2.token;
193                 }
194
195                 public static bool operator !=(SignatureToken st1, SignatureToken st2)
196                 {
197                         return st1.token != st2.token;
198                 }
199         }
200
201         public struct StringToken
202         {
203                 private readonly int token;
204
205                 internal StringToken(int token)
206                 {
207                         this.token = token;
208                 }
209
210                 public int Token
211                 {
212                         get { return token; }
213                 }
214
215                 public override bool Equals(object obj)
216                 {
217                         return obj as StringToken? == this;
218                 }
219
220                 public override int GetHashCode()
221                 {
222                         return token;
223                 }
224
225                 public bool Equals(StringToken other)
226                 {
227                         return this == other;
228                 }
229
230                 public static bool operator ==(StringToken st1, StringToken st2)
231                 {
232                         return st1.token == st2.token;
233                 }
234
235                 public static bool operator !=(StringToken st1, StringToken st2)
236                 {
237                         return st1.token != st2.token;
238                 }
239         }
240
241         public struct TypeToken
242         {
243                 public static readonly TypeToken Empty;
244                 private readonly int token;
245
246                 internal TypeToken(int token)
247                 {
248                         this.token = token;
249                 }
250
251                 public int Token
252                 {
253                         get { return token; }
254                 }
255
256                 public override bool Equals(object obj)
257                 {
258                         return obj as TypeToken? == this;
259                 }
260
261                 public override int GetHashCode()
262                 {
263                         return token;
264                 }
265
266                 public bool Equals(TypeToken other)
267                 {
268                         return this == other;
269                 }
270
271                 public static bool operator ==(TypeToken tt1, TypeToken tt2)
272                 {
273                         return tt1.token == tt2.token;
274                 }
275
276                 public static bool operator !=(TypeToken tt1, TypeToken tt2)
277                 {
278                         return tt1.token != tt2.token;
279                 }
280         }
281 }