I've decided to at least try to put all of the code sample in my Data Access with Silverlight 2 book in both VB and C#. While VB was once my main language, C# has long since been the primary language I use. Thankfully, there is the tool from Tangible Software Solutions called Instant VB that converts C# code to VB code. It can convert a snippet of code, a file, or an entire solution. Its pretty darn fast too.
For example, here is a class I created in C# ...
public class Customer
{
private int id;
private string companyName;
private Address companyAddress;
public int ID
{
get { return id; }
set { id = value; }
}
public string CompanyName
{
get { return companyName; }
set { companyName = value; }
}
public Address2 CompanyAddress
{
get { return companyAddress; }
set { companyAddress = value; }
}
}
and here is the code that Instant VB created for me.
Public Class Customer
Private privateID As Integer
Public Property ID() As Integer
Get
Return privateID
End Get
Set(ByVal value As Integer)
privateID = value
End Set
End Property
Private privateCompanyName As String
Public Property CompanyName() As String
Get
Return privateCompanyName
End Get
Set(ByVal value As String)
privateCompanyName = value
End Set
End Property
Private privateCompanyAddress As Address
Public Property CompanyAddress() As Address
Get
Return privateCompanyAddress
End Get
Set(ByVal value As Address)
privateCompanyAddress = value
End Set
End Property
End Class
While this small snippet is easy enough to translate, it really comes in handy when you forget an END statement or a line continuation character or some other language specific syntax (or a squiggly bracket in C#).
So far its going pretty well as I have only run into a few places where it did not convert the code as I expected it would. But it was easily fixed and I suspect that I had a problem because I was just converting a snippet of code (not even an entire method) and the tool could not determine if it was a property, method, or what. As I continue writing the book I will post more on my experiences with this tool, but so far its been pretty good. I don;t know if I trust it to convert my entire solution just yet, but I will be giving it a try once I have time to go through it all and test it.
They also have a Instant C# tool that converts from VB to C#, too.
And yes, this tool is not free :)