Skip to content

Add --typePrefixStrip for stripping a prefix from type and enum member names#768

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-prefix-strip-types-and-enum-members
Jul 14, 2026
Merged

Add --typePrefixStrip for stripping a prefix from type and enum member names#768
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-prefix-strip-types-and-enum-members

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Adds a new --typePrefixStrip (-tp) value option, the type-side analog of the existing --prefixStrip for methods. It strips a library-wide prefix from enum/struct/union type names, at both the declaration and every reference, reusing the existing PrefixAndStrip plumbing rather than adding a parallel path. It also strips the prefix from enum member names and composes with --config strip-enum-member-type-name.

Given:

typedef struct abc_some_struct { int value; } abc_some_struct;
typedef enum abc_some_enum { abc_some_enum_key1, abc_some_enum_key2 } abc_some_enum;
typedef struct abc_2d_point { int x; int y; } abc_2d_point;
void abc_use(abc_some_struct* s, abc_some_enum e, abc_2d_point* p);

with --typePrefixStrip abc_:

public partial struct some_struct { public int value; }
public enum some_enum { some_enum_key1, some_enum_key2 }
public partial struct _2d_point { public int x; public int y; }
public static extern void abc_use(some_struct* s, some_enum e, _2d_point* p);

Adding --config strip-enum-member-type-name collapses the members further to key1/key2 (the library prefix is stripped first, then the already-stripped enum type name).


The stripping is applied at the two consistent tag-type naming choke points -- GetRemappedCursorName for declarations and ApplyTagTypeNameOverrides for references -- plus EscapeAndStripEnumMemberName for members, so declarations and every reference resolve to the same C# name.

Edge cases:

  • A result that would leave a leading digit keeps an underscore (abc_2d_point -> _2d_point) so it stays a valid C# identifier.
  • An empty result (the name was exactly the prefix) is skipped, keeping the original name.
  • An explicit --remap/--remap-type always wins over stripping.
  • NativeTypeName attributes and the EntryPoint/mangled name keep the original C spelling.
  • Collisions that result from stripping are the user''s responsibility and can be resolved with an explicit --remap.

This is the explicit-prefix form only; auto-detecting a non-obvious common prefix (or a common postfix) per enum is intentionally left out and can be a follow-up. As a reminder, one of the best existing ways to consume these is simply using static abc_some_enum;, after which abc_some_enum_key1 works unqualified.

Addresses #333 and #461.


Build is clean (0 warnings) and dotnet test -c Release passes (3772 passed, 0 failed). Adds TypePrefixStripTest with golden baselines covering both the types-only and combined cases.

tannergooding and others added 2 commits July 13, 2026 23:04
…r names

Strips a library-wide prefix from enum, struct, and union type names and their enum member names, at both the declaration and every reference, reusing the existing PrefixAndStrip plumbing that backs --prefixStrip for methods. A result that would leave a leading digit keeps an underscore and an empty result is skipped so the name stays a valid C# identifier. Composes with strip-enum-member-type-name so members collapse fully to their leaf name.

Addresses dotnet#333 and dotnet#461.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Covers dotnet#333 (prefix stripped from enum/struct type declarations and references, leading-digit guard, methods left untouched) and dotnet#461 (enum members stripped, and collapsed to their leaf name when combined with strip-enum-member-type-name).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit d546965 into dotnet:main Jul 14, 2026
14 checks passed
@tannergooding
tannergooding deleted the tannergooding-prefix-strip-types-and-enum-members branch July 14, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant