C# – Converting a project from C++ to C#

c

I've got a medium scale project (a turn-based game) that's currently written in C/C++. Only one person is working on it. It will complie with /clr, although I haven't tried /clr:pure.

I'm looking for advice on the overall process of converting it to C#.

It's mainly C with a thin veneer of C++ on it (C with static/singleton classes for scoping). Yes, it's not 'real' OO, I've been planning to do the C# conversion first to avoid creating any conversion issues while converting.

It makes very limited use of the STL (The queue class) in the pathfinding module, and because it's a game, it also doesn't do any memory allocation outside of the third party sound library in a DLL, and what's necessary for loading the graphics bitmaps.

I want to convert it into idiomatic C#. I'd rather not hold a discussion on whether this is a good idea, I understand that it isn't, let's please let part go. Assume that I've got overriding reasons please.

I've also done my research, and there is a thread that is somewhat relevant about converting the methods using reflector. I plan to look more deeply into it when I get a chance.

Translate C++/CLI to C#

There is also one pay applicaiton that will convert from C++ to C# that I may look at if that doesn't work as well as I'd like.

The hardest part is going to be rewriting the interface in either WPF/Silverlight or XNA (or both) There are pros and cons to each one, but I'm leaning towards WPF right now because of the font support, and because that way I won't have to write all the widgets. I may end up doing both, an XNA quick port, and a WPF one later.

There are several possible approaches to this, and I wanted to know if anyone had any experience with a conversion like this, and any suggestions or pitfalls.

1) Create the UI first, This involves either leaving the Graphics module as is, and converting from GDI to raw GDI like calls in XNA, and converting later to WPF one dialog at a time.

2) Convert the guts first, and leave the main UI in C++/CLI for now, after the guts are converted, switch over the interface one dialog at a time to WPF.

A related question is whether it's worth doing this module by module, or basically all at once, and whether it's better to do a rough conversion into C# and clean everythig up, or clean up everything in C++ then convert to C#.

The thought right now is to rewrite the event loops to use a home grown common loop like MFC, then try to convert everything at once to C#. Leave the graphics in C++ and see what breaks. After that, move to XNA and provide a WPF layer later. The last two steps are arbitrary, I think that the XNA port is going to be simpler, but using WPF basic panel may be pretty simple too.

I'm open to any suggestions that may help.

Thanks,
Ralph

Best Answer

I must say that the best best advice I can give you is to rewrite the application. C++ and C# are so different that if you are certain that you want to convert the entire thing then a rewrite will most likely be your best option.

I guess my main question is why do you want to convert this project to C#? I understand that this is not your question but since you are undertaking what I consider to be a considerable effort to do this, I hope that you realize what you are getting into.