Browse Source

Fix oneof behaviour in the face of default values.

Jon Skeet 10 years ago
parent
commit
8fcde2cabd
1 changed files with 4 additions and 9 deletions
  1. 4 9
      src/google/protobuf/compiler/csharp/csharp_primitive_field.cc

+ 4 - 9
src/google/protobuf/compiler/csharp/csharp_primitive_field.cc

@@ -137,8 +137,6 @@ PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {
 }
 }
 
 
 void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
 void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
-  // TODO(jonskeet): What should foo.OneofIntField = 0; do? Clear the oneof?
-  // Currently foo.OneOfStringField = null will clear the oneof, but foo.OneOfStringField = "" won't. Ick.
   AddDeprecatedFlag(printer);
   AddDeprecatedFlag(printer);
   printer->Print(
   printer->Print(
     variables_,
     variables_,
@@ -148,15 +146,14 @@ void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
     if (is_value_type) {
     if (is_value_type) {
       printer->Print(
       printer->Print(
         variables_,
         variables_,
-        "    $oneof_name$_ = value;\n"
-        "    $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n");
+        "    $oneof_name$_ = value;\n");
     } else {
     } else {
       printer->Print(
       printer->Print(
         variables_,
         variables_,
-        "    $oneof_name$_ = value ?? $default_value$;\n"
-        "    $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$property_name$;\n");
+        "    $oneof_name$_ = value ?? $default_value$;\n");
     }
     }
     printer->Print(
     printer->Print(
+      "    $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n"
       "  }\n"
       "  }\n"
       "}\n");
       "}\n");
 }
 }
@@ -167,11 +164,9 @@ void PrimitiveOneofFieldGenerator::WriteToString(io::Printer* printer) {
 }
 }
 
 
 void PrimitiveOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) {
 void PrimitiveOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) {
-  // TODO(jonskeet): What if the value we read is the default value for the type?
     printer->Print(
     printer->Print(
       variables_,
       variables_,
-      "$oneof_name$_ = input.Read$capitalized_type_name$()\n;"
-      "$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n");
+      "$property_name$ = input.Read$capitalized_type_name$()\n;");
 }
 }
 
 
 }  // namespace csharp
 }  // namespace csharp