diff options
author | Jon Skeet <jonskeet@google.com> | 2015-07-30 14:06:01 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-07-31 07:00:25 +0100 |
commit | f994cfe8084ee81916a546715254d93c9f2a9380 (patch) | |
tree | fd6e6f52a8433d7119825c3e92f45d5db3d3e918 /src/google | |
parent | b193503aa74d493556af0fa08a99ba1fd97035af (diff) | |
download | protobuf-f994cfe8084ee81916a546715254d93c9f2a9380.tar.gz protobuf-f994cfe8084ee81916a546715254d93c9f2a9380.tar.bz2 protobuf-f994cfe8084ee81916a546715254d93c9f2a9380.zip |
Handle field names of "descriptor" and "types".
Diffstat (limited to 'src/google')
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_helpers.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index 07305a93..46f4fc33 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -251,7 +251,13 @@ std::string GetFieldConstantName(const FieldDescriptor* field) { std::string GetPropertyName(const FieldDescriptor* descriptor) { // TODO(jtattermusch): consider introducing csharp_property_name field option std::string property_name = UnderscoresToPascalCase(GetFieldName(descriptor)); - if (property_name == descriptor->containing_type()->name()) { + // Avoid either our own type name or reserved names. Note that not all names + // are reserved - a field called to_string, write_to etc would still cause a problem. + // There are various ways of ending up with naming collisions, but we try to avoid obvious + // ones. + if (property_name == descriptor->containing_type()->name() + || property_name == "Types" + || property_name == "Descriptor") { property_name += "_"; } return property_name; |