[Mono-bugs] [Bug 76286][Wis] New - codedom issue with nullable types and CodeGeneratorOptions

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Thu Sep 29 23:12:21 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by mmorano at mikeandwan.us.

http://bugzilla.ximian.com/show_bug.cgi?id=76286

--- shadow/76286	2005-09-29 23:12:21.000000000 -0400
+++ shadow/76286.tmp.24686	2005-09-29 23:12:21.000000000 -0400
@@ -0,0 +1,169 @@
+Bug#: 76286
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: mmorano at mikeandwan.us               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: codedom issue with nullable types and CodeGeneratorOptions
+
+Description of Problem:
+
+Tried using codedom to generate a basic test class.  When trying to create
+a member that is of type int?, the code that is generated for the nullable
+type is incorrect.
+
+
+Steps to reproduce the problem:
+1. Compile the following program with: 
+   gmcs -target:exe -r:System -out:t.exe Program.cs
+
+Here is Program.cs:
+
+using Microsoft.CSharp;
+using System;
+using System.CodeDom;
+using System.CodeDom.Compiler;
+using System.IO;
+
+namespace codegentest
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            CodeGeneratorOptions codeGeneratorOptions = new
+CodeGeneratorOptions();
+            codeGeneratorOptions.BlankLinesBetweenMembers = true;
+            codeGeneratorOptions.BracingStyle = "C";
+            codeGeneratorOptions.ElseOnClosing = false;
+            codeGeneratorOptions.IndentString = "\t";
+
+            // create the root of our compilation graph
+            CodeCompileUnit ccu = new CodeCompileUnit();
+
+            // prepare the main namespace for the classes to generate
+            CodeNamespace cn = new CodeNamespace("MyNamespace");
+
+            cn.Imports.Add(new CodeNamespaceImport("System"));
+            cn.Imports.Add(new
+CodeNamespaceImport("System.Collections.Generic"));
+            cn.Imports.Add(new CodeNamespaceImport("System.Data"));
+
+            // now link our namespace to the root of the compilation unit
+            ccu.Namespaces.Add(cn);
+
+            // prepare a test class
+            CodeTypeDeclaration testClass = new CodeTypeDeclaration("MyClass");
+            testClass.IsClass = true;
+
+            // prepare a field
+            CodeMemberField field = new CodeMemberField(typeof(int?),
+                                                        "myField");
+
+            testClass.Members.Add(field);
+
+            cn.Types.Add(testClass);
+
+            // now prepare the writer
+            CSharpCodeProvider provider = new CSharpCodeProvider();
+
+            StreamWriter sw = new StreamWriter("test.cs");
+
+            provider.GenerateCodeFromCompileUnit(ccu,
+                                                 sw,
+                                                 codeGeneratorOptions);
+
+            sw.Close();
+        }
+    }
+}
+
+
+
+Actual Results:
+
+//
+------------------------------------------------------------------------------
+//  <autogenerated>
+//      This code was generated by a tool.
+//      Mono Runtime Version: 2.0.50215.16
+//
+//      Changes to this file may cause incorrect behavior and will be lost if
+//      the code is regenerated.
+//  </autogenerated>
+//
+------------------------------------------------------------------------------
+
+namespace MyNamespace {
+        using System;
+        using System.Collections.Generic;
+        using System.Data;
+
+        public class MyClass {
+
+                private System.Nullable`1 myField;
+        }
+
+}
+
+
+Notice the type in the generated class is:  System.Nullable`1
+
+Also notice that the '{' is on the same line as the namespace and class
+declaration, rather than starting on a separate line, as configured in the
+CodeGeneratorOptions (obviously, this is a very minor issue, as it does not
+affect the correctness of the generated code).
+
+
+Expected Results:
+
+The following is the result of running this on ms.net 2:
+
+
+//------------------------------------------------------------------------------//
+<auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:2.0.50727.26
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+namespace MyNamespace
+{
+        using System;
+        using System.Collections.Generic;
+        using System.Data;
+
+
+        public class MyClass
+        {
+
+                private System.Nullable<int> myField;
+        }
+}
+
+
+Notice that it generates Nullable<int> and the braces are positioned as
+specified by the CodeGeneratorOptions.
+
+Perhaps this is on hold until the nullable type issue is straightened out,
+as miguel referenced the following in his blog:
+http://blogs.msdn.com/somasegar/archive/2005/08/11/450640.aspx
+
+
+How often does this happen? 
+
+always
+
+Additional Information:


More information about the mono-bugs mailing list