protobuf-csharp-port icon indicating copy to clipboard operation
protobuf-csharp-port copied to clipboard

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

Open GoogleCodeExporter opened this issue 10 years ago • 3 comments
trafficstars

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 avatar Apr 07 '15 15:04 GoogleCodeExporter

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 avatar Apr 07 '15 15:04 GoogleCodeExporter

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 avatar Apr 07 '15 15:04 GoogleCodeExporter

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

GoogleCodeExporter avatar Apr 07 '15 15:04 GoogleCodeExporter