What is the best way to port a C ++ library to C #?

I have (for header only) the C ++ library I'm looking for for a port in C #. This is an api victory wrapper that I made for a specific purpose. I want to port it to C # because I want to continue developing it with C #. What is the most effective (and easiest?) Way to transfer it. Please note: I do not want something to be hectic, because I do not want to spend more time moving the library than it took to make this library in the first place. So is there a way?

+4
source share
2 answers

It depends on how big your library is, how it is structured, how your memory allocation looks, how much you used libraries inaccessible in C # (for example, C ++ std lib), how many templates in C ++ you use, etc. .d.

Different strategies can be

  • try connecting (parts) it automatically with some code generator
  • don't port it to C #, use C ++ / CLI instead (something that I have done very successfully in the past)
  • do it manually, because the C ++ concepts you have used so far don't map well with C #

"Only the title" does not seem to have much meaning. In fact, things can be simplified a bit if you only have one C ++ file for each class that will be ported to a single C # class file.

+3
source

A few ways I can think of.

  • Manual conversion to C # dll with the possible generation of T4 code.
  • Change your C ++ library to a managed dll so you can use it in your C # project.
  • Of course, you can use interop with your C ++ library in your C # project. But in this case, I'm not sure about the purpose of your C ++ library, since you said it with a shell.

Since you already have a C ++ library that you can fully control, I will first try to switch to C # 2.

0
source

All Articles