C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Tools »

Convert C# to VB.NET


Posted Date: 02 Apr 2007    Resource Type: Code Snippets    Category: Tools
Author: Tony JohnMember Level: Diamond    
Rating: 1 out of 5Points: 10



This sample shows how to programmatically convert C# code to VB.NET and viceversa. I am using the sharpdevelop's ICSharpCode.NRefactory namespaces here to convert code. You can download the assemblies from http://www.icsharpcode.net/OpenSource/SD/Download/

The first parameter of the method is the actual code that need to be converted. Second parameter specifies whether to convert from C# to VB.NET or viceversa. Pass 'true' to convert from C# to VB.NET. Pass 'false' to convert from VB.NET to C#.

Private Function ConvertCodeSnippet(ByVal codeToConvert as string, ByVal csharpToVb As Boolean) as string
Dim input As New StringReader(codeToConvert)
Dim parser As IParser

parser = ParserFactory.CreateParser(IIf(csharpToVb, SupportedLanguage.CSharp, SupportedLanguage.VBNet), input)

parser.Parse()

If (parser.Errors.count > 0) Then
return parser.Errors.ErrorOutput
End If

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

output = IIf(csharpToVb, CType(New VBNetOutputVisitor(), IOutputASTVisitor), CType(New CSharpOutputVisitor(), IOutputASTVisitor))

cu.AcceptVisitor(output, DBNull.Value)
return output.Text
End Function



Responses

Author: Kumar    06 May 2009Member Level: Silver   Points : 1
Nice Code.
Sir , Like this can we successfully Convert VB6.0 Code
to VB.NET 2005 code ?




Author: D.Jeya kumar(JK)    07 May 2009Member Level: Diamond   Points : 1
Hi,


Good one. Nice to see a simple code converter to convert c# to vb.net and viceversa

Regards
JK


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Convert VB.NET to C#  .  Convert C# to VB.NET  .  Code convert  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Previous Resource: Create New WordDocument using VB.Net.
Return to Discussion Resource Index
Post New Resource
Category: Tools


Post resources and earn money!
 



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use