ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

Config option: strip-enum-member-type-name

Open fredrikhr opened this issue 1 year ago • 1 comments

Adds a new configuration option strip-enum-member-type-name. This feature adresses the feature request described in issue #461.

When the config option is applied, the enum type name is stripped from the beginning of each enum member.

enum abc_some_enum {
  abc_some_enum_key1,
  abc_some_enum_key2,
  abc_some_enum_key3,
};

becomes

enum abc_some_enum {
  key1,
  key2,
  key3,
}

Note above, that the original member name starts with abc_some_enum_ which matches the enum type name abc_some_enum separating underscores between the type name and the suffix are also stripped to avoid leading underscores in the member names.

The matching for the enum type name is only done if the type appears verbatim in the beginning of the member name. Infix or suffix matching of the type name is not supported.

As @tannergooding notes in https://github.com/dotnet/ClangSharp/issues/461#issuecomment-1930530486, there are other solutions to make C-language stype enum be nicely usable in C#. However, the different approaches are ultimately stylistic choices and therefore I argue that this feature makes sense as a configuration option, allowing users to choose freely between styles. Following that argument, the option is kept simply to apply to the entire code generation, i.e. generation for stripping one enum, but not another is not supported as that would lead to two different styles within the same generated codebase.

fredrikhr avatar Feb 07 '24 07:02 fredrikhr

Sorry for the delay on this, I've been heads down on some dotnet/runtime related work and completely forgot to respond.

This is on my backlog (as are the other couple PRs) to finish reviewing and get them merged. At a high level glance, they all looked reasonable and I just need to sit down and finish going through all the code.

tannergooding avatar Feb 29 '24 17:02 tannergooding