-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
Keep '_' in property name in C# generated code #4120
Comments
In addition to that, is there a way to specify "Keep property names as is" for the generated C# code? If not, is there an easy way to get property name for corresponding field name inside |
Have you tried Descriptors? Sample usage: |
Thanks @anandolee . I already tried that but it doesn't quite give what I want. Imagine protobuf message like this - message FooMulInputType {
repeated sint32 param1 = 1;
repeated sint32 Param2 = 2;
repeated sint32 p_aram3 = 3;
repeated sint32 p_aram_4 = 4;
} If i do something like this, I don't get desired ouput: FieldDescriptor par1 = FooApisType.Types.FooMulInputType.Descriptor.FindDescriptor<FieldDescriptor>("p_aram3");
Console.WriteLine(par1.Name); // "p_aram3" But this is not the property name that is generated in C#. See below screenshot that shows property names |
It is in the FieldDescriptor.propertyName: https://github.com/google/protobuf/blob/047575f20cbdee8fb2f88d78a317ffe6133b93e6/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs#L46 I think it is reasonable to make a public get API for the propertyName. Are you happy to make a PR for it? |
sure, will do it sometime. |
Friendly ping. @kunalspathak do you get time for it? |
sorry, not yet. I might have some time starting 1st week of August. |
Has anyone found or implemented a way to keep the _ in field names instead of forcing camelCase? |
Closing this due to the fix in #7642. |
Hi,
From trial and error, the style guide and source code I see that all recurrences of the character '_' are eliminated from property name when generating C# code.
Can this be overridden or avoided in some way? I need my properties with underscore (or any other char that can be perceived as a separator).
The text was updated successfully, but these errors were encountered: