~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory/TypeSystem/KnownTypeReference.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
ļ»æ// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
 
2
// 
 
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 
4
// software and associated documentation files (the "Software"), to deal in the Software
 
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
 
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 
7
// to whom the Software is furnished to do so, subject to the following conditions:
 
8
// 
 
9
// The above copyright notice and this permission notice shall be included in all copies or
 
10
// substantial portions of the Software.
 
11
// 
 
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
17
// DEALINGS IN THE SOFTWARE.
 
18
 
 
19
using System;
 
20
 
 
21
namespace ICSharpCode.NRefactory.TypeSystem
 
22
{
 
23
        /// <summary>
 
24
        /// Represents some well-known types.
 
25
        /// </summary>
 
26
        public enum KnownTypeCode
 
27
        {
 
28
                // Note: DefaultResolvedTypeDefinition uses (KnownTypeCode)-1 as special value for "not yet calculated"
 
29
                // The order of type codes at the beginning must correspond to those in System.TypeCode.
 
30
                
 
31
                /// <summary>
 
32
                /// Not one of the known types.
 
33
                /// </summary>
 
34
                None,
 
35
                /// <summary><c>object</c> (System.Object)</summary>
 
36
                Object,
 
37
                /// <summary><c>System.DBNull</c></summary>
 
38
                DBNull,
 
39
                /// <summary><c>bool</c> (System.Boolean)</summary>
 
40
                Boolean,
 
41
                /// <summary><c>char</c> (System.Char)</summary>
 
42
                Char,
 
43
                /// <summary><c>sbyte</c> (System.SByte)</summary>
 
44
                SByte,
 
45
                /// <summary><c>byte</c> (System.Byte)</summary>
 
46
                Byte,
 
47
                /// <summary><c>short</c> (System.Int16)</summary>
 
48
                Int16,
 
49
                /// <summary><c>ushort</c> (System.UInt16)</summary>
 
50
                UInt16,
 
51
                /// <summary><c>int</c> (System.Int32)</summary>
 
52
                Int32,
 
53
                /// <summary><c>uint</c> (System.UInt32)</summary>
 
54
                UInt32,
 
55
                /// <summary><c>long</c> (System.Int64)</summary>
 
56
                Int64,
 
57
                /// <summary><c>ulong</c> (System.UInt64)</summary>
 
58
                UInt64,
 
59
                /// <summary><c>float</c> (System.Single)</summary>
 
60
                Single,
 
61
                /// <summary><c>double</c> (System.Double)</summary>
 
62
                Double,
 
63
                /// <summary><c>decimal</c> (System.Decimal)</summary>
 
64
                Decimal,
 
65
                /// <summary><c>System.DateTime</c></summary>
 
66
                DateTime,
 
67
                /// <summary><c>string</c> (System.String)</summary>
 
68
                String = 18,
 
69
                
 
70
                // String was the last element from System.TypeCode, now our additional known types start
 
71
                
 
72
                /// <summary><c>void</c> (System.Void)</summary>
 
73
                Void,
 
74
                /// <summary><c>System.Type</c></summary>
 
75
                Type,
 
76
                /// <summary><c>System.Array</c></summary>
 
77
                Array,
 
78
                /// <summary><c>System.Attribute</c></summary>
 
79
                Attribute,
 
80
                /// <summary><c>System.ValueType</c></summary>
 
81
                ValueType,
 
82
                /// <summary><c>System.Enum</c></summary>
 
83
                Enum,
 
84
                /// <summary><c>System.Delegate</c></summary>
 
85
                Delegate,
 
86
                /// <summary><c>System.MulticastDelegate</c></summary>
 
87
                MulticastDelegate,
 
88
                /// <summary><c>System.Exception</c></summary>
 
89
                Exception,
 
90
                /// <summary><c>System.IntPtr</c></summary>
 
91
                IntPtr,
 
92
                /// <summary><c>System.UIntPtr</c></summary>
 
93
                UIntPtr,
 
94
                /// <summary><c>System.Collections.IEnumerable</c></summary>
 
95
                IEnumerable,
 
96
                /// <summary><c>System.Collections.IEnumerator</c></summary>
 
97
                IEnumerator,
 
98
                /// <summary><c>System.Collections.Generic.IEnumerable{T}</c></summary>
 
99
                IEnumerableOfT,
 
100
                /// <summary><c>System.Collections.Generic.IEnumerator{T}</c></summary>
 
101
                IEnumeratorOfT,
 
102
                /// <summary><c>System.Collections.Generic.ICollection</c></summary>
 
103
                ICollection,
 
104
                /// <summary><c>System.Collections.Generic.ICollection{T}</c></summary>
 
105
                ICollectionOfT,
 
106
                /// <summary><c>System.Collections.Generic.IList</c></summary>
 
107
                IList,
 
108
                /// <summary><c>System.Collections.Generic.IList{T}</c></summary>
 
109
                IListOfT,
 
110
                /// <summary><c>System.Collections.Generic.IReadOnlyList{T}</c></summary>
 
111
                IReadOnlyListOfT,
 
112
                /// <summary><c>System.Threading.Tasks.Task</c></summary>
 
113
                Task,
 
114
                /// <summary><c>System.Threading.Tasks.Task{T}</c></summary>
 
115
                TaskOfT,
 
116
                /// <summary><c>System.Nullable{T}</c></summary>
 
117
                NullableOfT,
 
118
                /// <summary><c>System.IDisposable</c></summary>
 
119
                IDisposable,
 
120
                /// <summary><c>System.Runtime.CompilerServices.INotifyCompletion</c></summary>
 
121
                INotifyCompletion,
 
122
                /// <summary><c>System.Runtime.CompilerServices.ICriticalNotifyCompletion</c></summary>
 
123
                ICriticalNotifyCompletion,
 
124
        }
 
125
        
 
126
        /// <summary>
 
127
        /// Contains well-known type references.
 
128
        /// </summary>
 
129
        [Serializable]
 
130
        public sealed class KnownTypeReference : ITypeReference
 
131
        {
 
132
                internal const int KnownTypeCodeCount = (int)KnownTypeCode.ICriticalNotifyCompletion + 1;
 
133
                
 
134
                static readonly KnownTypeReference[] knownTypeReferences = new KnownTypeReference[KnownTypeCodeCount] {
 
135
                        null, // None
 
136
                        new KnownTypeReference(KnownTypeCode.Object,   "System", "Object", baseType: KnownTypeCode.None),
 
137
                        new KnownTypeReference(KnownTypeCode.DBNull,   "System", "DBNull"),
 
138
                        new KnownTypeReference(KnownTypeCode.Boolean,  "System", "Boolean",  baseType: KnownTypeCode.ValueType),
 
139
                        new KnownTypeReference(KnownTypeCode.Char,     "System", "Char",     baseType: KnownTypeCode.ValueType),
 
140
                        new KnownTypeReference(KnownTypeCode.SByte,    "System", "SByte",    baseType: KnownTypeCode.ValueType),
 
141
                        new KnownTypeReference(KnownTypeCode.Byte,     "System", "Byte",     baseType: KnownTypeCode.ValueType),
 
142
                        new KnownTypeReference(KnownTypeCode.Int16,    "System", "Int16",    baseType: KnownTypeCode.ValueType),
 
143
                        new KnownTypeReference(KnownTypeCode.UInt16,   "System", "UInt16",   baseType: KnownTypeCode.ValueType),
 
144
                        new KnownTypeReference(KnownTypeCode.Int32,    "System", "Int32",    baseType: KnownTypeCode.ValueType),
 
145
                        new KnownTypeReference(KnownTypeCode.UInt32,   "System", "UInt32",   baseType: KnownTypeCode.ValueType),
 
146
                        new KnownTypeReference(KnownTypeCode.Int64,    "System", "Int64",    baseType: KnownTypeCode.ValueType),
 
147
                        new KnownTypeReference(KnownTypeCode.UInt64,   "System", "UInt64",   baseType: KnownTypeCode.ValueType),
 
148
                        new KnownTypeReference(KnownTypeCode.Single,   "System", "Single",   baseType: KnownTypeCode.ValueType),
 
149
                        new KnownTypeReference(KnownTypeCode.Double,   "System", "Double",   baseType: KnownTypeCode.ValueType),
 
150
                        new KnownTypeReference(KnownTypeCode.Decimal,  "System", "Decimal",  baseType: KnownTypeCode.ValueType),
 
151
                        new KnownTypeReference(KnownTypeCode.DateTime, "System", "DateTime", baseType: KnownTypeCode.ValueType),
 
152
                        null,
 
153
                        new KnownTypeReference(KnownTypeCode.String,    "System", "String"),
 
154
                        new KnownTypeReference(KnownTypeCode.Void,      "System", "Void"),
 
155
                        new KnownTypeReference(KnownTypeCode.Type,      "System", "Type"),
 
156
                        new KnownTypeReference(KnownTypeCode.Array,     "System", "Array"),
 
157
                        new KnownTypeReference(KnownTypeCode.Attribute, "System", "Attribute"),
 
158
                        new KnownTypeReference(KnownTypeCode.ValueType, "System", "ValueType"),
 
159
                        new KnownTypeReference(KnownTypeCode.Enum,      "System", "Enum", baseType: KnownTypeCode.ValueType),
 
160
                        new KnownTypeReference(KnownTypeCode.Delegate,  "System", "Delegate"),
 
161
                        new KnownTypeReference(KnownTypeCode.MulticastDelegate, "System", "MulticastDelegate", baseType: KnownTypeCode.Delegate),
 
162
                        new KnownTypeReference(KnownTypeCode.Exception, "System", "Exception"),
 
163
                        new KnownTypeReference(KnownTypeCode.IntPtr,    "System", "IntPtr", baseType: KnownTypeCode.ValueType),
 
164
                        new KnownTypeReference(KnownTypeCode.UIntPtr,   "System", "UIntPtr", baseType: KnownTypeCode.ValueType),
 
165
                        new KnownTypeReference(KnownTypeCode.IEnumerable,    "System.Collections", "IEnumerable"),
 
166
                        new KnownTypeReference(KnownTypeCode.IEnumerator,    "System.Collections", "IEnumerator"),
 
167
                        new KnownTypeReference(KnownTypeCode.IEnumerableOfT, "System.Collections.Generic", "IEnumerable", 1),
 
168
                        new KnownTypeReference(KnownTypeCode.IEnumeratorOfT, "System.Collections.Generic", "IEnumerator", 1),
 
169
                        new KnownTypeReference(KnownTypeCode.ICollection,    "System.Collections", "ICollection"),
 
170
                        new KnownTypeReference(KnownTypeCode.ICollectionOfT, "System.Collections.Generic", "ICollection", 1),
 
171
                        new KnownTypeReference(KnownTypeCode.IList,          "System.Collections", "IList"),
 
172
                        new KnownTypeReference(KnownTypeCode.IListOfT,       "System.Collections.Generic", "IList", 1),
 
173
 
 
174
                        new KnownTypeReference(KnownTypeCode.IReadOnlyListOfT, "System.Collections.Generic", "IReadOnlyList", 1),
 
175
                        new KnownTypeReference(KnownTypeCode.Task,        "System.Threading.Tasks", "Task"),
 
176
                        new KnownTypeReference(KnownTypeCode.TaskOfT,     "System.Threading.Tasks", "Task", 1, baseType: KnownTypeCode.Task),
 
177
                        new KnownTypeReference(KnownTypeCode.NullableOfT, "System", "Nullable", 1, baseType: KnownTypeCode.ValueType),
 
178
                        new KnownTypeReference(KnownTypeCode.IDisposable, "System", "IDisposable"),
 
179
                        new KnownTypeReference(KnownTypeCode.INotifyCompletion, "System.Runtime.CompilerServices", "INotifyCompletion"),
 
180
                        new KnownTypeReference(KnownTypeCode.ICriticalNotifyCompletion, "System.Runtime.CompilerServices", "ICriticalNotifyCompletion"),
 
181
                };
 
182
                
 
183
                /// <summary>
 
184
                /// Gets the known type reference for the specified type code.
 
185
                /// Returns null for KnownTypeCode.None.
 
186
                /// </summary>
 
187
                public static KnownTypeReference Get(KnownTypeCode typeCode)
 
188
                {
 
189
                        return knownTypeReferences[(int)typeCode];
 
190
                }
 
191
                
 
192
                /// <summary>
 
193
                /// Gets a type reference pointing to the <c>object</c> type.
 
194
                /// </summary>
 
195
                public static readonly KnownTypeReference Object = Get(KnownTypeCode.Object);
 
196
                
 
197
                /// <summary>
 
198
                /// Gets a type reference pointing to the <c>System.DBNull</c> type.
 
199
                /// </summary>
 
200
                public static readonly KnownTypeReference DBNull = Get(KnownTypeCode.DBNull);
 
201
                
 
202
                /// <summary>
 
203
                /// Gets a type reference pointing to the <c>bool</c> type.
 
204
                /// </summary>
 
205
                public static readonly KnownTypeReference Boolean = Get(KnownTypeCode.Boolean);
 
206
                
 
207
                /// <summary>
 
208
                /// Gets a type reference pointing to the <c>char</c> type.
 
209
                /// </summary>
 
210
                public static readonly KnownTypeReference Char = Get(KnownTypeCode.Char);
 
211
                
 
212
                /// <summary>
 
213
                /// Gets a type reference pointing to the <c>sbyte</c> type.
 
214
                /// </summary>
 
215
                public static readonly KnownTypeReference SByte = Get(KnownTypeCode.SByte);
 
216
                
 
217
                /// <summary>
 
218
                /// Gets a type reference pointing to the <c>byte</c> type.
 
219
                /// </summary>
 
220
                public static readonly KnownTypeReference Byte = Get(KnownTypeCode.Byte);
 
221
                
 
222
                /// <summary>
 
223
                /// Gets a type reference pointing to the <c>short</c> type.
 
224
                /// </summary>
 
225
                public static readonly KnownTypeReference Int16 = Get(KnownTypeCode.Int16);
 
226
                
 
227
                /// <summary>
 
228
                /// Gets a type reference pointing to the <c>ushort</c> type.
 
229
                /// </summary>
 
230
                public static readonly KnownTypeReference UInt16 = Get(KnownTypeCode.UInt16);
 
231
                
 
232
                /// <summary>
 
233
                /// Gets a type reference pointing to the <c>int</c> type.
 
234
                /// </summary>
 
235
                public static readonly KnownTypeReference Int32 = Get(KnownTypeCode.Int32);
 
236
                
 
237
                /// <summary>
 
238
                /// Gets a type reference pointing to the <c>uint</c> type.
 
239
                /// </summary>
 
240
                public static readonly KnownTypeReference UInt32 = Get(KnownTypeCode.UInt32);
 
241
                
 
242
                /// <summary>
 
243
                /// Gets a type reference pointing to the <c>long</c> type.
 
244
                /// </summary>
 
245
                public static readonly KnownTypeReference Int64 = Get(KnownTypeCode.Int64);
 
246
                
 
247
                /// <summary>
 
248
                /// Gets a type reference pointing to the <c>ulong</c> type.
 
249
                /// </summary>
 
250
                public static readonly KnownTypeReference UInt64 = Get(KnownTypeCode.UInt64);
 
251
                
 
252
                /// <summary>
 
253
                /// Gets a type reference pointing to the <c>float</c> type.
 
254
                /// </summary>
 
255
                public static readonly KnownTypeReference Single = Get(KnownTypeCode.Single);
 
256
                
 
257
                /// <summary>
 
258
                /// Gets a type reference pointing to the <c>double</c> type.
 
259
                /// </summary>
 
260
                public static readonly KnownTypeReference Double = Get(KnownTypeCode.Double);
 
261
                
 
262
                /// <summary>
 
263
                /// Gets a type reference pointing to the <c>decimal</c> type.
 
264
                /// </summary>
 
265
                public static readonly KnownTypeReference Decimal = Get(KnownTypeCode.Decimal);
 
266
                
 
267
                /// <summary>
 
268
                /// Gets a type reference pointing to the <c>System.DateTime</c> type.
 
269
                /// </summary>
 
270
                public static readonly KnownTypeReference DateTime = Get(KnownTypeCode.DateTime);
 
271
                
 
272
                /// <summary>
 
273
                /// Gets a type reference pointing to the <c>string</c> type.
 
274
                /// </summary>
 
275
                public static readonly KnownTypeReference String = Get(KnownTypeCode.String);
 
276
                
 
277
                /// <summary>
 
278
                /// Gets a type reference pointing to the <c>void</c> type.
 
279
                /// </summary>
 
280
                public static readonly KnownTypeReference Void = Get(KnownTypeCode.Void);
 
281
                
 
282
                /// <summary>
 
283
                /// Gets a type reference pointing to the <c>System.Type</c> type.
 
284
                /// </summary>
 
285
                public static readonly KnownTypeReference Type = Get(KnownTypeCode.Type);
 
286
                
 
287
                /// <summary>
 
288
                /// Gets a type reference pointing to the <c>System.Array</c> type.
 
289
                /// </summary>
 
290
                public static readonly KnownTypeReference Array = Get(KnownTypeCode.Array);
 
291
                
 
292
                /// <summary>
 
293
                /// Gets a type reference pointing to the <c>System.Attribute</c> type.
 
294
                /// </summary>
 
295
                public static readonly KnownTypeReference Attribute = Get(KnownTypeCode.Attribute);
 
296
                
 
297
                /// <summary>
 
298
                /// Gets a type reference pointing to the <c>System.ValueType</c> type.
 
299
                /// </summary>
 
300
                public static readonly KnownTypeReference ValueType = Get(KnownTypeCode.ValueType);
 
301
                
 
302
                /// <summary>
 
303
                /// Gets a type reference pointing to the <c>System.Enum</c> type.
 
304
                /// </summary>
 
305
                public static readonly KnownTypeReference Enum = Get(KnownTypeCode.Enum);
 
306
                
 
307
                /// <summary>
 
308
                /// Gets a type reference pointing to the <c>System.Delegate</c> type.
 
309
                /// </summary>
 
310
                public static readonly KnownTypeReference Delegate = Get(KnownTypeCode.Delegate);
 
311
                
 
312
                /// <summary>
 
313
                /// Gets a type reference pointing to the <c>System.MulticastDelegate</c> type.
 
314
                /// </summary>
 
315
                public static readonly KnownTypeReference MulticastDelegate = Get(KnownTypeCode.MulticastDelegate);
 
316
                
 
317
                /// <summary>
 
318
                /// Gets a type reference pointing to the <c>System.Exception</c> type.
 
319
                /// </summary>
 
320
                public static readonly KnownTypeReference Exception = Get(KnownTypeCode.Exception);
 
321
                
 
322
                /// <summary>
 
323
                /// Gets a type reference pointing to the <c>System.IntPtr</c> type.
 
324
                /// </summary>
 
325
                public static readonly KnownTypeReference IntPtr = Get(KnownTypeCode.IntPtr);
 
326
                
 
327
                /// <summary>
 
328
                /// Gets a type reference pointing to the <c>System.UIntPtr</c> type.
 
329
                /// </summary>
 
330
                public static readonly KnownTypeReference UIntPtr = Get(KnownTypeCode.UIntPtr);
 
331
                
 
332
                /// <summary>
 
333
                /// Gets a type reference pointing to the <c>System.Collections.IEnumerable</c> type.
 
334
                /// </summary>
 
335
                public static readonly KnownTypeReference IEnumerable = Get(KnownTypeCode.IEnumerable);
 
336
                
 
337
                /// <summary>
 
338
                /// Gets a type reference pointing to the <c>System.Collections.IEnumerator</c> type.
 
339
                /// </summary>
 
340
                public static readonly KnownTypeReference IEnumerator = Get(KnownTypeCode.IEnumerator);
 
341
                
 
342
                /// <summary>
 
343
                /// Gets a type reference pointing to the <c>System.Collections.Generic.IEnumerable{T}</c> type.
 
344
                /// </summary>
 
345
                public static readonly KnownTypeReference IEnumerableOfT = Get(KnownTypeCode.IEnumerableOfT);
 
346
                
 
347
                /// <summary>
 
348
                /// Gets a type reference pointing to the <c>System.Collections.Generic.IEnumerator{T}</c> type.
 
349
                /// </summary>
 
350
                public static readonly KnownTypeReference IEnumeratorOfT = Get(KnownTypeCode.IEnumeratorOfT);
 
351
                
 
352
                /// <summary>
 
353
                /// Gets a type reference pointing to the <c>System.Collections.ICollection</c> type.
 
354
                /// </summary>
 
355
                public static readonly KnownTypeReference ICollection = Get(KnownTypeCode.ICollection);
 
356
                
 
357
                /// <summary>
 
358
                /// Gets a type reference pointing to the <c>System.Collections.Generic.ICollection{T}</c> type.
 
359
                /// </summary>
 
360
                public static readonly KnownTypeReference ICollectionOfT = Get(KnownTypeCode.ICollectionOfT);
 
361
                
 
362
                /// <summary>
 
363
                /// Gets a type reference pointing to the <c>System.Collections.IList</c> type.
 
364
                /// </summary>
 
365
                public static readonly KnownTypeReference IList = Get(KnownTypeCode.IList);
 
366
                
 
367
                /// <summary>
 
368
                /// Gets a type reference pointing to the <c>System.Collections.Generic.IList{T}</c> type.
 
369
                /// </summary>
 
370
                public static readonly KnownTypeReference IListOfT = Get(KnownTypeCode.IListOfT);
 
371
                
 
372
                /// <summary>
 
373
                /// Gets a type reference pointing to the <c>System.Collections.Generic.IReadOnlyList{T}</c> type.
 
374
                /// </summary>
 
375
                public static readonly KnownTypeReference IReadOnlyListOfT = Get(KnownTypeCode.IReadOnlyListOfT);
 
376
                
 
377
                /// <summary>
 
378
                /// Gets a type reference pointing to the <c>System.Threading.Tasks.Task</c> type.
 
379
                /// </summary>
 
380
                public static readonly KnownTypeReference Task = Get(KnownTypeCode.Task);
 
381
                
 
382
                /// <summary>
 
383
                /// Gets a type reference pointing to the <c>System.Threading.Tasks.Task{T}</c> type.
 
384
                /// </summary>
 
385
                public static readonly KnownTypeReference TaskOfT = Get(KnownTypeCode.TaskOfT);
 
386
                
 
387
                /// <summary>
 
388
                /// Gets a type reference pointing to the <c>System.Nullable{T}</c> type.
 
389
                /// </summary>
 
390
                public static readonly KnownTypeReference NullableOfT = Get(KnownTypeCode.NullableOfT);
 
391
                
 
392
                /// <summary>
 
393
                /// Gets a type reference pointing to the <c>System.IDisposable</c> type.
 
394
                /// </summary>
 
395
                public static readonly KnownTypeReference IDisposable = Get(KnownTypeCode.IDisposable);
 
396
 
 
397
                /// <summary>
 
398
                /// Gets a type reference pointing to the <c>System.Runtime.CompilerServices.INotifyCompletion</c> type.
 
399
                /// </summary>
 
400
                public static readonly KnownTypeReference INotifyCompletion = Get(KnownTypeCode.INotifyCompletion);
 
401
 
 
402
                /// <summary>
 
403
                /// Gets a type reference pointing to the <c>System.Runtime.CompilerServices.ICriticalNotifyCompletion</c> type.
 
404
                /// </summary>
 
405
                public static readonly KnownTypeReference ICriticalNotifyCompletion = Get(KnownTypeCode.ICriticalNotifyCompletion);
 
406
 
 
407
                readonly KnownTypeCode knownTypeCode;
 
408
                readonly string namespaceName;
 
409
                readonly string name;
 
410
                readonly int typeParameterCount;
 
411
                internal readonly KnownTypeCode baseType;
 
412
                
 
413
                private KnownTypeReference(KnownTypeCode knownTypeCode, string namespaceName, string name, int typeParameterCount = 0, KnownTypeCode baseType = KnownTypeCode.Object)
 
414
                {
 
415
                        this.knownTypeCode = knownTypeCode;
 
416
                        this.namespaceName = namespaceName;
 
417
                        this.name = name;
 
418
                        this.typeParameterCount = typeParameterCount;
 
419
                        this.baseType = baseType;
 
420
                }
 
421
                
 
422
                public KnownTypeCode KnownTypeCode {
 
423
                        get { return knownTypeCode; }
 
424
                }
 
425
                
 
426
                public string Namespace {
 
427
                        get { return namespaceName; }
 
428
                }
 
429
                
 
430
                public string Name {
 
431
                        get { return name; }
 
432
                }
 
433
                
 
434
                public int TypeParameterCount {
 
435
                        get { return typeParameterCount; }
 
436
                }
 
437
                
 
438
                public IType Resolve(ITypeResolveContext context)
 
439
                {
 
440
                        return context.Compilation.FindType(knownTypeCode);
 
441
                }
 
442
                
 
443
                public override string ToString()
 
444
                {
 
445
                        return GetCSharpNameByTypeCode(knownTypeCode) ?? (this.Namespace + "." + this.Name);
 
446
                }
 
447
                
 
448
                /// <summary>
 
449
                /// Gets the C# primitive type name from the known type code.
 
450
                /// Returns null if there is no primitive name for the specified type.
 
451
                /// </summary>
 
452
                public static string GetCSharpNameByTypeCode(KnownTypeCode knownTypeCode)
 
453
                {
 
454
                        switch (knownTypeCode) {
 
455
                                case KnownTypeCode.Object:
 
456
                                        return "object";
 
457
                                case KnownTypeCode.Boolean:
 
458
                                        return "bool";
 
459
                                case KnownTypeCode.Char:
 
460
                                        return "char";
 
461
                                case KnownTypeCode.SByte:
 
462
                                        return "sbyte";
 
463
                                case KnownTypeCode.Byte:
 
464
                                        return "byte";
 
465
                                case KnownTypeCode.Int16:
 
466
                                        return "short";
 
467
                                case KnownTypeCode.UInt16:
 
468
                                        return "ushort";
 
469
                                case KnownTypeCode.Int32:
 
470
                                        return "int";
 
471
                                case KnownTypeCode.UInt32:
 
472
                                        return "uint";
 
473
                                case KnownTypeCode.Int64:
 
474
                                        return "long";
 
475
                                case KnownTypeCode.UInt64:
 
476
                                        return "ulong";
 
477
                                case KnownTypeCode.Single:
 
478
                                        return "float";
 
479
                                case KnownTypeCode.Double:
 
480
                                        return "double";
 
481
                                case KnownTypeCode.Decimal:
 
482
                                        return "decimal";
 
483
                                case KnownTypeCode.String:
 
484
                                        return "string";
 
485
                                case KnownTypeCode.Void:
 
486
                                        return "void";
 
487
                                default:
 
488
                                        return null;
 
489
                        }
 
490
                }
 
491
        }
 
492
}