Merge pull request #1225 from strawd/bug22307
[mono.git] / mcs / class / System / Test / System.CodeDom.Compiler / CodeGeneratorFromTypeTestBase.cs
1 //
2 // Base class for CodeGenerator.GenerateCodeFromType unit tests.
3 //
4 // Authors:
5 // Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (c) Novell
8 //
9
10 using System;
11 using System.CodeDom;
12 using System.CodeDom.Compiler;
13 using System.Reflection;
14 using System.Security;
15 using System.Security.Principal;
16
17 using NUnit.Framework;
18
19 namespace MonoTests.System.CodeDom.Compiler
20 {
21         public abstract class CodeGeneratorFromTypeTestBase : CodeGeneratorTestBase
22         {
23                 protected abstract CodeTypeDeclaration TypeDeclaration
24                 {
25                         get;
26                 }
27
28                 [Test]
29                 public abstract void DefaultTypeTest ();
30
31                 [Test]
32                 public abstract void NullTypeTest ();
33
34                 [Test]
35                 public abstract void SimpleTypeTest ();
36
37                 [Test]
38                 public abstract void DerivedTypeTest ();
39
40                 [Test]
41                 public abstract void AttributesAndTypeTest ();
42
43                 [Test]
44                 public abstract void EventMembersTypeTest1 ();
45
46                 [Test]
47                 public abstract void EventMembersTypeTest2 ();
48
49                 [Test]
50                 public abstract void EventImplementationTypes ();
51
52                 [Test]
53                 public abstract void EventPrivateImplementationType ();
54
55                 [Test]
56                 public abstract void EventImplementationTypeOrder ();
57
58                 [Test]
59                 public abstract void FieldMembersAttributesTest ();
60
61                 [Test]
62                 public abstract void FieldMembersTypeTest ();
63
64                 [Test]
65                 public abstract void FieldNewSlotTest ();
66
67                 [Test]
68                 public abstract void PropertyMembersTypeTest1 ();
69
70                 [Test]
71                 public abstract void PropertyMembersTypeTest2 ();
72
73                 [Test]
74                 public abstract void PropertyMembersTypeGetOnly ();
75
76                 [Test]
77                 public abstract void PropertyMembersTypeSetOnly ();
78
79                 [Test]
80                 public abstract void PropertyMembersTypeGetSet ();
81
82                 [Test]
83                 public abstract void PropertyMembersTypeFamilyOrAssembly ();
84
85                 [Test]
86                 public abstract void PropertyMembersTypeAssembly ();
87
88                 [Test]
89                 public abstract void PropertyParametersTest ();
90
91                 [Test]
92                 public abstract void PropertyIndexerTest1 ();
93
94                 [Test]
95                 public abstract void PropertyIndexerTest2 ();
96
97                 [Test]
98                 public abstract void PropertyIndexerGetOnly ();
99
100                 [Test]
101                 public abstract void PropertyIndexerSetOnly ();
102
103                 [Test]
104                 public abstract void PropertyImplementationTypes ();
105
106                 [Test]
107                 public abstract void PropertyOverloadsTest1 ();
108
109                 [Test]
110                 public abstract void PropertyOverloadsTest2 ();
111
112                 [Test]
113                 public abstract void PropertyOverloadsTest3 ();
114
115                 [Test]
116                 public abstract void PropertyPrivateImplementationType ();
117
118                 [Test]
119                 public abstract void PropertyImplementationTypeOrder ();
120
121                 [Test]
122                 public abstract void PropertyNewSlotTest ();
123
124                 [Test]
125                 public abstract void MethodMembersTypeTest1 ();
126
127                 [Test]
128                 public abstract void MethodMembersTypeTest2 ();
129
130                 [Test]
131                 public abstract void MethodMembersTypeTest3 ();
132
133                 [Test]
134                 public abstract void MethodImplementationTypes ();
135
136                 [Test]
137                 public abstract void MethodOverloadsTest1 ();
138
139                 [Test]
140                 public abstract void MethodOverloadsTest2 ();
141
142                 [Test]
143                 public abstract void MethodOverloadsTest3 ();
144
145                 [Test]
146                 public abstract void MethodPrivateImplementationType ();
147
148                 [Test]
149                 public abstract void MethodImplementationTypeOrder ();
150
151                 [Test]
152                 public abstract void MethodParamArrayAttribute ();
153
154                 [Test]
155                 public abstract void MethodReturnTypeAttributes ();
156
157                 [Test]
158                 public abstract void MethodNewSlotTest ();
159
160                 [Test]
161                 public abstract void ConstructorAttributesTest ();
162
163                 [Test]
164                 public abstract void ConstructorParametersTest ();
165
166                 [Test]
167                 public abstract void ConstructorParameterAttributesTest ();
168
169                 [Test]
170                 public abstract void BaseConstructorSingleArg ();
171
172                 [Test]
173                 public abstract void BaseConstructorMultipleArgs ();
174
175                 [Test]
176                 public abstract void ChainedConstructorSingleArg ();
177
178                 [Test]
179                 public abstract void ChainedConstructorMultipleArgs ();
180
181                 [Test]
182                 public abstract void TypeConstructorTest ();
183
184                 [Test]
185                 public abstract void EntryPointMethodTest ();
186                 
187                 [Test]
188                 public abstract void PartialTypeTest ();
189
190                 protected string GenerateDefaultType (CodeGeneratorOptions options)
191                 {
192                         return GenerateCodeFromType (TypeDeclaration, options);
193                 }
194
195                 protected string GenerateNullType (CodeGeneratorOptions options)
196                 {
197                         return GenerateCodeFromType (null, options);
198                 }
199
200                 protected string GenerateSimpleType (CodeGeneratorOptions options)
201                 {
202                         TypeDeclaration.Name = "Test1";
203                         return GenerateCodeFromType (TypeDeclaration, options);
204                 }
205
206                 protected string GenerateDerivedType (CodeGeneratorOptions options)
207                 {
208                         TypeDeclaration.Name = "Test1";
209                         TypeDeclaration.TypeAttributes |= TypeAttributes.NestedFamily | 
210                                 TypeAttributes.Abstract;
211                         TypeDeclaration.BaseTypes.Add (new CodeTypeReference (typeof (int)));
212                         TypeDeclaration.BaseTypes.Add (new CodeTypeReference (typeof (IIdentity)));
213                         TypeDeclaration.BaseTypes.Add (new CodeTypeReference (typeof (string)));
214                         TypeDeclaration.BaseTypes.Add (new CodeTypeReference (typeof (IPermission)));
215                         return GenerateCodeFromType (TypeDeclaration, options);
216                 }
217
218                 protected string GenerateAttributesAndType (CodeGeneratorOptions options)
219                 {
220                         TypeDeclaration.Name = "Test1";
221
222                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
223                         attrDec.Name = "A";
224                         TypeDeclaration.CustomAttributes.Add (attrDec);
225
226                         attrDec = new CodeAttributeDeclaration ();
227                         attrDec.Name = "B";
228                         TypeDeclaration.CustomAttributes.Add (attrDec);
229
230                         return GenerateCodeFromType (TypeDeclaration, options);
231                 }
232
233                 protected string GenerateEventMembersType1 (CodeGeneratorOptions options)
234                 {
235                         TypeDeclaration.Name = "Test1";
236
237                         CodeMemberEvent evt = new CodeMemberEvent ();
238
239                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
240                         attrDec.Name = "A";
241                         evt.CustomAttributes.Add (attrDec);
242
243                         attrDec = new CodeAttributeDeclaration ();
244                         attrDec.Name = "B";
245                         evt.CustomAttributes.Add (attrDec);
246
247                         TypeDeclaration.Members.Add (evt);
248
249                         return GenerateCodeFromType (TypeDeclaration, options);
250                 }
251
252                 protected string GenerateEventMembersType2 (CodeGeneratorOptions options)
253                 {
254                         TypeDeclaration.Name = "Test1";
255
256                         CodeMemberEvent evt = new CodeMemberEvent ();
257                         evt.Name = "Click";
258                         evt.Attributes = MemberAttributes.Public | MemberAttributes.Override
259                                 | MemberAttributes.Static | MemberAttributes.Abstract |
260                                 MemberAttributes.New;
261                         evt.Type = new CodeTypeReference (typeof (int));
262                         TypeDeclaration.Members.Add (evt);
263
264                         return GenerateCodeFromType (TypeDeclaration, options);
265                 }
266
267                 protected string GenerateEventImplementationTypes (CodeGeneratorOptions options)
268                 {
269                         TypeDeclaration.Name = "Test1";
270
271                         CodeMemberEvent evt = new CodeMemberEvent ();
272                         evt.Name = "Click";
273                         evt.Attributes = MemberAttributes.FamilyAndAssembly;
274                         evt.Type = new CodeTypeReference (typeof (int));
275                         evt.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
276                         evt.ImplementationTypes.Add (new CodeTypeReference ("IWhatever"));
277                         TypeDeclaration.Members.Add (evt);
278
279                         return GenerateCodeFromType (TypeDeclaration, options);
280                 }
281
282                 protected string GenerateEventPrivateImplementationType (CodeGeneratorOptions options)
283                 {
284                         TypeDeclaration.Name = "Test1";
285
286                         CodeMemberEvent evt = new CodeMemberEvent ();
287                         evt.Name = "Click";
288                         evt.Attributes = MemberAttributes.Family | MemberAttributes.Overloaded;
289                         evt.Type = new CodeTypeReference (typeof (int));
290                         evt.PrivateImplementationType = new CodeTypeReference (typeof (int));
291                         TypeDeclaration.Members.Add (evt);
292
293                         return GenerateCodeFromType (TypeDeclaration, options);
294                 }
295
296                 protected string GenerateEventImplementationTypeOrder (CodeGeneratorOptions options)
297                 {
298                         TypeDeclaration.Name = "Test1";
299
300                         CodeMemberEvent evt = new CodeMemberEvent ();
301                         evt.Name = "Click";
302                         evt.Attributes = MemberAttributes.Public | MemberAttributes.Overloaded;
303                         evt.Type = new CodeTypeReference (typeof (int));
304                         evt.PrivateImplementationType = new CodeTypeReference (typeof (int));
305                         evt.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
306                         TypeDeclaration.Members.Add (evt);
307
308                         return GenerateCodeFromType (TypeDeclaration, options);
309                 }
310
311                 protected string GenerateFieldMembersAttributes (CodeGeneratorOptions options)
312                 {
313                         TypeDeclaration.Name = "Test1";
314
315                         CodeMemberField fld = new CodeMemberField ();
316
317                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
318                         attrDec.Name = "A";
319                         fld.CustomAttributes.Add (attrDec);
320
321                         attrDec = new CodeAttributeDeclaration ();
322                         attrDec.Name = "B";
323                         fld.CustomAttributes.Add (attrDec);
324
325                         TypeDeclaration.Members.Add (fld);
326
327                         return GenerateCodeFromType (TypeDeclaration, options);
328                 }
329
330                 protected string GenerateFieldMembersType (MemberAttributes memberAttributes, CodeGeneratorOptions options)
331                 {
332                         TypeDeclaration.Name = "Test1";
333
334                         CodeMemberField fld = new CodeMemberField ();
335                         fld.Name = "Name";
336                         fld.Attributes = memberAttributes;
337                         fld.Type = new CodeTypeReference (typeof (int));
338                         fld.InitExpression = new CodePrimitiveExpression (2);
339                         TypeDeclaration.Members.Add (fld);
340
341                         return GenerateCodeFromType (TypeDeclaration, options);
342                 }
343
344                 protected string GeneratePropertyMembersAttributes (CodeGeneratorOptions options)
345                 {
346                         TypeDeclaration.Name = "Test1";
347
348                         CodeMemberProperty property = new CodeMemberProperty ();
349                         TypeDeclaration.Members.Add (property);
350
351                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
352                         attrDec.Name = "A";
353                         property.CustomAttributes.Add (attrDec);
354
355                         attrDec = new CodeAttributeDeclaration ();
356                         attrDec.Name = "B";
357                         property.CustomAttributes.Add (attrDec);
358
359                         return GenerateCodeFromType (TypeDeclaration, options);
360                 }
361
362                 protected string GenerateAbstractProperty (CodeGeneratorOptions options)
363                 {
364                         TypeDeclaration.Name = "Test1";
365                         TypeDeclaration.TypeAttributes = TypeAttributes.Abstract | TypeAttributes.Public;
366
367                         CodeMemberProperty property = new CodeMemberProperty ();
368                         property.Name = "Name";
369                         property.Attributes = MemberAttributes.Public | MemberAttributes.Abstract;
370                         property.HasGet = true;
371                         property.HasSet = true;
372                         property.Type = new CodeTypeReference (typeof (string));
373
374                         TypeDeclaration.Members.Add (property);
375
376                         return GenerateCodeFromType (TypeDeclaration, options);
377                 }
378
379                 protected string GenerateStaticProperty (CodeGeneratorOptions options)
380                 {
381                         TypeDeclaration.Name = "Test1";
382                         TypeDeclaration.TypeAttributes = TypeAttributes.Public;
383
384                         CodeMemberProperty property = new CodeMemberProperty ();
385                         property.Name = "Name";
386                         property.Attributes = MemberAttributes.Public | MemberAttributes.Static;
387                         property.HasSet = true;
388                         property.Type = new CodeTypeReference (typeof (string));
389
390                         TypeDeclaration.Members.Add (property);
391
392                         return GenerateCodeFromType (TypeDeclaration, options);
393                 }
394
395                 protected string GeneratePropertyMembersType (MemberAttributes memberAttributes, bool hasGet, bool hasSet, CodeGeneratorOptions options)
396                 {
397                         TypeDeclaration.Name = "Test1";
398
399                         CodeMemberProperty property = new CodeMemberProperty ();
400                         property.Name = "Name";
401                         property.Attributes = memberAttributes;
402                         property.HasGet = hasGet;
403                         property.HasSet = hasSet;
404                         property.Type = new CodeTypeReference (typeof (int));
405                         TypeDeclaration.Members.Add (property);
406
407                         return GenerateCodeFromType (TypeDeclaration, options);
408                 }
409
410                 protected string GeneratePropertyParameters (CodeGeneratorOptions options)
411                 {
412                         TypeDeclaration.Name = "Test1";
413
414                         CodeMemberProperty property = new CodeMemberProperty ();
415                         property.Name = "Name";
416                         property.Attributes = MemberAttributes.Public;
417                         property.Type = new CodeTypeReference (typeof (int));
418
419                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
420                                 typeof (object), "value1");
421                         property.Parameters.Add (param);
422
423                         param = new CodeParameterDeclarationExpression (
424                                 typeof (int), "value2");
425                         param.Direction = FieldDirection.Ref;
426                         property.Parameters.Add (param);
427
428                         TypeDeclaration.Members.Add (property);
429
430                         return GenerateCodeFromType (TypeDeclaration, options);
431                 }
432
433                 protected string GeneratePropertyIndexer (MemberAttributes memberAttributes, bool hasGet, bool hasSet, bool addParameters, CodeGeneratorOptions options)
434                 {
435                         TypeDeclaration.Name = "Test1";
436
437                         CodeMemberProperty property = new CodeMemberProperty ();
438                         // ensure case-insensitive comparison is done on name of property
439                         property.Name = "iTem";
440                         property.Attributes = memberAttributes;
441                         property.HasGet = hasGet;
442                         property.HasSet = hasSet;
443                         property.Type = new CodeTypeReference (typeof (int));
444                         TypeDeclaration.Members.Add (property);
445
446                         if (addParameters) {
447                                 CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
448                                         typeof (object), "value1");
449                                 property.Parameters.Add (param);
450
451                                 param = new CodeParameterDeclarationExpression (
452                                         typeof (int), "value2");
453                                 param.Direction = FieldDirection.Ref;
454                                 property.Parameters.Add (param);
455                         }
456
457                         return GenerateCodeFromType (TypeDeclaration, options);
458                 }
459
460                 protected string GeneratePropertyImplementationTypes (CodeGeneratorOptions options)
461                 {
462                         TypeDeclaration.Name = "Test1";
463
464                         CodeMemberProperty property = new CodeMemberProperty ();
465                         property.Name = "Name";
466                         property.Attributes = MemberAttributes.Public;
467                         property.Type = new CodeTypeReference (typeof (int));
468                         property.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
469                         property.ImplementationTypes.Add (new CodeTypeReference ("IWhatever"));
470                         TypeDeclaration.Members.Add (property);
471
472                         return GenerateCodeFromType (TypeDeclaration, options);
473                 }
474
475                 protected string GeneratePropertyOverloads1 (CodeGeneratorOptions options)
476                 {
477                         TypeDeclaration.Name = "Test1";
478
479                         CodeMemberProperty property = new CodeMemberProperty ();
480                         property.Name = "Name";
481                         property.Attributes = MemberAttributes.Family | MemberAttributes.Overloaded;
482                         property.Type = new CodeTypeReference (typeof (int));
483                         TypeDeclaration.Members.Add (property);
484
485                         return GenerateCodeFromType (TypeDeclaration, options);
486                 }
487
488                 protected string GeneratePropertyOverloads2 (CodeGeneratorOptions options)
489                 {
490                         TypeDeclaration.Name = "Test1";
491
492                         CodeMemberProperty property = new CodeMemberProperty ();
493                         property.Name = "Name";
494                         property.Attributes = MemberAttributes.Public;
495                         property.Type = new CodeTypeReference (typeof (int));
496                         TypeDeclaration.Members.Add (property);
497
498                         property = new CodeMemberProperty ();
499                         property.Name = "Name";
500                         property.Attributes = MemberAttributes.Private;
501                         property.Type = new CodeTypeReference (typeof (int));
502                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
503                                 typeof (object), "value1");
504                         property.Parameters.Add (param);
505                         TypeDeclaration.Members.Add (property);
506
507                         return GenerateCodeFromType (TypeDeclaration, options);
508                 }
509
510                 protected string GeneratePropertyOverloads3 (CodeGeneratorOptions options)
511                 {
512                         TypeDeclaration.Name = "Test1";
513
514                         CodeMemberProperty property = new CodeMemberProperty ();
515                         property.Name = "Name";
516                         property.Attributes = MemberAttributes.Public;
517                         property.Type = new CodeTypeReference (typeof (int));
518                         TypeDeclaration.Members.Add (property);
519
520                         property = new CodeMemberProperty ();
521                         property.Name = "Name";
522                         property.Attributes = MemberAttributes.Private;
523                         property.Type = new CodeTypeReference (typeof (int));
524                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
525                                 typeof (object), "value1");
526                         property.Parameters.Add (param);
527                         property.PrivateImplementationType = new CodeTypeReference (typeof (int));
528                         TypeDeclaration.Members.Add (property);
529
530                         return GenerateCodeFromType (TypeDeclaration, options);
531                 }
532
533                 protected string GeneratePropertyPrivateImplementationType (CodeGeneratorOptions options)
534                 {
535                         TypeDeclaration.Name = "Test1";
536
537                         CodeMemberProperty property = new CodeMemberProperty ();
538                         property.Name = "Item";
539                         property.Attributes = MemberAttributes.Public | MemberAttributes.Overloaded;
540                         property.Type = new CodeTypeReference (typeof (int));
541                         property.PrivateImplementationType = new CodeTypeReference (typeof (int));
542                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
543                                 typeof (object), "value1");
544                         property.Parameters.Add (param);
545                         TypeDeclaration.Members.Add (property);
546
547                         return GenerateCodeFromType (TypeDeclaration, options);
548                 }
549
550                 protected string GeneratePropertyImplementationTypeOrder (CodeGeneratorOptions options)
551                 {
552                         TypeDeclaration.Name = "Test1";
553
554                         CodeMemberProperty property = new CodeMemberProperty ();
555                         property.Name = "Item";
556                         property.Attributes = MemberAttributes.Public | MemberAttributes.Overloaded;
557                         property.Type = new CodeTypeReference (typeof (int));
558                         property.PrivateImplementationType = new CodeTypeReference (typeof (int));
559                         property.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
560                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
561                                 typeof (object), "value1");
562                         property.Parameters.Add (param);
563                         TypeDeclaration.Members.Add (property);
564
565                         return GenerateCodeFromType (TypeDeclaration, options);
566                 }
567
568                 protected string GenerateMethodMembersType1 (CodeGeneratorOptions options)
569                 {
570                         TypeDeclaration.Name = "Test1";
571
572                         CodeMemberMethod method = new CodeMemberMethod ();
573
574                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
575                         attrDec.Name = "A";
576                         method.CustomAttributes.Add (attrDec);
577
578                         attrDec = new CodeAttributeDeclaration ();
579                         attrDec.Name = "B";
580                         method.CustomAttributes.Add (attrDec);
581
582                         TypeDeclaration.Members.Add (method);
583
584                         return GenerateCodeFromType (TypeDeclaration, options);
585                 }
586
587                 protected string GenerateMethodMembersType2 (CodeGeneratorOptions options)
588                 {
589                         TypeDeclaration.Name = "Test1";
590
591                         CodeMemberMethod method = new CodeMemberMethod ();
592                         method.Name = "Something";
593                         method.Attributes = MemberAttributes.Public;
594                         method.ReturnType = new CodeTypeReference (typeof (int));
595
596                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
597                                 typeof (object), "value1");
598                         method.Parameters.Add (param);
599
600                         param = new CodeParameterDeclarationExpression (
601                                 typeof (object), "value2");
602                         param.Direction = FieldDirection.In;
603                         method.Parameters.Add (param);
604
605                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
606                         param.Direction = FieldDirection.Out;
607                         method.Parameters.Add (param);
608
609                         param = new CodeParameterDeclarationExpression (typeof (int), "count");
610                         param.Direction = FieldDirection.Ref;
611                         method.Parameters.Add (param);
612
613                         TypeDeclaration.Members.Add (method);
614
615                         return GenerateCodeFromType (TypeDeclaration, options);
616                 }
617
618                 protected string GenerateMethodMembersType3 (CodeGeneratorOptions options)
619                 {
620
621                         TypeDeclaration.Name = "Test1";
622
623                         CodeMemberMethod method = new CodeMemberMethod ();
624                         method.Name = "Something";
625                         method.Attributes = MemberAttributes.Public;
626                         method.ReturnType = new CodeTypeReference (typeof (int));
627
628                         // first parameter
629                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
630                                 typeof (object), "value");
631                         method.Parameters.Add (param);
632
633                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
634                         attrDec.Name = "A";
635                         param.CustomAttributes.Add (attrDec);
636
637                         attrDec = new CodeAttributeDeclaration ();
638                         attrDec.Name = "B";
639                         param.CustomAttributes.Add (attrDec);
640
641                         // second parameter
642                         param = new CodeParameterDeclarationExpression (typeof (int), null);
643                         param.Direction = FieldDirection.Out;
644                         method.Parameters.Add (param);
645
646                         attrDec = new CodeAttributeDeclaration ();
647                         attrDec.Name = "C";
648                         attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
649                                 new CodePrimitiveExpression (false)));
650                         attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
651                                 new CodePrimitiveExpression (true)));
652                         param.CustomAttributes.Add (attrDec);
653
654                         attrDec = new CodeAttributeDeclaration ();
655                         attrDec.Name = "D";
656                         param.CustomAttributes.Add (attrDec);
657
658                         TypeDeclaration.Members.Add (method);
659
660                         return GenerateCodeFromType (TypeDeclaration, options);
661                 }
662
663                 protected string GenerateMethodImplementationTypes (CodeGeneratorOptions options)
664                 {
665                         TypeDeclaration.Name = "Test1";
666
667                         CodeMemberMethod method = new CodeMemberMethod ();
668                         method.Name = "Execute";
669                         method.Attributes = MemberAttributes.Assembly;
670                         method.ReturnType = new CodeTypeReference (typeof (int));
671                         method.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
672                         method.ImplementationTypes.Add (new CodeTypeReference ("IWhatever"));
673                         TypeDeclaration.Members.Add (method);
674
675                         return GenerateCodeFromType (TypeDeclaration, options);
676                 }
677
678                 protected string GenerateMethodOverloads1 (CodeGeneratorOptions options)
679                 {
680                         TypeDeclaration.Name = "Test1";
681
682                         CodeMemberMethod method = new CodeMemberMethod ();
683                         method.Name = "Execute";
684                         method.Attributes = MemberAttributes.Assembly | MemberAttributes.Overloaded;
685                         method.ReturnType = new CodeTypeReference (typeof (int));
686                         TypeDeclaration.Members.Add (method);
687
688                         return GenerateCodeFromType (TypeDeclaration, options);
689                 }
690
691                 protected string GenerateMethodOverloads2 (CodeGeneratorOptions options)
692                 {
693                         TypeDeclaration.Name = "Test1";
694
695                         CodeMemberMethod method = new CodeMemberMethod ();
696                         method.Name = "Execute";
697                         method.Attributes = MemberAttributes.Public;
698                         TypeDeclaration.Members.Add (method);
699
700                         method = new CodeMemberMethod ();
701                         method.Name = "Execute";
702                         method.Attributes = MemberAttributes.Private;
703                         method.ReturnType = new CodeTypeReference (typeof (int));
704                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
705                                 typeof (object), "value1");
706                         method.Parameters.Add (param);
707                         TypeDeclaration.Members.Add (method);
708
709                         return GenerateCodeFromType (TypeDeclaration, options);
710                 }
711
712                 protected string GenerateMethodOverloads3 (CodeGeneratorOptions options)
713                 {
714                         TypeDeclaration.Name = "Test1";
715
716                         CodeMemberMethod method = new CodeMemberMethod ();
717                         method.Name = "Execute";
718                         method.Attributes = MemberAttributes.Public;
719                         TypeDeclaration.Members.Add (method);
720
721                         method = new CodeMemberMethod ();
722                         method.Name = "Execute";
723                         method.Attributes = MemberAttributes.Private;
724                         method.ReturnType = new CodeTypeReference (typeof (int));
725                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
726                                 typeof (object), "value1");
727                         method.Parameters.Add (param);
728                         method.PrivateImplementationType = new CodeTypeReference (typeof (int));
729                         TypeDeclaration.Members.Add (method);
730
731                         return GenerateCodeFromType (TypeDeclaration, options);
732                 }
733
734                 protected string GenerateMethodPrivateImplementationType (CodeGeneratorOptions options)
735                 {
736                         TypeDeclaration.Name = "Test1";
737
738                         CodeMemberMethod method = new CodeMemberMethod ();
739                         method.Name = "Execute";
740                         method.Attributes = MemberAttributes.Public | MemberAttributes.Overloaded;
741                         method.ReturnType = new CodeTypeReference (typeof (int));
742                         method.PrivateImplementationType = new CodeTypeReference (typeof (int));
743                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
744                                 typeof (object), "value1");
745                         method.Parameters.Add (param);
746                         TypeDeclaration.Members.Add (method);
747
748                         return GenerateCodeFromType (TypeDeclaration, options);
749                 }
750
751                 protected string GenerateMethodImplementationTypeOrder (CodeGeneratorOptions options)
752                 {
753                         TypeDeclaration.Name = "Test1";
754
755                         CodeMemberMethod method = new CodeMemberMethod ();
756                         method.Name = "Execute";
757                         method.Attributes = MemberAttributes.Public;
758                         method.ReturnType = new CodeTypeReference (typeof (int));
759                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
760                                 typeof (object), "value1");
761                         method.Parameters.Add (param);
762                         method.PrivateImplementationType = new CodeTypeReference (typeof (int));
763                         method.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
764                         TypeDeclaration.Members.Add (method);
765
766                         return GenerateCodeFromType (TypeDeclaration, options);
767                 }
768
769                 protected string GenerateMethodParamArrayAttribute (CodeGeneratorOptions options)
770                 {
771                         TypeDeclaration.Name = "Test1";
772
773                         CodeMemberMethod method = new CodeMemberMethod ();
774                         method.Name = "Something";
775                         method.Attributes = MemberAttributes.Public;
776                         method.ReturnType = new CodeTypeReference (typeof (int));
777
778                         // first parameter
779                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
780                                 typeof (object), "value");
781                         param.Direction = FieldDirection.Out;
782                         method.Parameters.Add (param);
783
784                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
785                         attrDec.Name = "A";
786                         param.CustomAttributes.Add (attrDec);
787
788                         attrDec = new CodeAttributeDeclaration ();
789                         attrDec.Name = typeof (ParamArrayAttribute).FullName;
790                         param.CustomAttributes.Add (attrDec);
791
792                         attrDec = new CodeAttributeDeclaration ();
793                         attrDec.Name = "B";
794                         param.CustomAttributes.Add (attrDec);
795
796                         // second parameter
797                         param = new CodeParameterDeclarationExpression (typeof (int), null);
798                         param.Direction = FieldDirection.Ref;
799                         method.Parameters.Add (param);
800
801                         attrDec = new CodeAttributeDeclaration ();
802                         attrDec.Name = "C";
803                         param.CustomAttributes.Add (attrDec);
804
805                         TypeDeclaration.Members.Add (method);
806
807                         return GenerateCodeFromType (TypeDeclaration, options);
808                 }
809
810                 protected string GenerateMethodReturnTypeAttributes (CodeGeneratorOptions options)
811                 {
812                         TypeDeclaration.Name = "Test1";
813
814                         CodeMemberMethod method = new CodeMemberMethod ();
815                         method.Name = "Execute";
816                         method.Attributes = MemberAttributes.Public;
817                         method.ReturnType = new CodeTypeReference (typeof (int));
818                         TypeDeclaration.Members.Add (method);
819
820                         // method custom attributes
821                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
822                         attrDec.Name = "A";
823                         method.CustomAttributes.Add (attrDec);
824
825                         attrDec = new CodeAttributeDeclaration ();
826                         attrDec.Name = "B";
827                         method.CustomAttributes.Add (attrDec);
828
829                         attrDec = new CodeAttributeDeclaration ();
830                         attrDec.Name = typeof (ParamArrayAttribute).FullName;
831                         method.CustomAttributes.Add (attrDec);
832
833                         // return TypeDeclaration custom attributes
834                         attrDec = new CodeAttributeDeclaration ();
835                         attrDec.Name = "C";
836                         attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
837                                 new CodePrimitiveExpression (false)));
838                         attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
839                                 new CodePrimitiveExpression (true)));
840                         method.ReturnTypeCustomAttributes.Add (attrDec);
841
842                         attrDec = new CodeAttributeDeclaration ();
843                         attrDec.Name = typeof (ParamArrayAttribute).FullName;
844                         method.ReturnTypeCustomAttributes.Add (attrDec);
845
846                         attrDec = new CodeAttributeDeclaration ();
847                         attrDec.Name = "D";
848                         method.ReturnTypeCustomAttributes.Add (attrDec);
849
850                         return GenerateCodeFromType (TypeDeclaration, options);
851                 }
852
853                 protected string GenerateConstructorAttributes (CodeGeneratorOptions options)
854                 {
855                         TypeDeclaration.Name = "Test1";
856
857                         CodeConstructor ctor = new CodeConstructor ();
858
859                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
860                         attrDec.Name = "A";
861                         ctor.CustomAttributes.Add (attrDec);
862
863                         attrDec = new CodeAttributeDeclaration ();
864                         attrDec.Name = "B";
865                         ctor.CustomAttributes.Add (attrDec);
866
867                         TypeDeclaration.Members.Add (ctor);
868
869                         return GenerateCodeFromType (TypeDeclaration, options);
870                 }
871
872                 protected string GenerateMethodNewSlot (CodeGeneratorOptions options)
873                 {
874                         TypeDeclaration.Name = "Test1";
875
876                         CodeMemberMethod method = new CodeMemberMethod ();
877                         method.Name = "Execute";
878                         method.Attributes = MemberAttributes.Public | MemberAttributes.New;
879                         method.ReturnType = new CodeTypeReference (typeof (int));
880                         TypeDeclaration.Members.Add (method);
881
882                         return GenerateCodeFromType (TypeDeclaration, options);
883                 }
884
885                 protected string GenerateConstructorParameters (CodeGeneratorOptions options)
886                 {
887                         TypeDeclaration.Name = "Test1";
888
889                         CodeConstructor ctor = new CodeConstructor ();
890                         ctor.Name = "Whatever";
891                         ctor.Attributes = MemberAttributes.Public;
892
893                         // scope and vtable modifiers should be ignored
894                         ctor.Attributes |= MemberAttributes.Abstract | MemberAttributes.Const
895                                 | MemberAttributes.Final | MemberAttributes.New
896                                 | MemberAttributes.Overloaded | MemberAttributes.Override
897                                 | MemberAttributes.Static;
898
899                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
900                                 typeof (object), "value1");
901                         ctor.Parameters.Add (param);
902
903                         param = new CodeParameterDeclarationExpression (
904                                 typeof (object), "value2");
905                         param.Direction = FieldDirection.In;
906                         ctor.Parameters.Add (param);
907
908                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
909                         param.Direction = FieldDirection.Out;
910                         ctor.Parameters.Add (param);
911
912                         param = new CodeParameterDeclarationExpression (typeof (int), "count");
913                         param.Direction = FieldDirection.Ref;
914                         ctor.Parameters.Add (param);
915
916                         TypeDeclaration.Members.Add (ctor);
917
918                         return GenerateCodeFromType (TypeDeclaration, options);
919                 }
920
921                 protected string GenerateConstructorParameterAttributes (CodeGeneratorOptions options)
922                 {
923                         TypeDeclaration.Name = "Test1";
924
925                         CodeConstructor ctor = new CodeConstructor ();
926                         ctor.Name = "Something";
927                         ctor.Attributes = MemberAttributes.Private;
928
929                         // first parameter
930                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
931                                 typeof (object), "value");
932                         ctor.Parameters.Add (param);
933
934                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
935                         attrDec.Name = "A";
936                         param.CustomAttributes.Add (attrDec);
937
938                         attrDec = new CodeAttributeDeclaration ();
939                         attrDec.Name = "B";
940                         param.CustomAttributes.Add (attrDec);
941
942                         // second parameter
943                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
944                         param.Direction = FieldDirection.Out;
945                         ctor.Parameters.Add (param);
946
947                         attrDec = new CodeAttributeDeclaration ();
948                         attrDec.Name = "C";
949                         attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
950                                 new CodePrimitiveExpression (false)));
951                         attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
952                                 new CodePrimitiveExpression (true)));
953                         param.CustomAttributes.Add (attrDec);
954
955                         attrDec = new CodeAttributeDeclaration ();
956                         attrDec.Name = "D";
957                         param.CustomAttributes.Add (attrDec);
958
959                         TypeDeclaration.Members.Add (ctor);
960
961                         return GenerateCodeFromType (TypeDeclaration, options);
962                 }
963
964                 protected string GenerateBaseConstructor (bool multipleArgs, CodeGeneratorOptions options)
965                 {
966                         TypeDeclaration.Name = "Test1";
967
968                         CodeConstructor ctor = new CodeConstructor ();
969                         ctor.Name = "Something";
970                         ctor.Attributes = MemberAttributes.Family;
971
972                         // first parameter
973                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
974                                 typeof (object), "value1");
975                         ctor.Parameters.Add (param);
976
977                         // second parameter
978                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
979                         param.Direction = FieldDirection.Out;
980                         ctor.Parameters.Add (param);
981
982                         // base ctor args
983                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
984
985                         if (multipleArgs) {
986                                 ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value2"));
987                         }
988
989                         TypeDeclaration.Members.Add (ctor);
990
991                         return GenerateCodeFromType (TypeDeclaration, options);
992                 }
993
994                 protected string GenerateChainedConstructor (bool multipleArgs, CodeGeneratorOptions options)
995                 {
996                         TypeDeclaration.Name = "Test1";
997
998                         CodeConstructor ctor = new CodeConstructor ();
999                         ctor.Name = "Something";
1000                         ctor.Attributes = MemberAttributes.Public;
1001
1002                         // first parameter
1003                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
1004                                 typeof (object), "value1");
1005                         ctor.Parameters.Add (param);
1006
1007                         // second parameter
1008                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
1009                         param.Direction = FieldDirection.Out;
1010                         ctor.Parameters.Add (param);
1011
1012                         // implementation types should be ignored on ctors
1013                         ctor.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
1014
1015                         // chained ctor args
1016                         ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
1017
1018                         if (multipleArgs) {
1019                                 ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value2"));
1020                         }
1021
1022                         // should be ignored as chained ctor args should take precedence over base 
1023                         // ctor args
1024                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value3"));
1025
1026                         TypeDeclaration.Members.Add (ctor);
1027
1028                         return GenerateCodeFromType (TypeDeclaration, options);
1029                 }
1030
1031                 protected string GenerateTypeConstructor (CodeGeneratorOptions options)
1032                 {
1033                         TypeDeclaration.Name = "Test1";
1034
1035                         CodeTypeConstructor typeCtor = new CodeTypeConstructor ();
1036                         // access, scope and vtable modifiers should be ignored
1037                         typeCtor.Attributes |= MemberAttributes.Public | MemberAttributes.Abstract
1038                                 | MemberAttributes.Const | MemberAttributes.Final
1039                                 | MemberAttributes.New | MemberAttributes.Overloaded
1040                                 | MemberAttributes.Override | MemberAttributes.Static;
1041                         TypeDeclaration.Members.Add (typeCtor);
1042
1043                         // custom attributes
1044                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
1045                         attrDec.Name = "A";
1046                         typeCtor.CustomAttributes.Add (attrDec);
1047
1048                         attrDec = new CodeAttributeDeclaration ();
1049                         attrDec.Name = "B";
1050                         typeCtor.CustomAttributes.Add (attrDec);
1051
1052                         // parameter should be ignored
1053                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
1054                                 typeof (object), "value1");
1055                         typeCtor.Parameters.Add (param);
1056
1057                         // implementation types should be ignored on type ctors
1058                         typeCtor.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
1059
1060                         // private immplementation type should be ignored on type ctors
1061                         typeCtor.PrivateImplementationType = new CodeTypeReference (typeof (int));
1062
1063                         // return type should be ignored on type ctors
1064                         typeCtor.ReturnType = new CodeTypeReference (typeof (int));
1065
1066                         // return TypeDeclaration custom attributes
1067                         attrDec = new CodeAttributeDeclaration ();
1068                         attrDec.Name = "A";
1069                         attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
1070                                 new CodePrimitiveExpression (false)));
1071                         attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
1072                                 new CodePrimitiveExpression (true)));
1073                         typeCtor.ReturnTypeCustomAttributes.Add (attrDec);
1074
1075                         return GenerateCodeFromType (TypeDeclaration, options);
1076                 }
1077
1078                 protected string GenerateEntryPointMethod (CodeGeneratorOptions options)
1079                 {
1080                         TypeDeclaration.Name = "Test1";
1081
1082                         CodeEntryPointMethod method = new CodeEntryPointMethod ();
1083                         method.Name = "Something"; // should be ignored in C# and VB
1084                         method.Attributes = MemberAttributes.Private ; // should be ignored in C# and VB
1085                         method.ReturnType = new CodeTypeReference (typeof (int)); // should be ignored in C# 1.x and VB 1.x and 2.x
1086
1087                         // parameters on entry point are ignored in C# and VB
1088                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
1089                                 typeof (object), "value1");
1090                         method.Parameters.Add (param);
1091
1092                         // custom attributes on entry point are ignored in C# 1.x and VB 1.x
1093                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
1094                         attrDec.Name = "A";
1095                         method.CustomAttributes.Add (attrDec);
1096
1097                         CodeVariableDeclarationStatement v = new CodeVariableDeclarationStatement ("Test+InnerType", "x");
1098                         method.Statements.Add (v);
1099
1100                         TypeDeclaration.Members.Add (method);
1101
1102                         /*
1103                         CodeTypeDeclaration nestedType = new CodeTypeDeclaration ("InnerType");
1104                         TypeDeclaration.Members.Add (nestedType);
1105                         */
1106
1107                         return GenerateCodeFromType (TypeDeclaration, options);
1108                 }
1109
1110                 protected string GenerateGenericCodeTypeReferences (CodeGeneratorOptions options)
1111                 {
1112                         CodeTypeDeclaration td = new CodeTypeDeclaration ("Test");
1113                         CodeMemberField f = new CodeMemberField (
1114                         new CodeTypeReference ("System.Nullable",
1115                         new CodeTypeReference (typeof (int))),
1116                         "Foo");
1117                         td.Members.Add (f);
1118                         CodeMemberField f2 = new CodeMemberField (
1119                         new CodeTypeReference (typeof (int?).GetGenericTypeDefinition ()),
1120                         "Bar");
1121                         td.Members.Add (f2);
1122                         return GenerateCodeFromType (td, options);
1123                 }
1124                 
1125                 protected string GeneratePartialType (CodeGeneratorOptions options)
1126                 {
1127                         TypeDeclaration.Name = "Test1";
1128                         TypeDeclaration.IsPartial = true;
1129                         return GenerateCodeFromType (TypeDeclaration, options);
1130                 }
1131         }
1132 }