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.IReadOnlyCollection{T}</c></summary> |
---|
111 | IReadOnlyCollectionOfT, |
---|
112 | /// <summary><c>System.Collections.Generic.IReadOnlyList{T}</c></summary> |
---|
113 | IReadOnlyListOfT, |
---|
114 | /// <summary><c>System.Threading.Tasks.Task</c></summary> |
---|
115 | Task, |
---|
116 | /// <summary><c>System.Threading.Tasks.Task{T}</c></summary> |
---|
117 | TaskOfT, |
---|
118 | /// <summary><c>System.Nullable{T}</c></summary> |
---|
119 | NullableOfT, |
---|
120 | /// <summary><c>System.IDisposable</c></summary> |
---|
121 | IDisposable, |
---|
122 | /// <summary><c>System.Runtime.CompilerServices.INotifyCompletion</c></summary> |
---|
123 | INotifyCompletion, |
---|
124 | /// <summary><c>System.Runtime.CompilerServices.ICriticalNotifyCompletion</c></summary> |
---|
125 | ICriticalNotifyCompletion, |
---|
126 | } |
---|
127 | |
---|
128 | /// <summary> |
---|
129 | /// Contains well-known type references. |
---|
130 | /// </summary> |
---|
131 | [Serializable] |
---|
132 | public sealed class KnownTypeReference : ITypeReference |
---|
133 | { |
---|
134 | internal const int KnownTypeCodeCount = (int)KnownTypeCode.ICriticalNotifyCompletion + 1; |
---|
135 | |
---|
136 | static readonly KnownTypeReference[] knownTypeReferences = new KnownTypeReference[KnownTypeCodeCount] { |
---|
137 | null, // None |
---|
138 | new KnownTypeReference(KnownTypeCode.Object, "System", "Object", baseType: KnownTypeCode.None), |
---|
139 | new KnownTypeReference(KnownTypeCode.DBNull, "System", "DBNull"), |
---|
140 | new KnownTypeReference(KnownTypeCode.Boolean, "System", "Boolean", baseType: KnownTypeCode.ValueType), |
---|
141 | new KnownTypeReference(KnownTypeCode.Char, "System", "Char", baseType: KnownTypeCode.ValueType), |
---|
142 | new KnownTypeReference(KnownTypeCode.SByte, "System", "SByte", baseType: KnownTypeCode.ValueType), |
---|
143 | new KnownTypeReference(KnownTypeCode.Byte, "System", "Byte", baseType: KnownTypeCode.ValueType), |
---|
144 | new KnownTypeReference(KnownTypeCode.Int16, "System", "Int16", baseType: KnownTypeCode.ValueType), |
---|
145 | new KnownTypeReference(KnownTypeCode.UInt16, "System", "UInt16", baseType: KnownTypeCode.ValueType), |
---|
146 | new KnownTypeReference(KnownTypeCode.Int32, "System", "Int32", baseType: KnownTypeCode.ValueType), |
---|
147 | new KnownTypeReference(KnownTypeCode.UInt32, "System", "UInt32", baseType: KnownTypeCode.ValueType), |
---|
148 | new KnownTypeReference(KnownTypeCode.Int64, "System", "Int64", baseType: KnownTypeCode.ValueType), |
---|
149 | new KnownTypeReference(KnownTypeCode.UInt64, "System", "UInt64", baseType: KnownTypeCode.ValueType), |
---|
150 | new KnownTypeReference(KnownTypeCode.Single, "System", "Single", baseType: KnownTypeCode.ValueType), |
---|
151 | new KnownTypeReference(KnownTypeCode.Double, "System", "Double", baseType: KnownTypeCode.ValueType), |
---|
152 | new KnownTypeReference(KnownTypeCode.Decimal, "System", "Decimal", baseType: KnownTypeCode.ValueType), |
---|
153 | new KnownTypeReference(KnownTypeCode.DateTime, "System", "DateTime", baseType: KnownTypeCode.ValueType), |
---|
154 | null, |
---|
155 | new KnownTypeReference(KnownTypeCode.String, "System", "String"), |
---|
156 | new KnownTypeReference(KnownTypeCode.Void, "System", "Void"), |
---|
157 | new KnownTypeReference(KnownTypeCode.Type, "System", "Type"), |
---|
158 | new KnownTypeReference(KnownTypeCode.Array, "System", "Array"), |
---|
159 | new KnownTypeReference(KnownTypeCode.Attribute, "System", "Attribute"), |
---|
160 | new KnownTypeReference(KnownTypeCode.ValueType, "System", "ValueType"), |
---|
161 | new KnownTypeReference(KnownTypeCode.Enum, "System", "Enum", baseType: KnownTypeCode.ValueType), |
---|
162 | new KnownTypeReference(KnownTypeCode.Delegate, "System", "Delegate"), |
---|
163 | new KnownTypeReference(KnownTypeCode.MulticastDelegate, "System", "MulticastDelegate", baseType: KnownTypeCode.Delegate), |
---|
164 | new KnownTypeReference(KnownTypeCode.Exception, "System", "Exception"), |
---|
165 | new KnownTypeReference(KnownTypeCode.IntPtr, "System", "IntPtr", baseType: KnownTypeCode.ValueType), |
---|
166 | new KnownTypeReference(KnownTypeCode.UIntPtr, "System", "UIntPtr", baseType: KnownTypeCode.ValueType), |
---|
167 | new KnownTypeReference(KnownTypeCode.IEnumerable, "System.Collections", "IEnumerable"), |
---|
168 | new KnownTypeReference(KnownTypeCode.IEnumerator, "System.Collections", "IEnumerator"), |
---|
169 | new KnownTypeReference(KnownTypeCode.IEnumerableOfT, "System.Collections.Generic", "IEnumerable", 1), |
---|
170 | new KnownTypeReference(KnownTypeCode.IEnumeratorOfT, "System.Collections.Generic", "IEnumerator", 1), |
---|
171 | new KnownTypeReference(KnownTypeCode.ICollection, "System.Collections", "ICollection"), |
---|
172 | new KnownTypeReference(KnownTypeCode.ICollectionOfT, "System.Collections.Generic", "ICollection", 1), |
---|
173 | new KnownTypeReference(KnownTypeCode.IList, "System.Collections", "IList"), |
---|
174 | new KnownTypeReference(KnownTypeCode.IListOfT, "System.Collections.Generic", "IList", 1), |
---|
175 | |
---|
176 | new KnownTypeReference(KnownTypeCode.IReadOnlyCollectionOfT, "System.Collections.Generic", "IReadOnlyCollection", 1), |
---|
177 | new KnownTypeReference(KnownTypeCode.IReadOnlyListOfT, "System.Collections.Generic", "IReadOnlyList", 1), |
---|
178 | new KnownTypeReference(KnownTypeCode.Task, "System.Threading.Tasks", "Task"), |
---|
179 | new KnownTypeReference(KnownTypeCode.TaskOfT, "System.Threading.Tasks", "Task", 1, baseType: KnownTypeCode.Task), |
---|
180 | new KnownTypeReference(KnownTypeCode.NullableOfT, "System", "Nullable", 1, baseType: KnownTypeCode.ValueType), |
---|
181 | new KnownTypeReference(KnownTypeCode.IDisposable, "System", "IDisposable"), |
---|
182 | new KnownTypeReference(KnownTypeCode.INotifyCompletion, "System.Runtime.CompilerServices", "INotifyCompletion"), |
---|
183 | new KnownTypeReference(KnownTypeCode.ICriticalNotifyCompletion, "System.Runtime.CompilerServices", "ICriticalNotifyCompletion"), |
---|
184 | }; |
---|
185 | |
---|
186 | /// <summary> |
---|
187 | /// Gets the known type reference for the specified type code. |
---|
188 | /// Returns null for KnownTypeCode.None. |
---|
189 | /// </summary> |
---|
190 | public static KnownTypeReference Get(KnownTypeCode typeCode) |
---|
191 | { |
---|
192 | return knownTypeReferences[(int)typeCode]; |
---|
193 | } |
---|
194 | |
---|
195 | /// <summary> |
---|
196 | /// Gets a type reference pointing to the <c>object</c> type. |
---|
197 | /// </summary> |
---|
198 | public static readonly KnownTypeReference Object = Get(KnownTypeCode.Object); |
---|
199 | |
---|
200 | /// <summary> |
---|
201 | /// Gets a type reference pointing to the <c>System.DBNull</c> type. |
---|
202 | /// </summary> |
---|
203 | public static readonly KnownTypeReference DBNull = Get(KnownTypeCode.DBNull); |
---|
204 | |
---|
205 | /// <summary> |
---|
206 | /// Gets a type reference pointing to the <c>bool</c> type. |
---|
207 | /// </summary> |
---|
208 | public static readonly KnownTypeReference Boolean = Get(KnownTypeCode.Boolean); |
---|
209 | |
---|
210 | /// <summary> |
---|
211 | /// Gets a type reference pointing to the <c>char</c> type. |
---|
212 | /// </summary> |
---|
213 | public static readonly KnownTypeReference Char = Get(KnownTypeCode.Char); |
---|
214 | |
---|
215 | /// <summary> |
---|
216 | /// Gets a type reference pointing to the <c>sbyte</c> type. |
---|
217 | /// </summary> |
---|
218 | public static readonly KnownTypeReference SByte = Get(KnownTypeCode.SByte); |
---|
219 | |
---|
220 | /// <summary> |
---|
221 | /// Gets a type reference pointing to the <c>byte</c> type. |
---|
222 | /// </summary> |
---|
223 | public static readonly KnownTypeReference Byte = Get(KnownTypeCode.Byte); |
---|
224 | |
---|
225 | /// <summary> |
---|
226 | /// Gets a type reference pointing to the <c>short</c> type. |
---|
227 | /// </summary> |
---|
228 | public static readonly KnownTypeReference Int16 = Get(KnownTypeCode.Int16); |
---|
229 | |
---|
230 | /// <summary> |
---|
231 | /// Gets a type reference pointing to the <c>ushort</c> type. |
---|
232 | /// </summary> |
---|
233 | public static readonly KnownTypeReference UInt16 = Get(KnownTypeCode.UInt16); |
---|
234 | |
---|
235 | /// <summary> |
---|
236 | /// Gets a type reference pointing to the <c>int</c> type. |
---|
237 | /// </summary> |
---|
238 | public static readonly KnownTypeReference Int32 = Get(KnownTypeCode.Int32); |
---|
239 | |
---|
240 | /// <summary> |
---|
241 | /// Gets a type reference pointing to the <c>uint</c> type. |
---|
242 | /// </summary> |
---|
243 | public static readonly KnownTypeReference UInt32 = Get(KnownTypeCode.UInt32); |
---|
244 | |
---|
245 | /// <summary> |
---|
246 | /// Gets a type reference pointing to the <c>long</c> type. |
---|
247 | /// </summary> |
---|
248 | public static readonly KnownTypeReference Int64 = Get(KnownTypeCode.Int64); |
---|
249 | |
---|
250 | /// <summary> |
---|
251 | /// Gets a type reference pointing to the <c>ulong</c> type. |
---|
252 | /// </summary> |
---|
253 | public static readonly KnownTypeReference UInt64 = Get(KnownTypeCode.UInt64); |
---|
254 | |
---|
255 | /// <summary> |
---|
256 | /// Gets a type reference pointing to the <c>float</c> type. |
---|
257 | /// </summary> |
---|
258 | public static readonly KnownTypeReference Single = Get(KnownTypeCode.Single); |
---|
259 | |
---|
260 | /// <summary> |
---|
261 | /// Gets a type reference pointing to the <c>double</c> type. |
---|
262 | /// </summary> |
---|
263 | public static readonly KnownTypeReference Double = Get(KnownTypeCode.Double); |
---|
264 | |
---|
265 | /// <summary> |
---|
266 | /// Gets a type reference pointing to the <c>decimal</c> type. |
---|
267 | /// </summary> |
---|
268 | public static readonly KnownTypeReference Decimal = Get(KnownTypeCode.Decimal); |
---|
269 | |
---|
270 | /// <summary> |
---|
271 | /// Gets a type reference pointing to the <c>System.DateTime</c> type. |
---|
272 | /// </summary> |
---|
273 | public static readonly KnownTypeReference DateTime = Get(KnownTypeCode.DateTime); |
---|
274 | |
---|
275 | /// <summary> |
---|
276 | /// Gets a type reference pointing to the <c>string</c> type. |
---|
277 | /// </summary> |
---|
278 | public static readonly KnownTypeReference String = Get(KnownTypeCode.String); |
---|
279 | |
---|
280 | /// <summary> |
---|
281 | /// Gets a type reference pointing to the <c>void</c> type. |
---|
282 | /// </summary> |
---|
283 | public static readonly KnownTypeReference Void = Get(KnownTypeCode.Void); |
---|
284 | |
---|
285 | /// <summary> |
---|
286 | /// Gets a type reference pointing to the <c>System.Type</c> type. |
---|
287 | /// </summary> |
---|
288 | public static readonly KnownTypeReference Type = Get(KnownTypeCode.Type); |
---|
289 | |
---|
290 | /// <summary> |
---|
291 | /// Gets a type reference pointing to the <c>System.Array</c> type. |
---|
292 | /// </summary> |
---|
293 | public static readonly KnownTypeReference Array = Get(KnownTypeCode.Array); |
---|
294 | |
---|
295 | /// <summary> |
---|
296 | /// Gets a type reference pointing to the <c>System.Attribute</c> type. |
---|
297 | /// </summary> |
---|
298 | public static readonly KnownTypeReference Attribute = Get(KnownTypeCode.Attribute); |
---|
299 | |
---|
300 | /// <summary> |
---|
301 | /// Gets a type reference pointing to the <c>System.ValueType</c> type. |
---|
302 | /// </summary> |
---|
303 | public static readonly KnownTypeReference ValueType = Get(KnownTypeCode.ValueType); |
---|
304 | |
---|
305 | /// <summary> |
---|
306 | /// Gets a type reference pointing to the <c>System.Enum</c> type. |
---|
307 | /// </summary> |
---|
308 | public static readonly KnownTypeReference Enum = Get(KnownTypeCode.Enum); |
---|
309 | |
---|
310 | /// <summary> |
---|
311 | /// Gets a type reference pointing to the <c>System.Delegate</c> type. |
---|
312 | /// </summary> |
---|
313 | public static readonly KnownTypeReference Delegate = Get(KnownTypeCode.Delegate); |
---|
314 | |
---|
315 | /// <summary> |
---|
316 | /// Gets a type reference pointing to the <c>System.MulticastDelegate</c> type. |
---|
317 | /// </summary> |
---|
318 | public static readonly KnownTypeReference MulticastDelegate = Get(KnownTypeCode.MulticastDelegate); |
---|
319 | |
---|
320 | /// <summary> |
---|
321 | /// Gets a type reference pointing to the <c>System.Exception</c> type. |
---|
322 | /// </summary> |
---|
323 | public static readonly KnownTypeReference Exception = Get(KnownTypeCode.Exception); |
---|
324 | |
---|
325 | /// <summary> |
---|
326 | /// Gets a type reference pointing to the <c>System.IntPtr</c> type. |
---|
327 | /// </summary> |
---|
328 | public static readonly KnownTypeReference IntPtr = Get(KnownTypeCode.IntPtr); |
---|
329 | |
---|
330 | /// <summary> |
---|
331 | /// Gets a type reference pointing to the <c>System.UIntPtr</c> type. |
---|
332 | /// </summary> |
---|
333 | public static readonly KnownTypeReference UIntPtr = Get(KnownTypeCode.UIntPtr); |
---|
334 | |
---|
335 | /// <summary> |
---|
336 | /// Gets a type reference pointing to the <c>System.Collections.IEnumerable</c> type. |
---|
337 | /// </summary> |
---|
338 | public static readonly KnownTypeReference IEnumerable = Get(KnownTypeCode.IEnumerable); |
---|
339 | |
---|
340 | /// <summary> |
---|
341 | /// Gets a type reference pointing to the <c>System.Collections.IEnumerator</c> type. |
---|
342 | /// </summary> |
---|
343 | public static readonly KnownTypeReference IEnumerator = Get(KnownTypeCode.IEnumerator); |
---|
344 | |
---|
345 | /// <summary> |
---|
346 | /// Gets a type reference pointing to the <c>System.Collections.Generic.IEnumerable{T}</c> type. |
---|
347 | /// </summary> |
---|
348 | public static readonly KnownTypeReference IEnumerableOfT = Get(KnownTypeCode.IEnumerableOfT); |
---|
349 | |
---|
350 | /// <summary> |
---|
351 | /// Gets a type reference pointing to the <c>System.Collections.Generic.IEnumerator{T}</c> type. |
---|
352 | /// </summary> |
---|
353 | public static readonly KnownTypeReference IEnumeratorOfT = Get(KnownTypeCode.IEnumeratorOfT); |
---|
354 | |
---|
355 | /// <summary> |
---|
356 | /// Gets a type reference pointing to the <c>System.Collections.ICollection</c> type. |
---|
357 | /// </summary> |
---|
358 | public static readonly KnownTypeReference ICollection = Get(KnownTypeCode.ICollection); |
---|
359 | |
---|
360 | /// <summary> |
---|
361 | /// Gets a type reference pointing to the <c>System.Collections.Generic.ICollection{T}</c> type. |
---|
362 | /// </summary> |
---|
363 | public static readonly KnownTypeReference ICollectionOfT = Get(KnownTypeCode.ICollectionOfT); |
---|
364 | |
---|
365 | /// <summary> |
---|
366 | /// Gets a type reference pointing to the <c>System.Collections.IList</c> type. |
---|
367 | /// </summary> |
---|
368 | public static readonly KnownTypeReference IList = Get(KnownTypeCode.IList); |
---|
369 | |
---|
370 | /// <summary> |
---|
371 | /// Gets a type reference pointing to the <c>System.Collections.Generic.IList{T}</c> type. |
---|
372 | /// </summary> |
---|
373 | public static readonly KnownTypeReference IListOfT = Get(KnownTypeCode.IListOfT); |
---|
374 | |
---|
375 | /// <summary> |
---|
376 | /// Gets a type reference pointing to the <c>System.Collections.Generic.IReadOnlyCollection{T}</c> type. |
---|
377 | /// </summary> |
---|
378 | public static readonly KnownTypeReference IReadOnlyCollectionOfT = Get(KnownTypeCode.IReadOnlyCollectionOfT); |
---|
379 | |
---|
380 | /// <summary> |
---|
381 | /// Gets a type reference pointing to the <c>System.Collections.Generic.IReadOnlyList{T}</c> type. |
---|
382 | /// </summary> |
---|
383 | public static readonly KnownTypeReference IReadOnlyListOfT = Get(KnownTypeCode.IReadOnlyListOfT); |
---|
384 | |
---|
385 | /// <summary> |
---|
386 | /// Gets a type reference pointing to the <c>System.Threading.Tasks.Task</c> type. |
---|
387 | /// </summary> |
---|
388 | public static readonly KnownTypeReference Task = Get(KnownTypeCode.Task); |
---|
389 | |
---|
390 | /// <summary> |
---|
391 | /// Gets a type reference pointing to the <c>System.Threading.Tasks.Task{T}</c> type. |
---|
392 | /// </summary> |
---|
393 | public static readonly KnownTypeReference TaskOfT = Get(KnownTypeCode.TaskOfT); |
---|
394 | |
---|
395 | /// <summary> |
---|
396 | /// Gets a type reference pointing to the <c>System.Nullable{T}</c> type. |
---|
397 | /// </summary> |
---|
398 | public static readonly KnownTypeReference NullableOfT = Get(KnownTypeCode.NullableOfT); |
---|
399 | |
---|
400 | /// <summary> |
---|
401 | /// Gets a type reference pointing to the <c>System.IDisposable</c> type. |
---|
402 | /// </summary> |
---|
403 | public static readonly KnownTypeReference IDisposable = Get(KnownTypeCode.IDisposable); |
---|
404 | |
---|
405 | /// <summary> |
---|
406 | /// Gets a type reference pointing to the <c>System.Runtime.CompilerServices.INotifyCompletion</c> type. |
---|
407 | /// </summary> |
---|
408 | public static readonly KnownTypeReference INotifyCompletion = Get(KnownTypeCode.INotifyCompletion); |
---|
409 | |
---|
410 | /// <summary> |
---|
411 | /// Gets a type reference pointing to the <c>System.Runtime.CompilerServices.ICriticalNotifyCompletion</c> type. |
---|
412 | /// </summary> |
---|
413 | public static readonly KnownTypeReference ICriticalNotifyCompletion = Get(KnownTypeCode.ICriticalNotifyCompletion); |
---|
414 | |
---|
415 | readonly KnownTypeCode knownTypeCode; |
---|
416 | readonly string namespaceName; |
---|
417 | readonly string name; |
---|
418 | readonly int typeParameterCount; |
---|
419 | internal readonly KnownTypeCode baseType; |
---|
420 | |
---|
421 | private KnownTypeReference(KnownTypeCode knownTypeCode, string namespaceName, string name, int typeParameterCount = 0, KnownTypeCode baseType = KnownTypeCode.Object) |
---|
422 | { |
---|
423 | this.knownTypeCode = knownTypeCode; |
---|
424 | this.namespaceName = namespaceName; |
---|
425 | this.name = name; |
---|
426 | this.typeParameterCount = typeParameterCount; |
---|
427 | this.baseType = baseType; |
---|
428 | } |
---|
429 | |
---|
430 | public KnownTypeCode KnownTypeCode { |
---|
431 | get { return knownTypeCode; } |
---|
432 | } |
---|
433 | |
---|
434 | public string Namespace { |
---|
435 | get { return namespaceName; } |
---|
436 | } |
---|
437 | |
---|
438 | public string Name { |
---|
439 | get { return name; } |
---|
440 | } |
---|
441 | |
---|
442 | public int TypeParameterCount { |
---|
443 | get { return typeParameterCount; } |
---|
444 | } |
---|
445 | |
---|
446 | public IType Resolve(ITypeResolveContext context) |
---|
447 | { |
---|
448 | return context.Compilation.FindType(knownTypeCode); |
---|
449 | } |
---|
450 | |
---|
451 | public override string ToString() |
---|
452 | { |
---|
453 | return GetCSharpNameByTypeCode(knownTypeCode) ?? (this.Namespace + "." + this.Name); |
---|
454 | } |
---|
455 | |
---|
456 | /// <summary> |
---|
457 | /// Gets the C# primitive type name from the known type code. |
---|
458 | /// Returns null if there is no primitive name for the specified type. |
---|
459 | /// </summary> |
---|
460 | public static string GetCSharpNameByTypeCode(KnownTypeCode knownTypeCode) |
---|
461 | { |
---|
462 | switch (knownTypeCode) { |
---|
463 | case KnownTypeCode.Object: |
---|
464 | return "object"; |
---|
465 | case KnownTypeCode.Boolean: |
---|
466 | return "bool"; |
---|
467 | case KnownTypeCode.Char: |
---|
468 | return "char"; |
---|
469 | case KnownTypeCode.SByte: |
---|
470 | return "sbyte"; |
---|
471 | case KnownTypeCode.Byte: |
---|
472 | return "byte"; |
---|
473 | case KnownTypeCode.Int16: |
---|
474 | return "short"; |
---|
475 | case KnownTypeCode.UInt16: |
---|
476 | return "ushort"; |
---|
477 | case KnownTypeCode.Int32: |
---|
478 | return "int"; |
---|
479 | case KnownTypeCode.UInt32: |
---|
480 | return "uint"; |
---|
481 | case KnownTypeCode.Int64: |
---|
482 | return "long"; |
---|
483 | case KnownTypeCode.UInt64: |
---|
484 | return "ulong"; |
---|
485 | case KnownTypeCode.Single: |
---|
486 | return "float"; |
---|
487 | case KnownTypeCode.Double: |
---|
488 | return "double"; |
---|
489 | case KnownTypeCode.Decimal: |
---|
490 | return "decimal"; |
---|
491 | case KnownTypeCode.String: |
---|
492 | return "string"; |
---|
493 | case KnownTypeCode.Void: |
---|
494 | return "void"; |
---|
495 | default: |
---|
496 | return null; |
---|
497 | } |
---|
498 | } |
---|
499 | } |
---|
500 | } |
---|