.Net has built in compiling and code generation via the CodeDom namespace. The code generater takes a CodeDom object (a language inspecific program) and writes sourcecode for it in either vb or c# depending on which object set you use.
I'm interested in translating some c# code to vb using the codedom.
The c# to vb translator I wrote uses this code to translate:
VB Code:
Dim cs As New Microsoft.CSharp.CSharpCodeProvider Dim csParser As CodeDom.Compiler.ICodeParser = cs.CreateParser [B]Dim DOM As CodeDom.CodeCompileUnit = csParser.Parse(New IO.StringReader(tC.Text))[/B] Dim vb As New Microsoft.VisualBasic.VBCodeProvider Dim vbGenerator As CodeDom.Compiler.ICodeGenerator = vb.CreateGenerator() Dim Output As System.Text.StringBuilder() Dim Dest As New IO.StringWriter(Output) vbGenerator.GenerateCodeFromCompileUnit(DOM, Dest, New CodeDom.Compiler.CodeGeneratorOptions) tV.Text = Output.ToString
The bolded line is where execution stops and I get a Null Reference Exception. What gives?
The source of the C# code is a textbox names 'tc' and the vb output should go to 'tv'.
Let me know if this can be done... it should have no problems.




Reply With Quote