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