Proposal: Improve Native Method Declaration with Source Generators #10
Der-Joscha
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Thanks for the suggestion! Funnily enough I'm working on something like this for calling Corals C# methods from C++, so I could potentially extend the source generator to do what you've suggested, and I probably will end up doing that, although it might not be for a little while 🙂 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all, I wanted to thank you for creating this project.
I have a suggestion regarding the usage of
unsafe delegate*<...>
for declaring native methods. In my opinion, it seems counterintuitive and prone to errors. Specifically:unsafe { ... }
block.I propose using source generators to generate a thin wrapper method over those delegates. For instance, instead of:
Users of Coral.Managed could declare their methods like this:
The source generator would then kick in at compile time and generate the implementation of the wrapper as well as the delegate.
Here's an example:
Note that this approach is optional and works in combination with the current implementation. It still allows the use of raw
unsafe delegate*<...>
.I'd love to hear your thoughts on this idea, and I'm more than willing to assist with a pull request if you find it promising.
Best regards
Beta Was this translation helpful? Give feedback.
All reactions