bottlenoselabs / c2cs

Generate C# bindings from a C header.
MIT License
245 stars 18 forks source link

Ability to remap pointer types #111

Open RandyPasion opened 1 year ago

RandyPasion commented 1 year ago

Currently remapping is only evaluated on element types (e.g. remapping someType will apply the same remapping to someType*)

Allow defining remapping of pointer types separately from element type.

This can be particularly useful for safe pointer management in C#. A common use case would be to remap someType* to a class inheriting SafeHandle (e.g. SomeTypeHandle : SafeHandle) that the user defines for managing the pointer.

Secondary improvement here - prioritize user remappings to defaults. Some types are default remapped ((char* to CString for example). If a user defines a different remapping from this, it should prefer the user's remapping.

lithiumtoast commented 1 year ago

Makes sense; sounds like this would go well with the idea of trying to work on right now: C# plugin. Use a C# library to control generating C# code rather than a config file. This would help with automating custom wrappers as custom C# code can be written to help transform the bindings into a desired wrapper.

lithiumtoast commented 1 year ago

I found a way forward to implement this. It requires some major refactoring however... I'll be working on it when I can.