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

Enhancement: Convert Enum values to be compliant to .NET naming standards #51

Open
GoogleCodeExporter opened this issue Apr 7, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

The naming guidelines for Google Protobuf enums is to use the C++/Java standard 
of all capitals:

enum MyEnum {
    OPTION_ONE =1;
    OPTION_TWO =2;
}

In .NET the naming standards are to use Pascal case (upper camel): 
http://msdn.microsoft.com/en-us/library/4x252001(VS.71).aspx

Please include a ProtoGen setting that will convert enumerated values to the 
.NET standard.  Expected output would be:

enum MyEnum {
    OptionOne,
    OptionTwo
}

Original issue reported on code.google.com by [email protected] on 4 Jan 2013 at 6:40

@GoogleCodeExporter
Copy link
Author

I was slightly surprised to see that we don't already do this. I'm pretty sure 
we've got the relevant code already, as we convert field names appropriately.

I can't promise when I'll get to this, but it seems entirely reasonable as an 
option.

Original comment by jonathan.skeet on 5 Jan 2013 at 8:54

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Hi Jon

In addition to this option, I think it would be great to include another option 
to remove the type name if it appears at the start of the enum value.  This 
goes back to the uniqueness rules for enum values following the C++ convention 
in ProtoBuf.  Because of these rules, developers tend to prefix the enum values 
with the type name of the containing type (using the different naming 
conventions):

enum MyEnum {
    MY_ENUM_ONE = 1;
    MY_ENUM_TWO = 2;
}

It would be nice to include an additional option that would clear up the 
generated C# enum and remove the type name prefix where it matches the 
containing type:

enum MyEnum {
    One,
    Two
}

It's a pity the original proto C++ compiler didn't just add this prefix in the 
generated C++ code and made the enum values unique to the containing type. 

Original comment by [email protected] on 5 Jan 2013 at 2:12

@GoogleCodeExporter
Copy link
Author

Yes, that makes sense too, and I should be able to do it as part of the same 
set of changes. As I say, don't hold your breath for it, but it shouldn't be 
too hard when I find time :)

Original comment by jonathan.skeet on 5 Jan 2013 at 7:46

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

1 participant