-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
"; | ||
|
||
[Fact] | ||
public void ProtoIncludesEnumNamePrefix() |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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_
?
src/protobuf-net/Meta/MetaType.cs
Outdated
@@ -2028,6 +2030,7 @@ public bool IsGroup | |||
else if (Type.IsEnum) | |||
{ | |||
var enums = GetEnumValues(); | |||
string enumNamePrefix = $"{GetSchemaTypeName(callstack)}_"; |
There was a problem hiding this comment.
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
src/protobuf-net/Meta/MetaType.cs
Outdated
@@ -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(';'); |
There was a problem hiding this comment.
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
There was a problem hiding this 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!
This list is good, thanks! |
Adds Schema Generation Option for Prefixed Enum Members
Issue: protobuf-net/protobuf-net.Grpc#323