Search code examples
c#c++c++-clireflector

Converting some C# code to managed or C++/CLI code


I have an existing C# application. What I want is to write native code for some part of the c# application for speed improvement while another part using C# app and the other part using C++/CLI to provide interfaces to C# application. So for latter part, I need to convert C# code into C++/CLI.

I am wondering if I can convert my C# code to C++/CLI code. Maybe converting .net assembly to C++/CLI would be a better idea to get specific code. I looked into reflector and its addin CppCli. But the addin is not available any more. So I am looking for any way to automate this. I would appreciate any advice.


Solution

  • Generally speaking C++/CLI will have about the same run-time as C# (both are managed and probably would be converted to the same IL). If there is a certain part of your application you need to run faster you can write a C++/CLI layer so your C# app can interop with some native C++. This will be faster if you write your native C++ appropriately.

    EDIT: As Ben Voigt pointed out, the C++/CLI might be more optimized than the C#, but still not nearly as fast as well-written native C++ since it's still managed.

    If you're looking to wrap some native code in C++/CLI then a conversion tool probably wouldn't structure it in a useful fashion anyway. You're better off just hand-coding the interop portion.

    There are commercial tools out there that do this, but I think you're still better off doing it by hand.