Author: gert
Date: 2005-06-26 11:13:54 -0400 (Sun, 26 Jun 2005)
New Revision: 46518

Modified:
   trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs
   trunk/mcs/class/System/Microsoft.CSharp/ChangeLog
   trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog
   trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs
Log:
* CodeGeneratorFromTypeTest.cs: Added tests to verify code generated for 
events, fields, properties, methods and ctors to match MS.NET.
* CSharpCodeGenerator.cs: Fixed generated code for events, fields, properties,
methods and ctors to match MS.NET.


Modified: trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs
===================================================================
--- trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs      
2005-06-26 11:41:24 UTC (rev 46517)
+++ trunk/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs      
2005-06-26 15:13:54 UTC (rev 46518)
@@ -161,7 +161,8 @@
                        GenerateCompileUnitStart (compileUnit);
 
                        if (compileUnit.AssemblyCustomAttributes.Count > 0) {
-                               OutputAttributes 
(compileUnit.AssemblyCustomAttributes, "assembly: ");
+                               OutputAttributes 
(compileUnit.AssemblyCustomAttributes, 
+                                       "assembly: ", false);
                                Output.WriteLine ("");
                        }
 
@@ -525,8 +526,7 @@
 
                protected override void GenerateEvent( CodeMemberEvent 
eventRef, CodeTypeDeclaration declaration )
                {
-                       if (eventRef.CustomAttributes.Count > 0)
-                               OutputAttributeDeclarations 
(eventRef.CustomAttributes);
+                       OutputAttributes (eventRef.CustomAttributes, null, 
false);
 
                        OutputMemberAccessModifier (eventRef.Attributes);
                        OutputMemberScopeModifier (eventRef.Attributes | 
MemberAttributes.Final); // Don't output "virtual"
@@ -539,8 +539,7 @@
                {
                        TextWriter output = Output;
 
-                       if (field.CustomAttributes.Count > 0)
-                               OutputAttributeDeclarations( 
field.CustomAttributes );
+                       OutputAttributes (field.CustomAttributes, null, false);
 
                        if (IsCurrentEnum)
                                Output.Write(GetSafeName (field.Name));
@@ -581,8 +580,7 @@
                {
                        TextWriter output = Output;
 
-                       if (method.CustomAttributes.Count > 0)
-                               OutputAttributeDeclarations( 
method.CustomAttributes );
+                       OutputAttributes (method.CustomAttributes, null, false);
 
                        if (method.ReturnTypeCustomAttributes.Count > 0)
                                OutputAttributeDeclarations( 
method.ReturnTypeCustomAttributes );
@@ -634,12 +632,11 @@
                {
                        TextWriter output = Output;
 
-                       if (property.CustomAttributes.Count > 0)
-                               OutputAttributeDeclarations( 
property.CustomAttributes );
+                       OutputAttributes (property.CustomAttributes, null, 
false);
 
                        MemberAttributes attributes = property.Attributes;
-                       OutputMemberAccessModifier( attributes );
-                       OutputMemberScopeModifier( attributes );
+                       OutputMemberAccessModifier (attributes);
+                       OutputMemberScopeModifier (attributes);
 
                        if (property.Name == "Item")
                        {
@@ -672,7 +669,7 @@
                                        GenerateStatements 
(property.GetStatements);
 
                                        --Indent;
-                                       output.WriteLine ("}");
+                                       output.WriteLine ('}');
                                }
 
                                if (property.HasSet)
@@ -683,53 +680,40 @@
                                        GenerateStatements 
(property.SetStatements);
 
                                        --Indent;
-                                       output.WriteLine ("}");
+                                       output.WriteLine ('}');
                                }
                        }
 
                        --Indent;
-                       output.WriteLine ("}");
+                       output.WriteLine ('}');
                }
 
                protected override void GenerateConstructor( CodeConstructor 
constructor,
                                                             
CodeTypeDeclaration declaration )
                {
-                       if (constructor.CustomAttributes.Count > 0)
-                               OutputAttributeDeclarations 
(constructor.CustomAttributes);
+                       OutputAttributes (constructor.CustomAttributes, null, 
false);
 
                        OutputMemberAccessModifier (constructor.Attributes);
-                       Output.Write (GetSafeName (CurrentTypeName) + " (");
+                       Output.Write (GetSafeName (CurrentTypeName) + "(");
                        OutputParameters (constructor.Parameters);
-                       Output.Write (") ");
-                       if (constructor.ChainedConstructorArgs.Count > 0)
-                       {
-                               Output.Write(": this(");
-                               bool first = true;
-                               foreach (CodeExpression ex in 
constructor.ChainedConstructorArgs)
-                               {
-                                       if (!first)
-                                               Output.Write(", ");
-                                       first = false;
-                                       GenerateExpression(ex);
-                               }
-                               
-                               Output.Write(") ");
-                       };
-                       if (constructor.BaseConstructorArgs.Count > 0)
-                       {
-                               Output.Write(": base(");
-                               bool first = true;
-                               foreach (CodeExpression ex in 
constructor.BaseConstructorArgs)
-                               {
-                                       if (!first)
-                                               Output.Write(", ");
-                                       first = false;
-                                       GenerateExpression(ex);
-                               }
-                               
-                               Output.Write(") ");
-                       };
-                       Output.WriteLine ("{");
+                       Output.Write (")");
+                       if (constructor.BaseConstructorArgs.Count > 0) {
+                               Output.WriteLine (" : ");
+                               Indent += 2;
+                               Output.Write ("base(");
+                               OutputExpressionList 
(constructor.BaseConstructorArgs);
+                               Output.Write (')');
+                               Indent -= 2;
+                       }
+                       if (constructor.ChainedConstructorArgs.Count > 0) {
+                               Output.WriteLine (" : ");
+                               Indent += 2;
+                               Output.Write("this(");
+                               OutputExpressionList 
(constructor.ChainedConstructorArgs);
+                               Output.Write(')');
+                               Indent -= 2;
+                       }
+                       Output.WriteLine (" {");
                        Indent++;
                        GenerateStatements (constructor.Statements);
                        Indent--;
@@ -750,7 +734,7 @@
                        TextWriter output = Output;
                        CodeTypeDelegate del = declaration as CodeTypeDelegate;
 
-                       OutputAttributes (declaration.CustomAttributes, null);
+                       OutputAttributes (declaration.CustomAttributes, null, 
false);
 
                        TypeAttributes attributes = declaration.TypeAttributes;
                        OutputTypeAttributes( attributes,
@@ -850,6 +834,23 @@
                        Output.Write (']');
                }
 
+               private void OutputAttributes 
(CodeAttributeDeclarationCollection attributes, string prefix, bool inline)
+               {
+                       foreach (CodeAttributeDeclaration att in attributes) {
+                               GenerateAttributeDeclarationsStart (attributes);
+                               if (prefix != null) {
+                                       Output.Write (prefix);
+                               }
+                               OutputAttributeDeclaration (att);
+                               GenerateAttributeDeclarationsEnd (attributes);
+                               if (inline) {
+                                       Output.Write (" ");
+                               } else {
+                                       Output.WriteLine ();
+                               }
+                       }
+               }
+
                private void OutputAttributeDeclaration 
(CodeAttributeDeclaration attribute)
                {
                        Output.Write (attribute.Name.Replace ('+', '.'));
@@ -868,19 +869,6 @@
                        Output.Write (')');
                }
 
-               private void OutputAttributes 
(CodeAttributeDeclarationCollection attributes, string prefix)
-               {
-                       foreach (CodeAttributeDeclaration att in attributes) {
-                               GenerateAttributeDeclarationsStart (attributes);
-                               if (prefix != null) {
-                                       Output.Write ("assembly: ");
-                               }
-                               OutputAttributeDeclaration (att);
-                               GenerateAttributeDeclarationsEnd (attributes);
-                               Output.WriteLine ();
-                       }
-               }
-
                protected override void OutputType( CodeTypeReference type )
                {
                        Output.Write( GetTypeOutput( type ) );
@@ -901,8 +889,7 @@
 
                protected override void GenerateParameterDeclarationExpression 
(CodeParameterDeclarationExpression e)
                {
-                       if (e.CustomAttributes != null && 
e.CustomAttributes.Count > 0)
-                               OutputAttributeDeclarations 
(e.CustomAttributes);
+                       OutputAttributes (e.CustomAttributes, null, true);
                        OutputDirection (e.Direction);
                        OutputType (e.Type);
                        Output.Write (' ');

Modified: trunk/mcs/class/System/Microsoft.CSharp/ChangeLog
===================================================================
--- trunk/mcs/class/System/Microsoft.CSharp/ChangeLog   2005-06-26 11:41:24 UTC 
(rev 46517)
+++ trunk/mcs/class/System/Microsoft.CSharp/ChangeLog   2005-06-26 15:13:54 UTC 
(rev 46518)
@@ -1,3 +1,8 @@
+2005-06-26 Gert Driesen <[EMAIL PROTECTED]>
+
+       * CSharpCodeGenerator.cs: Fixed generated code for events, fields,
+       properties, methods and ctors to match MS.NET.
+
 2005-06-25 Gert Driesen <[EMAIL PROTECTED]>
 
        * CSharpCodeGenerator.cs: Also modified generated code for type-level

Modified: trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog      2005-06-26 
11:41:24 UTC (rev 46517)
+++ trunk/mcs/class/System/Test/Microsoft.CSharp/ChangeLog      2005-06-26 
15:13:54 UTC (rev 46518)
@@ -1,3 +1,8 @@
+2005-06-26  Gert Driesen <[EMAIL PROTECTED]>
+
+       * CodeGeneratorFromTypeTest.cs: Added tests to verify code generated
+       for events, fields, properties, methods and ctors to match MS.NET.
+
 2005-06-25  Gert Driesen <[EMAIL PROTECTED]>
 
        * CodeGeneratorFromTypeTest.cs: Added tests to verify code generated

Modified: 
trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs
===================================================================
--- trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs   
2005-06-26 11:41:24 UTC (rev 46517)
+++ trunk/mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs   
2005-06-26 15:13:54 UTC (rev 46518)
@@ -79,9 +79,562 @@
 
                        Generate ();
                        Assertion.AssertEquals (string.Format 
(CultureInfo.InvariantCulture,
-                               "[A()]{0}[B()]{0}public class Test1 
{{{0}}}{0}", writer.NewLine), Code);
+                               "[A()]{0}"
+                               + "[B()]{0}"
+                               + "public class Test1 {{{0}"
+                               + "}}{0}", writer.NewLine), Code);
                }
 
+               [Test]
+               public void EventMembersTypeTest1 ()
+               {
+                       type.Name = "Test1";
+
+                       CodeMemberEvent evt = new CodeMemberEvent ();
+
+                       CodeAttributeDeclaration attrDec = new 
CodeAttributeDeclaration ();
+                       attrDec.Name = "A";
+                       evt.CustomAttributes.Add (attrDec);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "B";
+                       evt.CustomAttributes.Add (attrDec);
+
+                       type.Members.Add (evt);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    [A()]{0}"
+                               + "    [B()]{0}"
+                               + "    private event void ;{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void EventMembersTypeTest2 ()
+               {
+                       type.Name = "Test1";
+
+                       CodeMemberEvent evt = new CodeMemberEvent ();
+                       evt.Name = "OnClick";
+                       evt.Attributes = MemberAttributes.Public;
+                       evt.Type = new CodeTypeReference (typeof (int));
+                       type.Members.Add (evt);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public event int OnClick;{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void FieldMembersTypeTest1 ()
+               {
+                       type.Name = "Test1";
+
+                       CodeMemberField fld = new CodeMemberField ();
+
+                       CodeAttributeDeclaration attrDec = new 
CodeAttributeDeclaration ();
+                       attrDec.Name = "A";
+                       fld.CustomAttributes.Add (attrDec);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "B";
+                       fld.CustomAttributes.Add (attrDec);
+
+                       type.Members.Add (fld);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    [A()]{0}"
+                               + "    [B()]{0}"
+                               + "    private void ;{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void FieldMembersTypeTest2 ()
+               {
+                       type.Name = "Test1";
+
+                       CodeMemberField fld = new CodeMemberField ();
+                       fld.Name = "Name";
+                       fld.Attributes = MemberAttributes.Public;
+                       fld.Type = new CodeTypeReference (typeof (int));
+                       type.Members.Add (fld);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public int Name;{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void PropertyMembersTypeTest1 ()
+               {
+                       type.Name = "Test1";
+
+                       CodeMemberProperty property = new CodeMemberProperty ();
+
+                       CodeAttributeDeclaration attrDec = new 
CodeAttributeDeclaration ();
+                       attrDec.Name = "A";
+                       property.CustomAttributes.Add (attrDec);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "B";
+                       property.CustomAttributes.Add (attrDec);
+
+                       type.Members.Add (property);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    [A()]{0}"
+                               + "    [B()]{0}"
+                               + "    private void  {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void PropertyMembersTypeTest2 ()
+               {
+                       type.Name = "Test1";
+
+                       CodeMemberProperty property = new CodeMemberProperty ();
+                       property.Name = "Name";
+                       property.Attributes = MemberAttributes.Public;
+                       property.Type = new CodeTypeReference (typeof (int));
+                       type.Members.Add (property);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public virtual int Name {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void MethodMembersTypeTest1 ()
+               {
+                       type.Name = "Test1";
+
+                       CodeMemberMethod method = new CodeMemberMethod ();
+
+                       CodeAttributeDeclaration attrDec = new 
CodeAttributeDeclaration ();
+                       attrDec.Name = "A";
+                       method.CustomAttributes.Add (attrDec);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "B";
+                       method.CustomAttributes.Add (attrDec);
+
+                       type.Members.Add (method);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    [A()]{0}"
+                               + "    [B()]{0}"
+                               + "    private void () {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void MethodMembersTypeTest2 ()
+               {
+                       type.Name = "Test1";
+
+                       CodeMemberMethod method = new CodeMemberMethod ();
+                       method.Name = "Something";
+                       method.Attributes = MemberAttributes.Public;
+                       method.ReturnType = new CodeTypeReference (typeof 
(int));
+
+                       CodeParameterDeclarationExpression param = new 
CodeParameterDeclarationExpression (
+                               typeof (object), "value1");
+                       method.Parameters.Add (param);
+
+                       param = new CodeParameterDeclarationExpression (
+                               typeof (object), "value2");
+                       param.Direction = FieldDirection.In;
+                       method.Parameters.Add (param);
+
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "index");
+                       param.Direction = FieldDirection.Out;
+                       method.Parameters.Add (param);
+
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "count");
+                       param.Direction = FieldDirection.Ref;
+                       method.Parameters.Add (param);
+
+                       type.Members.Add (method);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public virtual int Something(object 
value1, object value2, out int index, ref int count) {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void MethodMembersTypeTest3 ()
+               {
+                       type.Name = "Test1";
+
+                       CodeMemberMethod method = new CodeMemberMethod ();
+                       method.Name = "Something";
+                       method.Attributes = MemberAttributes.Public;
+                       method.ReturnType = new CodeTypeReference (typeof 
(int));
+
+                       // first parameter
+                       CodeParameterDeclarationExpression param = new 
CodeParameterDeclarationExpression (
+                               typeof (object), "value");
+                       method.Parameters.Add (param);
+
+                       CodeAttributeDeclaration attrDec = new 
CodeAttributeDeclaration ();
+                       attrDec.Name = "A";
+                       param.CustomAttributes.Add (attrDec);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "B";
+                       param.CustomAttributes.Add (attrDec);
+
+                       // second parameter
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "index");
+                       param.Direction = FieldDirection.Out;
+                       method.Parameters.Add (param);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "C";
+                       attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
+                               new CodePrimitiveExpression (false)));
+                       attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
+                               new CodePrimitiveExpression (true)));
+                       param.CustomAttributes.Add (attrDec);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "D";
+                       param.CustomAttributes.Add (attrDec);
+
+                       type.Members.Add (method);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public virtual int Something([A()] [B()] 
object value, [C(A1=false, A2=true)] [D()] out int index) {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void ConstructorAttributesTest ()
+               {
+                       type.Name = "Test1";
+
+                       CodeConstructor ctor = new CodeConstructor ();
+
+                       CodeAttributeDeclaration attrDec = new 
CodeAttributeDeclaration ();
+                       attrDec.Name = "A";
+                       ctor.CustomAttributes.Add (attrDec);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "B";
+                       ctor.CustomAttributes.Add (attrDec);
+
+                       type.Members.Add (ctor);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    [A()]{0}"
+                               + "    [B()]{0}"
+                               + "    private Test1() {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void ConstructorParametersTest ()
+               {
+                       type.Name = "Test1";
+
+                       CodeConstructor ctor = new CodeConstructor ();
+                       ctor.Name = "Whatever";
+                       ctor.Attributes = MemberAttributes.Public;
+
+                       CodeParameterDeclarationExpression param = new 
CodeParameterDeclarationExpression (
+                               typeof (object), "value1");
+                       ctor.Parameters.Add (param);
+
+                       param = new CodeParameterDeclarationExpression (
+                               typeof (object), "value2");
+                       param.Direction = FieldDirection.In;
+                       ctor.Parameters.Add (param);
+
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "index");
+                       param.Direction = FieldDirection.Out;
+                       ctor.Parameters.Add (param);
+
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "count");
+                       param.Direction = FieldDirection.Ref;
+                       ctor.Parameters.Add (param);
+
+                       type.Members.Add (ctor);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public Test1(object value1, object 
value2, out int index, ref int count) {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void ConstructorParameterAttributesTest ()
+               {
+                       type.Name = "Test1";
+
+                       CodeConstructor ctor = new CodeConstructor ();
+                       ctor.Name = "Something";
+                       ctor.Attributes = MemberAttributes.Public;
+
+                       // first parameter
+                       CodeParameterDeclarationExpression param = new 
CodeParameterDeclarationExpression (
+                               typeof (object), "value");
+                       ctor.Parameters.Add (param);
+
+                       CodeAttributeDeclaration attrDec = new 
CodeAttributeDeclaration ();
+                       attrDec.Name = "A";
+                       param.CustomAttributes.Add (attrDec);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "B";
+                       param.CustomAttributes.Add (attrDec);
+
+                       // second parameter
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "index");
+                       param.Direction = FieldDirection.Out;
+                       ctor.Parameters.Add (param);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "C";
+                       attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
+                               new CodePrimitiveExpression (false)));
+                       attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
+                               new CodePrimitiveExpression (true)));
+                       param.CustomAttributes.Add (attrDec);
+
+                       attrDec = new CodeAttributeDeclaration ();
+                       attrDec.Name = "D";
+                       param.CustomAttributes.Add (attrDec);
+
+                       type.Members.Add (ctor);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public Test1([A()] [B()] object value, 
[C(A1=false, A2=true)] [D()] out int index) {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void BaseConstructorSingleArg ()
+               {
+                       type.Name = "Test1";
+
+                       CodeConstructor ctor = new CodeConstructor ();
+                       ctor.Name = "Something";
+                       ctor.Attributes = MemberAttributes.Public;
+
+                       // first parameter
+                       CodeParameterDeclarationExpression param = new 
CodeParameterDeclarationExpression (
+                               typeof (object), "value1");
+                       ctor.Parameters.Add (param);
+
+                       // second parameter
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "value2");
+                       param.Direction = FieldDirection.Out;
+                       ctor.Parameters.Add (param);
+
+                       // base ctor args
+                       ctor.BaseConstructorArgs.Add (new 
CodeVariableReferenceExpression ("value1"));
+
+                       type.Members.Add (ctor);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public Test1(object value1, out int 
value2) : {0}"
+                               + "            base(value1) {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void BaseConstructorMultipleArgs ()
+               {
+                       type.Name = "Test1";
+
+                       CodeConstructor ctor = new CodeConstructor ();
+                       ctor.Name = "Something";
+                       ctor.Attributes = MemberAttributes.Public;
+
+                       // first parameter
+                       CodeParameterDeclarationExpression param = new 
CodeParameterDeclarationExpression (
+                               typeof (object), "value1");
+                       ctor.Parameters.Add (param);
+
+                       // second parameter
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "value2");
+                       param.Direction = FieldDirection.Out;
+                       ctor.Parameters.Add (param);
+
+                       // base ctor args
+                       ctor.BaseConstructorArgs.Add (new 
CodeVariableReferenceExpression ("value1"));
+                       ctor.BaseConstructorArgs.Add (new 
CodeVariableReferenceExpression ("value2"));
+
+                       type.Members.Add (ctor);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public Test1(object value1, out int 
value2) : {0}"
+                               + "            base(value1, value2) {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void ChainedConstructorSingleArg ()
+               {
+                       type.Name = "Test1";
+
+                       CodeConstructor ctor = new CodeConstructor ();
+                       ctor.Name = "Something";
+                       ctor.Attributes = MemberAttributes.Public;
+
+                       // first parameter
+                       CodeParameterDeclarationExpression param = new 
CodeParameterDeclarationExpression (
+                               typeof (object), "value1");
+                       ctor.Parameters.Add (param);
+
+                       // second parameter
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "value2");
+                       param.Direction = FieldDirection.Out;
+                       ctor.Parameters.Add (param);
+
+                       // chained ctor args
+                       ctor.ChainedConstructorArgs.Add (new 
CodeVariableReferenceExpression ("value1"));
+
+                       type.Members.Add (ctor);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public Test1(object value1, out int 
value2) : {0}"
+                               + "            this(value1) {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void ChainedConstructorMultipleArgs ()
+               {
+                       type.Name = "Test1";
+
+                       CodeConstructor ctor = new CodeConstructor ();
+                       ctor.Name = "Something";
+                       ctor.Attributes = MemberAttributes.Public;
+
+                       // first parameter
+                       CodeParameterDeclarationExpression param = new 
CodeParameterDeclarationExpression (
+                               typeof (object), "value1");
+                       ctor.Parameters.Add (param);
+
+                       // second parameter
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "value2");
+                       param.Direction = FieldDirection.Out;
+                       ctor.Parameters.Add (param);
+
+                       // chained ctor args
+                       ctor.ChainedConstructorArgs.Add (new 
CodeVariableReferenceExpression ("value1"));
+                       ctor.ChainedConstructorArgs.Add (new 
CodeVariableReferenceExpression ("value2"));
+
+                       type.Members.Add (ctor);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public Test1(object value1, out int 
value2) : {0}"
+                               + "            this(value1, value2) {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
+               [Test]
+               public void BaseAndChainedConstructorArg ()
+               {
+                       type.Name = "Test1";
+
+                       CodeConstructor ctor = new CodeConstructor ();
+                       ctor.Name = "Something";
+                       ctor.Attributes = MemberAttributes.Public;
+
+                       // first parameter
+                       CodeParameterDeclarationExpression param = new 
CodeParameterDeclarationExpression (
+                               typeof (object), "value1");
+                       ctor.Parameters.Add (param);
+
+                       // second parameter
+                       param = new CodeParameterDeclarationExpression (typeof 
(int), "value2");
+                       param.Direction = FieldDirection.Out;
+                       ctor.Parameters.Add (param);
+
+                       // base ctor args
+                       ctor.BaseConstructorArgs.Add (new 
CodeVariableReferenceExpression ("value1"));
+
+                       // should be ignored as base ctor args should take 
precedence over 
+                       // chained ctor args
+                       ctor.ChainedConstructorArgs.Add (new 
CodeVariableReferenceExpression ("value1"));
+                       ctor.ChainedConstructorArgs.Add (new 
CodeVariableReferenceExpression ("value2"));
+
+                       type.Members.Add (ctor);
+
+                       Generate ();
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "public class Test1 {{{0}"
+                               + "    {0}"
+                               + "    public Test1(object value1, out int 
value2) : {0}"
+                               + "            base(value1) : {0}"
+                               + "            this(value1, value2) {{{0}"
+                               + "    }}{0}"
+                               + "}}{0}", writer.NewLine), Code);
+               }
+
                /*
                [Test]
                public void ReferencedTest ()

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to