Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum key stripping #461

Open
dovdiienko-el3 opened this issue Jul 4, 2023 · 3 comments
Open

Enum key stripping #461

dovdiienko-el3 opened this issue Jul 4, 2023 · 3 comments

Comments

@dovdiienko-el3
Copy link

Could you add an option to strip the prefix from the enumeration keys. For example given following C code:

enum abc_some_enum {
  abc_some_enum_key1,
  abc_some_enum_key2,
  abc_some_enum_key3,
};

The expected C# output is following:

enum abc_some_enum {
  key1,
  key2,
  key3,
};

My best guess is that generator should cut maximum common prefix from the enum key name.

@tannergooding
Copy link
Member

This can be achieved via remapping today.

A new option to explicitly trim out some prefixes would also be possible, but there are many cases this won't work. This includes where the prefix is non-obvious, where it is instead a common postfix, where the first letter after the prefix is a number, etc.

I'll leave this open and up-for-grabs in case someone wants to do it, but I expect it would need to look like: -config prefix-strip-enum

Alternatively, or in addition, the existing --prefixStrip could be expanded to support specifying a common prefix to remove per enum.

@fredrikhr
Copy link

fredrikhr commented Feb 6, 2024

In many cases the prefix is the enum member type name. So, in order to keep it simple, I suggest --config strip-enum-type-from-member-name which would simply strip the enum member type name (and following underscore) from the enum member name. That would satisfy the above example.

I am working on this now, will submit PR soon.

@tannergooding
Copy link
Member

It's worth noting one of the "best" ways to consume these types is simply to do using static abc_some_enum; at which point you can just use abc_some_enum_key1 as is, unqualified.

This is ultimately very consistent with C/C++ (which can help with porting) and fits in if C# ever gets the proposed feature to allow contextual access to enum members without having to qualify the type name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants