Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Trial Issue of Visual Studio Magazine

email article
printer friendly

Convert VB.NET Code to C#
by Don Kiely

September 13, 2004

Sometimes you have good reasons to use one .NET language over another. Much as you might love VB.NET, you must use C# occasionally (or vice versa). It would be nice to have an easy way to convert code from one language to the other.

ADVERTISEMENT

Tangible Software Solutions' Instant C# 1.7 takes care of one direction of the conversion—from VB.NET to C# (see Figure 1). You can feed it either a complete VB.NET project or a snippet of code. The snippet feature is handy for comparing how the C# code would look for a particular task. Tangible claims that Instant C# converts 99 percent of all VB.NET code, the highest rate in the industry. It can't, and shouldn't, handle some constructs, such as antiquated OnError Resume statements, When statements in Catch blocks (because C# doesn't support them), and inline ASP.NET code.

I threw Instant C# to the wolves, feeding it the fairly large middle-tier VB.NET objects for my current project. When I started the conversion, Instant C# found that it needed help resolving some of the project's references by name to external assemblies. A dialog box made it easy to resolve these. Instant C# eliminates a reference from the list after you tell it where to find the appropriate DLL and it verifies that the file has the necessary namespace. Once that's done, it begins the conversion.

Conversions are normally a one-time job, so performance isn't as important as the quality of the output code. My conversion took an hour and 40 minutes for 110,114 lines of code, 648 code files, and the new csproj file. Instant C# made 2,208 notes where it made a change worth checking, such as initializing loop variables in the foreach statement rather than in a separate statement. I had 108 TODO conversion tasks that Instant C# didn't handle, most dealing with parameterized properties that C# doesn't support. The project won't compile until I deal with them.

Instant C#'s UI is functional but immature. For example, if an output directory for the C# project doesn't exist, Instant C# won't create one. It never repaints itself during the conversion process and offers no status information about its progress. The best I could do was check the Windows Task Manager periodically to make sure Instant C# was still running.

The product ships as a single executable file, living up to the promise of .NET xcopy deployment. Unfortunately, this also means that you get no documentation other than a basic FAQ on the company's Web site. You might not miss the documentation, though, because the product's function and operation are straightforward.

No conversion is ever fully automatic; you'll always need to check and tweak the output code. However, Instant C# does a fine job of converting VB.NET code to C#, doing the vast bulk of the work for you.

Instant C# 1.7
Tangible Software Solutions
Web:
www.tangiblesoftwaresolutions.com
Phone: 604-930-9949
Price: $159
Quick Facts: VB.NET-to-C# converter for short code snippets or full projects.
Pros: Produces generally good code; intelligent handling of incompatible syntax.
Cons: Immature UI; no status information for long operations.

About the Author
Don Kiely is a senior technology consultant. When he isn't writing software, he's writing about it, speaking about it at conferences, and training developers in it. Reach him at .




Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home