|
-
Mar 16th, 2006, 10:20 PM
#1
Thread Starter
Fanatic Member
automated C# to vb.net translation
.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.
-
Mar 17th, 2006, 12:17 AM
#2
Re: automated C# to vb.net translation
An article about that in DevX:
Generate .NET Code in Any Language Using CodeDOM
In that example, they used GenerateCodeFromNamespace and GenerateCodeFromType, but you can also use: GenerateCodeFromExpression, GenerateCodeFromCompileUnit, GenerateCodeFromStatement.
There is an example to download also.
-
Mar 17th, 2006, 02:05 AM
#3
Thread Starter
Fanatic Member
Re: automated C# to vb.net translation
 Originally Posted by jcis
An article about that in DevX:
Generate .NET Code in Any Language Using CodeDOM
In that example, they used GenerateCodeFromNamespace and GenerateCodeFromType, but you can also use: GenerateCodeFromExpression, GenerateCodeFromCompileUnit, GenerateCodeFromStatement.
There is an example to download also.
I'm most interested in GenerateCodeFromCompileUnit, but the problem I'm having is CreateParser is returning a null reference instead of a parser which can provide a CodeCompileUnit that can be outputted to code.
Is there any other way to get a CodeCompileUnit from C# or VB.Net code or from a compiled assembly?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|