aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/csharp
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-10-24 06:45:20 +0100
committerJon Skeet <jonskeet@google.com>2015-10-24 06:45:20 +0100
commit964627ece023577f252b888c9a9d6d9c2c563fc3 (patch)
tree8204a0d53d65c037407c8178110314cc4f6d3a8b /src/google/protobuf/compiler/csharp
parent1abf297fb9762df6d52735026d2dd670f540a947 (diff)
downloadprotobuf-964627ece023577f252b888c9a9d6d9c2c563fc3.tar.gz
protobuf-964627ece023577f252b888c9a9d6d9c2c563fc3.tar.bz2
protobuf-964627ece023577f252b888c9a9d6d9c2c563fc3.zip
Include the oneof-case in equality and hash code generated code.
The included C# test will fail until the regenerated code is used, which is in the next commit.
Diffstat (limited to 'src/google/protobuf/compiler/csharp')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_message.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc
index 21fbf7e3..6cca6703 100644
--- a/src/google/protobuf/compiler/csharp/csharp_message.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_message.cc
@@ -323,6 +323,10 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
CreateFieldGeneratorInternal(descriptor_->field(i)));
generator->WriteEquals(printer);
}
+ for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
+ printer->Print("if ($property_name$Case != other.$property_name$Case) return false;\n",
+ "property_name", UnderscoresToCamelCase(descriptor_->oneof_decl(i)->name(), true));
+ }
printer->Outdent();
printer->Print(
" return true;\n"
@@ -339,6 +343,10 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
CreateFieldGeneratorInternal(descriptor_->field(i)));
generator->WriteHash(printer);
}
+ for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
+ printer->Print("hash ^= (int) $name$Case_;\n",
+ "name", UnderscoresToCamelCase(descriptor_->oneof_decl(i)->name(), false));
+ }
printer->Print("return hash;\n");
printer->Outdent();
printer->Print("}\n\n");