Skip to content

Adds New SchemaGeneration Flag for Generating Prefixed Enum Members #1133

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

Merged
merged 3 commits into from
Feb 28, 2024

Conversation

ThaTechMaestro
Copy link
Contributor

Adds Schema Generation Option for Prefixed Enum Members
Issue: protobuf-net/protobuf-net.Grpc#323

";

[Fact]
public void ProtoIncludesEnumNamePrefix()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a second test here, so we can immediately contrast with/without ?

Assert.Equal(ExpectedProto, proto, ignoreLineEndingDifferences: true);
}

[ProtoContract]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a second enum here with a [ProtoContract(Name = "SomethingElse")] to check that the generated prefix is SomethingElse_ ?

@@ -2028,6 +2030,7 @@ public bool IsGroup
else if (Type.IsEnum)
{
var enums = GetEnumValues();
string enumNamePrefix = $"{GetSchemaTypeName(callstack)}_";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: = isEnumNamePrefixSupported ? $"{GetSchemaTypeName(callstack)}_" : ""; - that way the later uses can be simplified to just .Append(enumNamePrefix).Append(member.Name), which simplifies the code and avoids a bunch of unnecessary string allocations

@@ -2080,11 +2084,13 @@ public bool IsGroup
if (parsed.HasValue)
{
if (parsed.Value == 0) continue;
NewLine(builder, indent + 1).Append(member.Name).Append(" = ").Append(parsed.Value).Append(';');
NewLine(builder, indent + 1).Append(isEnumNamePrefixSupported ? $"{enumNamePrefix}{member.Name}" : member.Name).Append(" = ").Append(parsed.Value).Append(';');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a semantic thing here for me to think about - "what should happen if the name was already explicitly specified? is it prefixed? (probably not)" - not 100% sure we know that currently; a job for me to worry about

Copy link
Member

@mgravell mgravell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking in the right direction; added some thoughts - thanks!

@mgravell
Copy link
Member

This list is good, thanks!

@mgravell mgravell merged commit 7c8c000 into protobuf-net:main Feb 28, 2024
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.

2 participants