2 // CodeTypeReferenceTest.cs - NUnit Test Cases for System.CodeDom.CodeTypeReference
5 // Gert Driesen (drieseng@users.sourceforge.net)
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
12 using System.Collections.Generic;
14 using NUnit.Framework;
16 namespace MonoTests.System.CodeDom
19 public class CodeTypeReferenceTest
22 public void EmptyTypeName ()
24 CodeTypeReference reference = new CodeTypeReference (string.Empty);
25 Assert.AreEqual (typeof (void).FullName, reference.BaseType);
26 Assert.AreEqual (0, reference.ArrayRank);
27 Assert.IsNull (reference.ArrayElementType);
28 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
29 Assert.IsNotNull (reference.TypeArguments, "#5");
30 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
34 public void NullTypeName ()
36 CodeTypeReference reference = new CodeTypeReference ((string) null);
37 Assert.AreEqual (typeof (void).FullName, reference.BaseType, "#1");
38 Assert.AreEqual (0, reference.ArrayRank, "#2");
39 Assert.IsNull (reference.ArrayElementType, "#3");
40 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
41 Assert.IsNotNull (reference.TypeArguments, "#5");
42 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
46 [ExpectedException (typeof(ArgumentNullException))]
47 public void NullType ()
49 new CodeTypeReference ((Type) null);
53 public void NullBaseType ()
55 CodeTypeReference reference = new CodeTypeReference ((string) null);
56 Assert.AreEqual (typeof (void).FullName, reference.BaseType);
60 public void ZeroLengthBaseType ()
62 CodeTypeReference reference = new CodeTypeReference (string.Empty);
63 Assert.AreEqual (typeof (void).FullName, reference.BaseType, "#1");
67 public void BaseTypeTest1 ()
69 CodeTypeReference reference = new CodeTypeReference ("A[B]");
70 Assert.AreEqual ("A", reference.BaseType, "#1");
71 Assert.AreEqual (0, reference.ArrayRank, "#2");
72 Assert.IsNull (reference.ArrayElementType, "#3");
73 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
74 Assert.IsNotNull (reference.TypeArguments, "#5");
75 Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
77 CodeTypeReference typeArgument = reference.TypeArguments[0];
78 Assert.AreEqual ("B", typeArgument.BaseType, "#7");
79 Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
80 Assert.IsNull (typeArgument.ArrayElementType, "#9");
81 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
82 Assert.IsNotNull (typeArgument.TypeArguments, "#11");
83 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
87 public void BaseTypeTest2 ()
89 CodeTypeReference reference = new CodeTypeReference ("A[]");
90 Assert.AreEqual ("A", reference.BaseType, "#1");
91 Assert.AreEqual (1, reference.ArrayRank, "#2");
92 Assert.IsNotNull (reference.ArrayElementType, "#3");
93 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
94 Assert.IsNotNull (reference.TypeArguments, "#5");
95 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
97 CodeTypeReference arrayElementType = reference.ArrayElementType;
98 Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
99 Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
100 Assert.IsNull (arrayElementType.ArrayElementType, "#9");
101 Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
102 Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
103 Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
107 public void BaseTypeTest3 ()
109 CodeTypeReference reference = new CodeTypeReference ("A[,]");
110 Assert.AreEqual ("A", reference.BaseType, "#1");
111 Assert.AreEqual (2, reference.ArrayRank, "#2");
112 Assert.IsNotNull (reference.ArrayElementType, "#3");
113 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
114 Assert.IsNotNull (reference.TypeArguments, "#5");
115 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
117 CodeTypeReference arrayElementType = reference.ArrayElementType;
118 Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
119 Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
120 Assert.IsNull (arrayElementType.ArrayElementType, "#9");
121 Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
122 Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
123 Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
127 public void BaseTypeTest4 ()
129 CodeTypeReference reference = new CodeTypeReference ("A[,,]");
130 Assert.AreEqual ("A", reference.BaseType, "#1");
131 Assert.AreEqual (3, reference.ArrayRank, "#2");
132 Assert.IsNotNull (reference.ArrayElementType, "#3");
133 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
134 Assert.IsNotNull (reference.TypeArguments, "#5");
135 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
137 CodeTypeReference arrayElementType = reference.ArrayElementType;
138 Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
139 Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
140 Assert.IsNull (arrayElementType.ArrayElementType, "#9");
141 Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
142 Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
143 Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
147 public void BaseTypeTest5 ()
149 CodeTypeReference reference = new CodeTypeReference ("A[B,C]");
150 Assert.AreEqual ("A", reference.BaseType, "#1");
151 Assert.AreEqual (0, reference.ArrayRank, "#2");
152 Assert.IsNull (reference.ArrayElementType, "#3");
153 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
154 Assert.IsNotNull (reference.TypeArguments, "#5");
155 Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
157 CodeTypeReference typeArgument = reference.TypeArguments[0];
158 Assert.AreEqual ("B", typeArgument.BaseType, "#7");
159 Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
160 Assert.IsNull (typeArgument.ArrayElementType, "#9");
161 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
162 Assert.IsNotNull (typeArgument.TypeArguments, "#11");
163 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
165 typeArgument = reference.TypeArguments[1];
166 Assert.AreEqual ("C", typeArgument.BaseType, "#13");
167 Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
168 Assert.IsNull (typeArgument.ArrayElementType, "#15");
169 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
170 Assert.IsNotNull (typeArgument.TypeArguments, "#17");
171 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
175 public void BaseTypeTest6 ()
177 CodeTypeReference reference = new CodeTypeReference ("A[");
178 Assert.AreEqual ("A[", reference.BaseType, "#1");
179 Assert.AreEqual (0, reference.ArrayRank, "#2");
180 Assert.IsNull (reference.ArrayElementType, "#3");
181 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
182 Assert.IsNotNull (reference.TypeArguments, "#5");
183 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
187 public void BaseTypeTest7 ()
189 CodeTypeReference reference = new CodeTypeReference ("A[,B,,C]");
190 Assert.AreEqual ("A", reference.BaseType, "#1");
191 Assert.AreEqual (0, reference.ArrayRank, "#2");
192 Assert.IsNull (reference.ArrayElementType, "#3");
193 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
194 Assert.IsNotNull (reference.TypeArguments, "#5");
195 Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
197 CodeTypeReference typeArgument = reference.TypeArguments[0];
198 Assert.AreEqual ("B", typeArgument.BaseType, "#7");
199 Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
200 Assert.IsNull (typeArgument.ArrayElementType, "#9");
201 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
202 Assert.IsNotNull (typeArgument.TypeArguments, "#11");
203 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
205 typeArgument = reference.TypeArguments[1];
206 Assert.AreEqual ("C", typeArgument.BaseType, "#13");
207 Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
208 Assert.IsNull (typeArgument.ArrayElementType, "#15");
209 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
210 Assert.IsNotNull (typeArgument.TypeArguments, "#17");
211 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
215 // CodeTypeReference should parse basetype from right to left in 2.0
217 [Category ("NotWorking")]
218 public void BaseTypeTest8 ()
220 CodeTypeReference reference = new CodeTypeReference ("A[,,][,]");
221 Assert.AreEqual ("A", reference.BaseType, "#1");
222 Assert.AreEqual (3, reference.ArrayRank, "#2");
223 Assert.IsNotNull (reference.ArrayElementType, "#3");
225 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
226 Assert.IsNotNull (reference.TypeArguments, "#5");
227 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
229 CodeTypeReference arrayElementType = reference.ArrayElementType;
230 Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
231 Assert.AreEqual (2, arrayElementType.ArrayRank, "#8");
232 Assert.IsNotNull (arrayElementType.ArrayElementType, "#9");
233 Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
234 Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
235 Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
237 arrayElementType = arrayElementType.ArrayElementType;
238 Assert.AreEqual ("A", arrayElementType.BaseType, "#13");
239 Assert.AreEqual (0, arrayElementType.ArrayRank, "#14");
240 Assert.IsNull (arrayElementType.ArrayElementType, "#15");
241 Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#16");
242 Assert.IsNotNull (arrayElementType.TypeArguments, "#17");
243 Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#18");
247 // CodeTypeReference should parse basetype from right to left in 2.0
249 [Category ("NotWorking")]
250 public void BaseTypeTest9 ()
252 CodeTypeReference reference = new CodeTypeReference ("A[B,,D][,]");
253 Assert.AreEqual ("A`2", reference.BaseType, "#1");
254 Assert.AreEqual (2, reference.ArrayRank, "#2");
255 Assert.IsNotNull (reference.ArrayElementType, "#3");
257 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
258 Assert.IsNotNull (reference.TypeArguments, "#5");
259 Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
261 CodeTypeReference arrayElementType = reference.ArrayElementType;
262 Assert.AreEqual ("A`2", arrayElementType.BaseType, "#7");
263 Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
264 Assert.IsNull (arrayElementType.ArrayElementType, "#9");
265 Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
266 Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
267 Assert.AreEqual (2, arrayElementType.TypeArguments.Count, "#12");
269 CodeTypeReference typeArgument = reference.TypeArguments[0];
270 Assert.AreEqual ("B", typeArgument.BaseType, "#13");
271 Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
272 Assert.IsNull (typeArgument.ArrayElementType, "#15");
273 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
274 Assert.IsNotNull (typeArgument.TypeArguments, "#17");
275 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
277 typeArgument = reference.TypeArguments[1];
278 Assert.AreEqual ("D", typeArgument.BaseType, "#19");
279 Assert.AreEqual (0, typeArgument.ArrayRank, "#20");
280 Assert.IsNull (typeArgument.ArrayElementType, "#21");
281 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#22");
282 Assert.IsNotNull (typeArgument.TypeArguments, "#23");
283 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#24");
287 public void Defaults ()
289 CodeTypeReference reference = new CodeTypeReference ();
291 Assert.IsNull (reference.ArrayElementType, "#1");
292 Assert.AreEqual (0, reference.ArrayRank, "#2");
293 Assert.AreEqual (string.Empty, reference.BaseType, "#3");
294 Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
295 Assert.IsNotNull (reference.TypeArguments, "#5");
296 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
300 public void CodeTypeParameter1 ()
302 CodeTypeReference reference = new CodeTypeReference(
303 new CodeTypeParameter ("A"));
304 Assert.AreEqual ("A", reference.BaseType, "#1");
305 Assert.AreEqual (0, reference.ArrayRank, "#2");
306 Assert.IsNull (reference.ArrayElementType, "#3");
307 Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
308 Assert.IsNotNull (reference.TypeArguments, "#5");
309 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
313 public void CodeTypeParameter2 ()
315 CodeTypeReference reference = new CodeTypeReference (
316 new CodeTypeParameter ("A[B]"));
317 Assert.AreEqual ("A", reference.BaseType, "#1");
318 Assert.AreEqual (0, reference.ArrayRank, "#2");
319 Assert.IsNull (reference.ArrayElementType, "#3");
320 Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
321 Assert.IsNotNull (reference.TypeArguments, "#5");
322 Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
324 CodeTypeReference typeArgument = reference.TypeArguments[0];
325 Assert.AreEqual ("B", typeArgument.BaseType, "#7");
326 Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
327 Assert.IsNull (typeArgument.ArrayElementType, "#9");
328 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
329 Assert.IsNotNull (typeArgument.TypeArguments, "#11");
330 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
334 public void CodeTypeParameter3 ()
336 CodeTypeReference reference = new CodeTypeReference (
337 new CodeTypeParameter ("A[B, C]"));
338 Assert.AreEqual ("A", reference.BaseType, "#1");
339 Assert.AreEqual (0, reference.ArrayRank, "#2");
340 Assert.IsNull (reference.ArrayElementType, "#3");
341 Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
342 Assert.IsNotNull (reference.TypeArguments, "#5");
343 Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
345 CodeTypeReference typeArgument = reference.TypeArguments[0];
346 Assert.AreEqual ("B", typeArgument.BaseType, "#7");
347 Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
348 Assert.IsNull (typeArgument.ArrayElementType, "#9");
349 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
350 Assert.IsNotNull (typeArgument.TypeArguments, "#11");
351 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
353 typeArgument = reference.TypeArguments[1];
354 Assert.AreEqual (" C", typeArgument.BaseType, "#13");
355 Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
356 Assert.IsNull (typeArgument.ArrayElementType, "#15");
357 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
358 Assert.IsNotNull (typeArgument.TypeArguments, "#17");
359 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
363 public void CodeTypeParameter4 ()
365 CodeTypeReference reference = new CodeTypeReference (
366 new CodeTypeParameter ("A[]"));
367 Assert.AreEqual ("A", reference.BaseType, "#1");
368 Assert.AreEqual (1, reference.ArrayRank, "#2");
369 Assert.IsNotNull (reference.ArrayElementType, "#3");
370 Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
371 Assert.IsNotNull (reference.TypeArguments, "#5");
372 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
374 CodeTypeReference arrayElementType = reference.ArrayElementType;
375 Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
376 Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
377 Assert.IsNull (arrayElementType.ArrayElementType, "#9");
378 Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
379 Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
380 Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
384 public void CodeTypeParameter5 ()
386 CodeTypeReference reference = new CodeTypeReference (
387 new CodeTypeParameter ("A[,"));
388 Assert.AreEqual ("A[,", reference.BaseType, "#1");
389 Assert.AreEqual (0, reference.ArrayRank, "#2");
390 Assert.IsNull (reference.ArrayElementType, "#3");
391 Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
392 Assert.IsNotNull (reference.TypeArguments, "#5");
393 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
397 public void GenericTypeTest1 () {
398 CodeTypeReference reference = new CodeTypeReference (
399 typeof (Dictionary<int,string>));
400 Assert.AreEqual ("System.Collections.Generic.Dictionary`2", reference.BaseType, "#1");
401 Assert.AreEqual (0, reference.ArrayRank, "#2");
402 Assert.IsNull (reference.ArrayElementType, "#3");
403 Assert.AreEqual (0, (int) reference.Options, "#4");
404 Assert.IsNotNull (reference.TypeArguments, "#5");
405 Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
407 CodeTypeReference typeArgument = reference.TypeArguments[0];
408 Assert.AreEqual ("System.Int32", typeArgument.BaseType, "#7");
409 Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
410 Assert.IsNull (typeArgument.ArrayElementType, "#9");
411 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
412 Assert.IsNotNull (typeArgument.TypeArguments, "#11");
413 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
415 typeArgument = reference.TypeArguments[1];
416 Assert.AreEqual ("System.String", typeArgument.BaseType, "#13");
417 Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
418 Assert.IsNull (typeArgument.ArrayElementType, "#15");
419 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
420 Assert.IsNotNull (typeArgument.TypeArguments, "#17");
421 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
425 public void GenericTypeTest2 () {
426 CodeTypeReference reference = new CodeTypeReference (
427 typeof (Dictionary<List<int>, string>));
428 Assert.AreEqual ("System.Collections.Generic.Dictionary`2", reference.BaseType, "#1");
429 Assert.AreEqual (0, reference.ArrayRank, "#2");
430 Assert.IsNull (reference.ArrayElementType, "#3");
431 Assert.AreEqual (0, (int) reference.Options, "#4");
432 Assert.IsNotNull (reference.TypeArguments, "#5");
433 Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
435 CodeTypeReference typeArgument = reference.TypeArguments[0];
436 Assert.AreEqual ("System.Collections.Generic.List`1", typeArgument.BaseType, "#7");
437 Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
438 Assert.IsNull (typeArgument.ArrayElementType, "#9");
439 Assert.AreEqual (0, (int) typeArgument.Options, "#10");
440 Assert.IsNotNull (typeArgument.TypeArguments, "#11");
441 Assert.AreEqual (1, typeArgument.TypeArguments.Count, "#12");
443 CodeTypeReference nestedTypeArgument = typeArgument.TypeArguments[0];
444 Assert.AreEqual ("System.Int32", nestedTypeArgument.BaseType, "#13");
445 Assert.AreEqual (0, nestedTypeArgument.ArrayRank, "#14");
446 Assert.IsNull (nestedTypeArgument.ArrayElementType, "#15");
447 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
448 Assert.IsNotNull (nestedTypeArgument.TypeArguments, "#17");
449 Assert.AreEqual (0, nestedTypeArgument.TypeArguments.Count, "#18");
451 typeArgument = reference.TypeArguments[1];
452 Assert.AreEqual ("System.String", typeArgument.BaseType, "#19");
453 Assert.AreEqual (0, typeArgument.ArrayRank, "#20");
454 Assert.IsNull (typeArgument.ArrayElementType, "#21");
455 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#22");
456 Assert.IsNotNull (typeArgument.TypeArguments, "#23");
457 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#24");
461 public void GenericTypeTest3 ()
463 CodeTypeReference reference = new CodeTypeReference (
464 "System.Nullable", new CodeTypeReference (typeof (int)));
465 Assert.AreEqual ("System.Nullable`1", reference.BaseType, "#1");
466 Assert.AreEqual (0, reference.ArrayRank, "#2");
467 Assert.IsNull (reference.ArrayElementType, "#3");
468 Assert.AreEqual (0, (int) reference.Options, "#4");
469 Assert.IsNotNull (reference.TypeArguments, "#5");
470 Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
472 CodeTypeReference typeArgument = reference.TypeArguments[0];
473 Assert.AreEqual ("System.Int32", typeArgument.BaseType, "#7");
474 Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
475 Assert.IsNull (typeArgument.ArrayElementType, "#9");
476 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
477 Assert.IsNotNull (typeArgument.TypeArguments, "#11");
478 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
482 public void GenericTypeTest4 ()
484 CodeTypeReference reference = new CodeTypeReference (
485 "System.Nullable`1", new CodeTypeReference (typeof (int)));
486 Assert.AreEqual ("System.Nullable`1", reference.BaseType, "#1");
487 Assert.AreEqual (0, reference.ArrayRank, "#2");
488 Assert.IsNull (reference.ArrayElementType, "#3");
489 Assert.AreEqual (0, (int) reference.Options, "#4");
490 Assert.IsNotNull (reference.TypeArguments, "#5");
491 Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
493 CodeTypeReference typeArgument = reference.TypeArguments[0];
494 Assert.AreEqual ("System.Int32", typeArgument.BaseType, "#7");
495 Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
496 Assert.IsNull (typeArgument.ArrayElementType, "#9");
497 Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
498 Assert.IsNotNull (typeArgument.TypeArguments, "#11");
499 Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
503 public void GenericTypeTest5 ()
505 CodeTypeReference reference = new CodeTypeReference (
506 typeof (int?).GetGenericTypeDefinition ());
507 Assert.AreEqual ("System.Nullable`1", reference.BaseType, "#1");
508 Assert.AreEqual (0, reference.ArrayRank, "#2");
509 Assert.IsNull (reference.ArrayElementType, "#3");
510 Assert.AreEqual (0, (int) reference.Options, "#4");
511 Assert.IsNotNull (reference.TypeArguments, "#5");
512 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
515 [Test (Description="Bug #523341")]
516 public void GenericTypeTest6 ()
518 CodeTypeReference reference = new CodeTypeReference ("System.Collections.List<System.Globalization.CultureInfo[]>");
519 Assert.AreEqual ("System.Collections.List<System.Globalization.CultureInfo[]>", reference.BaseType, "#1");
520 Assert.AreEqual (0, reference.ArrayRank, "#2");
521 Assert.IsNull (reference.ArrayElementType, "#3");
522 Assert.AreEqual (0, (int) reference.Options, "#4");
523 Assert.IsNotNull (reference.TypeArguments, "#5");
524 Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
529 public void BaseType_ArrayElementType ()
531 CodeTypeReference ctr = new CodeTypeReference ("System.Int32");
532 Assert.IsNull (ctr.ArrayElementType, "#1");
533 Assert.AreEqual (0, ctr.ArrayRank, "#2");
534 ctr.ArrayElementType = new CodeTypeReference ("System.String");
535 Assert.IsNotNull (ctr.ArrayElementType, "#3");
536 Assert.AreEqual (0, ctr.ArrayRank, "#4");
537 Assert.AreEqual ("System.Int32", ctr.BaseType, "#4");
539 Assert.AreEqual (-1, ctr.ArrayRank, "#5");
540 Assert.AreEqual ("System.Int32", ctr.BaseType, "#6");
542 Assert.AreEqual (1, ctr.ArrayRank, "#7");
543 Assert.AreEqual ("System.String", ctr.BaseType, "#8");
547 public void Null_ArrayElementType ()
549 CodeTypeReference ctr = new CodeTypeReference ((string) null, 0);
550 Assert.IsNotNull (ctr.ArrayElementType, "#1");
551 Assert.AreEqual (typeof(void).FullName, ctr.ArrayElementType.BaseType, "#2");
552 Assert.AreEqual (0, ctr.ArrayRank, "#3");
553 Assert.AreEqual (string.Empty, ctr.BaseType, "#4");
555 Assert.AreEqual (1, ctr.ArrayRank, "#5");
556 Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#6");
558 ctr = new CodeTypeReference ((string) null, 1);
559 Assert.IsNotNull (ctr.ArrayElementType, "#7");
560 Assert.AreEqual (typeof (void).FullName, ctr.ArrayElementType.BaseType, "#8");
561 Assert.AreEqual (1, ctr.ArrayRank, "#9");
562 Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#10");
564 ctr = new CodeTypeReference ((CodeTypeReference) null, 0);
565 Assert.IsNull (ctr.ArrayElementType, "#11");
566 Assert.AreEqual (0, ctr.ArrayRank, "#12");
567 Assert.AreEqual (string.Empty, ctr.BaseType, "#13");
569 Assert.AreEqual (1, ctr.ArrayRank, "#14");
570 Assert.AreEqual (string.Empty, ctr.BaseType, "#15");
572 ctr = new CodeTypeReference ((CodeTypeReference) null, 1);
573 Assert.IsNull (ctr.ArrayElementType, "#16");
574 Assert.AreEqual (1, ctr.ArrayRank, "#17");
575 Assert.AreEqual (string.Empty, ctr.BaseType, "#18");
579 public void Empty_ArrayElementType ()
581 CodeTypeReference ctr = new CodeTypeReference (string.Empty, 0);
582 Assert.IsNotNull (ctr.ArrayElementType, "#1");
583 Assert.AreEqual (typeof (void).FullName, ctr.ArrayElementType.BaseType, "#2");
584 Assert.AreEqual (0, ctr.ArrayRank, "#3");
585 Assert.AreEqual (string.Empty, ctr.BaseType, "#4");
587 Assert.AreEqual (1, ctr.ArrayRank, "#5");
588 Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#6");
590 ctr = new CodeTypeReference (string.Empty, 1);
591 Assert.IsNotNull (ctr.ArrayElementType, "#7");
592 Assert.AreEqual (typeof (void).FullName, ctr.ArrayElementType.BaseType, "#8");
593 Assert.AreEqual (1, ctr.ArrayRank, "#9");
594 Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#10");