Over three years ago, in my first days as an “official” Telerik employee, I created a small little project as a simple way of showing-off some of Telerik’s RadControls for ASP.NET (this was pre-Prometheus days). The project, Code Converter, is a simple tool for converting code between C# and VB.NET, and it has steadily grown in popularity over the years and is now used by thousands of developers every day.
Today, the conversion approach used by Code Converter got much better! We’re still using the NRefactory open source libraries to power our conversions, but there are three significant improvements:
- We updated the NRefactory libraries to the latest available version (4.0.0.5757)
- We changed the way code snippet processing is handled, abandoning the old “dummy class wrapper” approach and instead using the more efficient approach described by Fabien in the Code Converter forums.
- We added some additional RegEx-based “clean-up” parsing to the conversion to try to fix a few of the errors that NRefactory currently lets slip when converting code. In particular, when converting something like Session(“key”) from VB to C#, our conversion output will correctly change the parenthesis to brackets, or Session[“key”]. No other online converter is doing that today.
The end result of these back-end changes is more accurate conversions. Many of the bugs that have been reported in the Code Converter forums are now fixed by this update. For example, converting this C#:
for (int x = 1; x <= 100; x++) {
int a;
a = x;
}
Now correctly outputs this VB:
For x As Integer = 1 To 100
Dim a As Integer
a = x
Next
No more of the dreaded System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)! Other scenarios that now convert correctly:
- Regions (C# to VB)
- Using statements in a namespace (C# to VB)
- Type conversions (VB to C#)
- Lambda expressions (C# to VB)
- RaiseEvent (C# to VB)
There are, of course, still limits imposed by the underlying NRefactory engine. Among the limits most likely to affect your conversions:
- No support for converting LINQ syntax
- No support (yet) for .NET 4 language features
As soon as NRefactory supports these language features, we’ll try to improve our support. In the mean time, enjoy the improved conversion engine and let us know what you think. There are lots of things that could be done with Code Converter in the future, but we want to hear your voice. What would make Code Converter an even more valuable tool for you?
0 comments:
Post a Comment