views:

292

answers:

5

We have developed a C# class library on VS 2008. We want the same functionality as a C++ library on Red Hat Linux. How do we accomplish that?

I am sure we are not the first to migrate C# to C++. Are there any automated tools to convert the source code?

We know about Mono, but we would very much prefer C++ source code. About 15% is the useful code, the rest 85% are unit tests using NUnit. At the very least we do want to migrate all the unit tests as source code.

We used Reflector, which did almost all the work for us. The only thing it screwed up were constructors.

Consider the following C# code:

public MyClass() : this(1,2,3){}

it should be converted to

public MyClass() : {this(1,2,3);}

but Reflector converted it to

public MyClass() : {MyClass(1,2,3);}
+12  A: 

um, are you asking for a general-purpose c# to c++ code converter that also switches platforms?

No problem, it's called a human, and you can hire or contract one from many different locations.

You may also want to look at the Mono Project, which has a fully functional c# compiler and .net runtime for various other platforms (including RH Linux). This way you would not need to recode the library into c++, although you may need to change the code in small ways if you're using things that mono does not support.

Philip Rieck
+2  A: 

I don't think there's any way to automatically translate C# to C++, if that's what you're asking, so I don't think you could get the C++ you want without manually writing it. Maybe you can use the C# itself instead via Mono...?

Alex Martelli
+1 Mono for the win
Daniel Elliott
A: 

Is there a particular reason you prefer C++ in RHEL ? If not Mono is a better solution.

Missoula
+1  A: 

Unfortunately, I'm not aware of any such tool. However, translation from C# to C++ should be easier than C++ to C#. The features C# supports but C++ doesn't (say, reflection, and defined behavior in certain cases -- like order of evaluation) is much smaller and easier to work around than the features C++ has but C# doesn't (looking at just C++ templates, you have template functions with the ability to deduce type arguments, passing compile-time constants as template arguments, partial template specialization, complete template specialization, CRTP, substitution failure is not an error, etc.).

Max Lybbert
+2  A: 

You can get a head start by first converting to C++/CLI (the .NET flavor of C++). Red Gate's .NET Reflector supports conversions between .NET languages (you need a plugin to decompile to C++/CLI) and there are other tools as well.

Ben Voigt
Thanks Ben! The Reflector got most of the job done for us.
AlexKuznetsov