aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2015-07-30 14:06:01 +0100
committerGravatar Jon Skeet <jonskeet@google.com>2015-07-31 07:00:25 +0100
commitf994cfe8084ee81916a546715254d93c9f2a9380 (patch)
treefd6e6f52a8433d7119825c3e92f45d5db3d3e918 /src
parentb193503aa74d493556af0fa08a99ba1fd97035af (diff)
Handle field names of "descriptor" and "types".
Diffstat (limited to 'src')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_helpers.cc8
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;