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