Add Ons - DevSource
DevSource: Microsoft Developer Resource DevSource Home Sponsored by Microsoft Home Add Ons Architecture Languages Techniques Using VS Forums
Home arrow Add Ons arrow Instant C#: Add VB and Stir
Instant C#: Add VB and Stir
By Peter Aitken

Rate This Article: Add This Article To:

Review: Instant C# is not the only VB to C# converter on the market, but it may well be the best.

Suppose you have slaved away for a few weeks on a Visual Basic.Net project. Things are going quite well, when all of a sudden your boss or client (same thing, I guess!) calls and tells you that now the project has to be done in C#.

Is it hair-tearing time? Are you doomed to dozens of hours of tedious manual recoding? Not if you have Tangible Software Solutions Inc.'s Instant C# — a few clicks, a modest amount of fine-tuning, and the task is done. Of course the boss does not need to know how easy it was!

ADVERTISEMENT

Instant C# is not the only VB to C# converter on the market, but it may well be the best. I was very impressed with the attention that the creators paid to both the quality of conversion and the ease of use. The program can convert anything from a code snippet to complete projects and solutions. It works on ASP.Net web sites as well. It does not convert Visual Basic 6 code, although it does a pretty good job of dealing with VB6 holdovers, such as On Error Goto, that may be present if your VB.Net project was itself converted from VB6.

Program use could hardly be simpler. Navigate to the VB.Net project file to convert, then specify an output folder for the new C# files. Click the Convert button and away you go. Conversion speed seems quite good, but that is not really an important factor because it is a task you will do only once for each project.

During conversion, Instant C# may ask your assistance in resolving specific assembly references. Even if a reference cannot be resolved immediately, you can complete the conversion and then go back and fix it later.

After conversion, Instant C# displays a status message indicating how many notes, warnings, and to-do tasks were inserted as comments in your code. These three categories mean different things:

  • A note is an informative message that does not require any action on your part. For example, if a parameterized property was encountered — not supported by C# — it is converted to one or more methods, and a note to that effect inserted.
  • A warning marks a conversion detail that probably requires your attention. For example, the Exit Try statement, not supported in C#, is replaced with a goto statement and a warning so that you can modify the code structure to get rid of the goto, if desired.
  • A to-do task is something that definitely requires your attention. An example is when a class is contained in an interface, something not supported by C#.

The program offers several conversion options that relate to the Visual Basic namespace. By default, these are all turned on, and there will be few if any situation when you would want to disable them. Still, it's nice to know you have this level of control if it is ever needed. These options are:

  • Whether to convert Visual Basic string functions (for example, Asc, GetChar, RTrim, and UCase) to the equivalent .Net string methods.
  • Whether to convert Visual Basic date functions to the equivalent .Net date/time methods.
  • Whether to convert IIF statements to the C# conditional operator ("?:").
  • Whether the Visual Basic constants vbCrLf and ControlChars.CrLf are converted to System.Environment.Newline or to "\r\n".

Other conversion options are well thought out and provide an excellent level of control. You can, for example, specify whether opening braces are put on the same line as the preceding statement or by themselves on the next line, whether tabs or spaces are used for indents, and whether local variables are explicitly initialized.

I found Instant C# to do a really good job. Not perfect, of course, but that would be expecting a bit much! I tested it on medium and large projects, both VB.Net and ASP.Net. My experience was that if I ran the conversion and then attended to the notes, warnings, and to-do tasks, I was usually all set for testing.

Yes, you must test. Would you trust an important project to an automated conversion utility, no matter how good? Errors are often caught on building the new project, and tend to be more frequent if the VB project does not have Option Strict set, uses a lot of COM interop, or uses late binding.

Instant C# is itself a .Net program. Assuming the Framework is installed, then installing the program is a simple matter of copying the EXE and help files to the desired folder. The publisher, Tangible Software Solutions, also makes a C# to VB converter. Free demos downloads are available on the company web site. While relatively few people need to convert VB code to C#, this product can be a lifesaver to those few.




Discuss Instant C#: Add VB and Stir
 
>>> Be the FIRST to comment on this article!
 

 
 
>>> More Add Ons Articles          >>> More By Peter Aitken
 



Microsoft's Future: A Chat With Their CTO, Barry Briggs

Play Video >

All Videos >

Julia explores the Robotics Studio!

Read now >

Messages to Bill Gates!

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.