Silverlight Brass Tacks

Bill Reiss' Silverlight Ramblings
My upcoming Silverlight book for beginners Hello! Silverlight 2 with Dave Campbell, available online now!



Pages

Recent posts

Navigation

Archive

Blogroll

Tampa Divorce Lawyer

North of Tampa in Lutz, Florida. A Tampa Divorce Lawyer focusing on family, divorce, and real estate law.

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Converting C# samples to VB.NET

It seems that all of the good samples out there for Silverlight or any other .NET technology are written in C#. So f you’re a VB.NET developer, what are you to do?

There are some good tools out there to convert C# code to VB.NET, some are very good and cost a good deal of money. For a quick and dirty conversion of pieces of code, I have found the following to work pretty well.

You may have already used Red Gate’s Reflector application (formerly Lutz Roeder’s Reflector), downloadable for free here:

http://www.red-gate.com/products/reflector/

Reflector is typically used for digging into assemblies that you don’t have the source code for and figuring out how they work. However, by using the language dropdown, you can get a pretty decent language converter.

Let’s assume you have a sample written in C#. For this example, I’ll use a piece of code from our upcoming book, Hello! Silverlight 2. As a side note, you won’t have to use a method like this for converting the samples in our book since we will be including all of the samples as both C# and VB.NET inline in the book’s text.

If we select the dll output from a Silverlight project, and then select one of the classes in it, let’s say FishEyeMenuItem in our case, you’ll see the following:

reflector

Then you can click on the Expand Methods link in the right hand pane, and see all of the C# source code for this class:

reflectorcs

Now if you look in the top toolbar, you’ll see a dropdown that says C#. Change that to “Visual Basic” and Expand Methods again and you’ll see something like this:

reflectorvb

Now since this is code for a user control, there is generated code mixed in here, specifically the InitializeComponent method and some generated field definitions corresponding to XAML elements. So if you try to copy and paste this into a VB version of the project you would get duplicate definitions. It’s pretty easy to track those down and remove them though, and the code then should work as-is.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
Posted: Dec 09 2008, 02:21 by Bill Reiss | Comments (8) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:

Related posts

Comments

Coal us said:

# December 09 2008, 08:08

Bill Reiss us said:

Bill ReissYeah I don't see the average developer paying $179 for InstantVB although I've heard it's very good.

# December 09 2008, 08:39

geekswithblogs.net said:

pingbackPingback from geekswithblogs.net

Silverlight Cream for December 10, 2008 -- #450

# December 10 2008, 02:54

Jason Bock us said:

Jason BockI've created an add-in for Reflector that lets you generate this code to files:

http://www.codeplex.com/FileGenReflector

If you're doing a lot of translation like this, the add-in makes it pretty easy.

# December 10 2008, 04:19

Bill Reiss us said:

Bill ReissJason,

Looks pretty cool I'll haveto check that out. Thanks for sharing.

Bill

# December 10 2008, 04:32

Paul ca said:

Paulhmmmm how perfect is this, you will get your normal errors, no?

# January 30 2009, 09:12

.NET Guy us said:

.NET GuyIts nice..and the best thing is its still free. well i used developerfusion online tools to convert to C# to Vb.net and vice versa and i feel converting from vb.net to C# it will have () instead of []. But it seems to me its not happening using this new tools..

Thanks for sharing..

# March 20 2009, 05:57

hilpers.com said:

pingbackPingback from hilpers.com

DGV mit Fußzeile | hilpers

# May 31 2009, 00:06

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

said:

# February 08 2010, 18:36