Allow customisation of C# access modifiers in generated output
pixsperdavid opened this issue · 4 comments
Would be useful to have an option in C# code generation config to customize access modifiers on generated classes/structs. In my usage of interoptopus, I'm creating a friendlier C# wrapper around a native DLL so would prefer not to expose the generated classes in the wrapper library interface. Currently I'm doing a regex find and replace on the file after generation to change the accessors to 'internal'.
Yes, this is generally wanted; also see the comment around #[ffi_tag]
in #32. I don't quite know what the best solution is. Tagging could work, but it will require lots of logic to satisfy everyone.
Originally the idea was to just overload the generation trait and write your desired behavior in code (like, you can overload CSharpWriter
and CSharpTypeConverter
, and compose a new Generator
using your's; but I haven't used / tested that system in a while, so it might run into issues.
As a stop-gap to the wider tagging discussion/implementation, perhaps this could be implemented in the 'Config' struct as a 'default_access_modifier' field which would set the accessibility of all types which are untagged?
If this sounds like a good starting point I'm happy to create a PR and submit for review.
Sounds good. If we talk about fields, could you (re)use emit_rust_visibility
, making it an enum, to guide visibility generation. Although I could swear I implemented that one, it looks unused right now. How about:
enum Visibility {
AsDeclared, // what we have right now: mimics Rust, or later can be overwritten with custom visibility attributes
Protected // or whatever you intend to do
}
I'm not sure how that works with more fine-gained visibility demands, e.g., fields vs. types vs. methods. If you really want to hide all types / methods there should probably be another config option.
Pushed as 0.13.14
. I've renamed the config to visibility_types
as there will likely be a visibility_fields
later.