The reason p / invoke is less efficient, because it should be a very universal interface for any function, knowing only the signature. Your hypothetical wrapping generator will not work better.
On the other hand, a developer encoding a custom wrapper class has much more information about functions that are used together, etc., and therefore can avoid a lot of slow and unnecessary conversions, for example, by storing values โโdirectly inside the wrapper and not converting them into some .NET format.
So, this does not mean that such an instrument is impossible, there is simply little use for it. If you care about performance, you write your own shell, complete with smart pointers for managing life time, etc.
Of course, p / invoke only provides access to the bare function. The fact that SWiG should be useful is to expose any interfaces of the C ++ class through bare exported functions.
I found one guide to the tool, which may be what you are looking for, although it looks pretty narrow in focus:
Ben voigt
source share