The #develop teamblog
#  Thursday, November 10, 2005

Daniel did a great video on what is possible with NRefactory. When I saw it, I felt that I had to build something with it - and so I set out to create a simple ASP.NET 2.0 page that converts C# source code to VB.NET source code (written in VB.NET, just to get my fingers dirty once in a while):

The code is pretty much the same as Daniel wrote, this time VB.NET:

Imports ICSharpCode.NRefactory.Parser
Imports ICSharpCode.NRefactory.Parser.AST
Imports ICSharpCode.NRefactory.PrettyPrinter

Imports System.IO

Partial Class CodeConvert Inherits System.Web.UI.Page

Protected Sub convertCode_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles convertCode.Click
   Dim input As New StringReader(inputTextBox.Text)
   Dim parser As IParser

   parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, input)
   parser.Parse()

   If (parser.Errors.count > 0) Then
      outputTextBox.Text = parser.Errors.ErrorOutput
      Exit Sub
   End If

   Dim cu As CompilationUnit, output As IOutputASTVisitor
   cu = parser.CompilationUnit

   output = CType(New VBNetOutputVisitor(), IOutputASTVisitor)
   cu.AcceptVisitor(output, DBNull.Value)
   outputTextBox.Text = output.Text
End Sub
End Class

The source code for the entire Web application is provided in the download at the end of this blog entry. Feel free to add more features to it, just note that the code is GPL-licensed, so please make your changes public.

CodeConvert.NET.zip (114.98 KB)

Categories: Chris
Thursday, November 10, 2005 5:56:58 PM (GMT Standard Time, UTC+00:00)  #    Comments [2]Tracked by:
http://laputa.sharpdevelop.net/CToVBNETCodeConverterNowOnline.aspx [Pingback]
"Convert C# 2.0 Code to VB.NET 8.0" (this.Pose() as Expert) [Trackback]

 



© Copyright 2012 SharpDevelop Core Team

Subscribe to this weblog's RSS feed with SharpReader, Radio Userland, NewsGator or any other aggregator listening on port 5335 by clicking this button.   RSS 2.0|Atom 1.0  Send mail to the author(s)

 

Copyright ©2000-2009 IC#Code. All rights reserved. Projects sponsored by AlphaSierraPapa.