How I can translate small C++/CLI project to c#
I haven't tried it, but I just googled it and found this: http://code2code.net/ According t it, you shouldn't fully rely on the code it produces:
You accept that this page does only half the work. Futher work on your part is required. In most cases, the translated code will not even compile.
Also, read this: http://stackoverflow.com/questions/73879/translate-c-cli-to-c
One roundabout, manual way would be to compile your C++/CLI project and open the output assembly in Reflector. Disassemble each class, have it convert the disassembled IL to C#, and save that code off.
As for an automatic way to do it, I can't think of any off the top of my head.
Those things being said, are you sure you really want to convert your project to C#? If your C++/CLI project uses any unmanaged code, you'll have a difficult time coming up with a purely managed equivalent. If the project is more or less composed of pure CLR code, and it was written in C++/CLI for the sake of being written in C++/CLI, I can understand wanting to convert it to C#. But if there was a reason for writing it in C++/CLI, you may want to keep it that way.
IMHO, line by line is the best way. I've ported several C++ style projects to a managed language and I've tried various approaches; translators, line by line, scripting, etc ... Over time I've found the most effective way is to do it line by line even though it seems like the slowest way at first.
Too much is lost in a translator. No translator is perfect and you end up spending a lot of time fixing up the translated code. Also, translated code as a rule is ugly and tends to be less readable than hand crafted code. So the result is a fixed up, not very pretty code base.
A couple of tips I have on line by line
- Start by defining all of the leaf types
- For every type that has a non-trivial (freeing memory) destructor, implement IDisposable
- Turn on the FxCop rule that checks for lack of Dispose calls to catch all of the places use used stack based RAII and missed it
- Pay very close attention to the uses of byref in C++.