[Mono-list] Problem with CodeDom
Alfonso Ali
isa@infomed.sld.cu
Tue, 18 Feb 2003 19:41:09 -0500
This is a multi-part message in MIME format.
------=_NextPart_000_0009_01C2D785.AF5E24C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hi everyone!!!
I'm getting the following result from the execution of the attached program:
1.- namespace ComputerSpeaks {
2.- using System;
3.- using System.Text;
4.-
5.- class HelloWorld {
6.-
7.- public static void () {
8.- System.Text.StringBuilder sbMessage = new
System.Text.StringBuilder();
9.- Console.WriteLine(sbMessage.ToString());
10.- }
11.- }
12.- }
The problem is in line 7:
public static void () {
^^
it doesn't generate the name of the method: Main.
I'm using mono 0.19 installed from rpm, taking a look at a snapshot more
recent than 0.19's version
(January 20, sorry but i was unable to download a more recent snapshot) I
can see in System/Microsoft.CSharp
CSharpGenerator.cs:
protected override void GenerateEntryPointMethod( CodeEntryPointMethod
method,
CodeTypeDeclaration declaration )
{
method.Name = "Main";
GenerateMethod( method, declaration );
}
and in the line 498 of the GenerateMethod method:
output.Write( method.Name );
so it seems to me that perhaps the problem is with the 0.19 code, can anyone
please confirm if the attached
program generate the correct result using a version of mono more recent than
0.19????
In case the problem with 0.19 is confirmed can anyone from the mono team
tell me when would be a 0.20 release???
TIA,
Ali
------=_NextPart_000_0009_01C2D785.AF5E24C0
Content-Type: application/octet-stream;
name="code2.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="code2.cs"
using System;=0A=
using System.CodeDom;=0A=
using System.CodeDom.Compiler;=0A=
using System.Text;=0A=
using System.IO;=0A=
using Microsoft.CSharp;=0A=
=0A=
class MyCode {=0A=
private CodeNamespace CurrentNameSpace;=0A=
=0A=
public MyCode() {=0A=
CurrentNameSpace =3D InitializeNameSpace("ComputerSpeaks");=0A=
CodeTypeDeclaration ctd =3D CreateClass("HelloWorld");=0A=
CurrentNameSpace.Types.Add(ctd);=0A=
=0A=
CodeEntryPointMethod mtd =3D CreateMethod();=0A=
ctd.Members.Add(mtd);=0A=
=0A=
CodeVariableDeclarationStatement vad =3D =
DeclareVariable(typeof(StringBuilder), "sbMessage");=0A=
mtd.Statements.Add(vad);=0A=
mtd.Statements.Add(new =
CodeSnippetExpression("Console.WriteLine(sbMessage.ToString())")); =0A=
}=0A=
=0A=
private CodeNamespace InitializeNameSpace(string Name) {=0A=
CodeNamespace CurrentNameSpace =3D new CodeNamespace(Name);=0A=
CurrentNameSpace.Imports.Add(new CodeNamespaceImport("System"));=0A=
CurrentNameSpace.Imports.Add(new =
CodeNamespaceImport("System.Text"));=0A=
return CurrentNameSpace;=0A=
}=0A=
=0A=
private CodeTypeDeclaration CreateClass(string Name) {=0A=
CodeTypeDeclaration ctd =3D new CodeTypeDeclaration(Name);=0A=
ctd.IsClass=3Dtrue;=0A=
ctd.Attributes =3D MemberAttributes.Public;=0A=
return ctd;=0A=
}=0A=
=0A=
private CodeEntryPointMethod CreateMethod() {=0A=
CodeEntryPointMethod mtd =3D new CodeEntryPointMethod();=0A=
mtd.Attributes =3D MemberAttributes.Public | MemberAttributes.Static;=0A=
return mtd;=0A=
}=0A=
=0A=
private CodeVariableDeclarationStatement DeclareVariable(System.Type =
DataType, string Name) {=0A=
CodeTypeReference tr =3D new CodeTypeReference(DataType);=0A=
CodeVariableDeclarationStatement Declaration =3D new =
CodeVariableDeclarationStatement(tr, Name);=0A=
CodeObjectCreateExpression newStatement =3D new =
CodeObjectCreateExpression();=0A=
newStatement.CreateType=3Dtr;=0A=
Declaration.InitExpression=3DnewStatement;=0A=
return Declaration;=0A=
}=0A=
=0A=
private string GenerateCode(ICodeGenerator CodeGenerator) {=0A=
CodeGeneratorOptions cop =3D new CodeGeneratorOptions();=0A=
cop.BracingStyle =3D "C";=0A=
cop.IndentString =3D " ";=0A=
StringBuilder sbCode =3D new StringBuilder();=0A=
StringWriter sw =3D new StringWriter(sbCode);=0A=
CodeGenerator.GenerateCodeFromNamespace(CurrentNameSpace, sw, cop);=0A=
return sbCode.ToString();=0A=
}=0A=
=0A=
=0A=
public string CSharpCode {=0A=
get {=0A=
CSharpCodeProvider provider =3D new CSharpCodeProvider();=0A=
ICodeGenerator codeGen =3D provider.CreateGenerator();=0A=
return GenerateCode(codeGen);=0A=
}=0A=
}=0A=
=0A=
}=0A=
=0A=
class Test {=0A=
public static void Main() {=0A=
MyCode codigo =3D new MyCode();=0A=
Console.WriteLine(codigo.CSharpCode);=0A=
}=0A=
}=0A=
------=_NextPart_000_0009_01C2D785.AF5E24C0--