Bläddra i källkod

Write messages to backing field in generated C# cloning code (#4440)

* Edited MessageFieldGenerator to clone to backing field instead of property

* Generated C# proto code
Sydney Acksman 7 år sedan
förälder
incheckning
4ca46ede5c

+ 1 - 1
csharp/src/AddressBook/Addressbook.cs

@@ -78,7 +78,7 @@ namespace Google.Protobuf.Examples.AddressBook {
       id_ = other.id_;
       email_ = other.email_;
       phones_ = other.phones_.Clone();
-      LastUpdated = other.lastUpdated_ != null ? other.LastUpdated.Clone() : null;
+      lastUpdated_ = other.lastUpdated_ != null ? other.lastUpdated_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 

+ 1 - 1
csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs

@@ -642,7 +642,7 @@ namespace Google.Protobuf.TestProtos {
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public TestMapSubmessage(TestMapSubmessage other) : this() {
-      TestMap = other.testMap_ != null ? other.TestMap.Clone() : null;
+      testMap_ = other.testMap_ != null ? other.testMap_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 

+ 10 - 10
csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs

@@ -273,13 +273,13 @@ namespace ProtobufTestMessages.Proto3 {
       optionalBool_ = other.optionalBool_;
       optionalString_ = other.optionalString_;
       optionalBytes_ = other.optionalBytes_;
-      OptionalNestedMessage = other.optionalNestedMessage_ != null ? other.OptionalNestedMessage.Clone() : null;
-      OptionalForeignMessage = other.optionalForeignMessage_ != null ? other.OptionalForeignMessage.Clone() : null;
+      optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null;
+      optionalForeignMessage_ = other.optionalForeignMessage_ != null ? other.optionalForeignMessage_.Clone() : null;
       optionalNestedEnum_ = other.optionalNestedEnum_;
       optionalForeignEnum_ = other.optionalForeignEnum_;
       optionalStringPiece_ = other.optionalStringPiece_;
       optionalCord_ = other.optionalCord_;
-      RecursiveMessage = other.recursiveMessage_ != null ? other.RecursiveMessage.Clone() : null;
+      recursiveMessage_ = other.recursiveMessage_ != null ? other.recursiveMessage_.Clone() : null;
       repeatedInt32_ = other.repeatedInt32_.Clone();
       repeatedInt64_ = other.repeatedInt64_.Clone();
       repeatedUint32_ = other.repeatedUint32_.Clone();
@@ -338,12 +338,12 @@ namespace ProtobufTestMessages.Proto3 {
       repeatedDoubleWrapper_ = other.repeatedDoubleWrapper_.Clone();
       repeatedStringWrapper_ = other.repeatedStringWrapper_.Clone();
       repeatedBytesWrapper_ = other.repeatedBytesWrapper_.Clone();
-      OptionalDuration = other.optionalDuration_ != null ? other.OptionalDuration.Clone() : null;
-      OptionalTimestamp = other.optionalTimestamp_ != null ? other.OptionalTimestamp.Clone() : null;
-      OptionalFieldMask = other.optionalFieldMask_ != null ? other.OptionalFieldMask.Clone() : null;
-      OptionalStruct = other.optionalStruct_ != null ? other.OptionalStruct.Clone() : null;
-      OptionalAny = other.optionalAny_ != null ? other.OptionalAny.Clone() : null;
-      OptionalValue = other.optionalValue_ != null ? other.OptionalValue.Clone() : null;
+      optionalDuration_ = other.optionalDuration_ != null ? other.optionalDuration_.Clone() : null;
+      optionalTimestamp_ = other.optionalTimestamp_ != null ? other.optionalTimestamp_.Clone() : null;
+      optionalFieldMask_ = other.optionalFieldMask_ != null ? other.optionalFieldMask_.Clone() : null;
+      optionalStruct_ = other.optionalStruct_ != null ? other.optionalStruct_.Clone() : null;
+      optionalAny_ = other.optionalAny_ != null ? other.optionalAny_.Clone() : null;
+      optionalValue_ = other.optionalValue_ != null ? other.optionalValue_.Clone() : null;
       repeatedDuration_ = other.repeatedDuration_.Clone();
       repeatedTimestamp_ = other.repeatedTimestamp_.Clone();
       repeatedFieldmask_ = other.repeatedFieldmask_.Clone();
@@ -3455,7 +3455,7 @@ namespace ProtobufTestMessages.Proto3 {
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
         public NestedMessage(NestedMessage other) : this() {
           a_ = other.a_;
-          Corecursive = other.corecursive_ != null ? other.Corecursive.Clone() : null;
+          corecursive_ = other.corecursive_ != null ? other.corecursive_.Clone() : null;
           _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
         }
 

+ 3 - 3
csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs

@@ -1740,9 +1740,9 @@ namespace UnitTest.Issues.TestProtos {
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public ComplexOptionType2(ComplexOptionType2 other) : this() {
-      Bar = other.bar_ != null ? other.Bar.Clone() : null;
+      bar_ = other.bar_ != null ? other.bar_.Clone() : null;
       baz_ = other.baz_;
-      Fred = other.fred_ != null ? other.Fred.Clone() : null;
+      fred_ = other.fred_ != null ? other.fred_.Clone() : null;
       barney_ = other.barney_.Clone();
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
@@ -2331,7 +2331,7 @@ namespace UnitTest.Issues.TestProtos {
     public Aggregate(Aggregate other) : this() {
       i_ = other.i_;
       s_ = other.s_;
-      Sub = other.sub_ != null ? other.Sub.Clone() : null;
+      sub_ = other.sub_ != null ? other.sub_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 

+ 1 - 1
csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs

@@ -704,7 +704,7 @@ namespace UnitTest.Issues.TestProtos {
     public DeprecatedFieldsMessage(DeprecatedFieldsMessage other) : this() {
       primitiveValue_ = other.primitiveValue_;
       primitiveArray_ = other.primitiveArray_.Clone();
-      MessageValue = other.messageValue_ != null ? other.MessageValue.Clone() : null;
+      messageValue_ = other.messageValue_ != null ? other.messageValue_.Clone() : null;
       messageArray_ = other.messageArray_.Clone();
       enumValue_ = other.enumValue_;
       enumArray_ = other.enumArray_.Clone();

+ 12 - 12
csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs

@@ -280,13 +280,13 @@ namespace Google.Protobuf.TestProtos {
       singleBool_ = other.singleBool_;
       singleString_ = other.singleString_;
       singleBytes_ = other.singleBytes_;
-      SingleNestedMessage = other.singleNestedMessage_ != null ? other.SingleNestedMessage.Clone() : null;
-      SingleForeignMessage = other.singleForeignMessage_ != null ? other.SingleForeignMessage.Clone() : null;
-      SingleImportMessage = other.singleImportMessage_ != null ? other.SingleImportMessage.Clone() : null;
+      singleNestedMessage_ = other.singleNestedMessage_ != null ? other.singleNestedMessage_.Clone() : null;
+      singleForeignMessage_ = other.singleForeignMessage_ != null ? other.singleForeignMessage_.Clone() : null;
+      singleImportMessage_ = other.singleImportMessage_ != null ? other.singleImportMessage_.Clone() : null;
       singleNestedEnum_ = other.singleNestedEnum_;
       singleForeignEnum_ = other.singleForeignEnum_;
       singleImportEnum_ = other.singleImportEnum_;
-      SinglePublicImportMessage = other.singlePublicImportMessage_ != null ? other.SinglePublicImportMessage.Clone() : null;
+      singlePublicImportMessage_ = other.singlePublicImportMessage_ != null ? other.singlePublicImportMessage_.Clone() : null;
       repeatedInt32_ = other.repeatedInt32_.Clone();
       repeatedInt64_ = other.repeatedInt64_.Clone();
       repeatedUint32_ = other.repeatedUint32_.Clone();
@@ -1786,8 +1786,8 @@ namespace Google.Protobuf.TestProtos {
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public NestedTestAllTypes(NestedTestAllTypes other) : this() {
-      Child = other.child_ != null ? other.Child.Clone() : null;
-      Payload = other.payload_ != null ? other.Payload.Clone() : null;
+      child_ = other.child_ != null ? other.child_.Clone() : null;
+      payload_ = other.payload_ != null ? other.payload_.Clone() : null;
       repeatedChild_ = other.repeatedChild_.Clone();
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
@@ -2342,7 +2342,7 @@ namespace Google.Protobuf.TestProtos {
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public TestForeignNested(TestForeignNested other) : this() {
-      ForeignNested = other.foreignNested_ != null ? other.ForeignNested.Clone() : null;
+      foreignNested_ = other.foreignNested_ != null ? other.foreignNested_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 
@@ -2641,7 +2641,7 @@ namespace Google.Protobuf.TestProtos {
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public TestRecursiveMessage(TestRecursiveMessage other) : this() {
-      A = other.a_ != null ? other.A.Clone() : null;
+      a_ = other.a_ != null ? other.a_.Clone() : null;
       i_ = other.i_;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
@@ -2807,7 +2807,7 @@ namespace Google.Protobuf.TestProtos {
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public TestMutualRecursionA(TestMutualRecursionA other) : this() {
-      Bb = other.bb_ != null ? other.Bb.Clone() : null;
+      bb_ = other.bb_ != null ? other.bb_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 
@@ -2942,7 +2942,7 @@ namespace Google.Protobuf.TestProtos {
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public TestMutualRecursionB(TestMutualRecursionB other) : this() {
-      A = other.a_ != null ? other.A.Clone() : null;
+      a_ = other.a_ != null ? other.a_.Clone() : null;
       optionalInt32_ = other.optionalInt32_;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
@@ -3241,7 +3241,7 @@ namespace Google.Protobuf.TestProtos {
       primitiveField_ = other.primitiveField_;
       stringField_ = other.stringField_;
       enumField_ = other.enumField_;
-      MessageField = other.messageField_ != null ? other.MessageField.Clone() : null;
+      messageField_ = other.messageField_ != null ? other.messageField_.Clone() : null;
       repeatedPrimitiveField_ = other.repeatedPrimitiveField_.Clone();
       repeatedStringField_ = other.repeatedStringField_.Clone();
       repeatedEnumField_ = other.repeatedEnumField_.Clone();
@@ -3546,7 +3546,7 @@ namespace Google.Protobuf.TestProtos {
       myString_ = other.myString_;
       myInt_ = other.myInt_;
       myFloat_ = other.myFloat_;
-      SingleNestedMessage = other.singleNestedMessage_ != null ? other.SingleNestedMessage.Clone() : null;
+      singleNestedMessage_ = other.singleNestedMessage_ != null ? other.singleNestedMessage_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 

+ 10 - 10
csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs

@@ -204,15 +204,15 @@ namespace Google.Protobuf.TestProtos {
 
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public TestWellKnownTypes(TestWellKnownTypes other) : this() {
-      AnyField = other.anyField_ != null ? other.AnyField.Clone() : null;
-      ApiField = other.apiField_ != null ? other.ApiField.Clone() : null;
-      DurationField = other.durationField_ != null ? other.DurationField.Clone() : null;
-      EmptyField = other.emptyField_ != null ? other.EmptyField.Clone() : null;
-      FieldMaskField = other.fieldMaskField_ != null ? other.FieldMaskField.Clone() : null;
-      SourceContextField = other.sourceContextField_ != null ? other.SourceContextField.Clone() : null;
-      StructField = other.structField_ != null ? other.StructField.Clone() : null;
-      TimestampField = other.timestampField_ != null ? other.TimestampField.Clone() : null;
-      TypeField = other.typeField_ != null ? other.TypeField.Clone() : null;
+      anyField_ = other.anyField_ != null ? other.anyField_.Clone() : null;
+      apiField_ = other.apiField_ != null ? other.apiField_.Clone() : null;
+      durationField_ = other.durationField_ != null ? other.durationField_.Clone() : null;
+      emptyField_ = other.emptyField_ != null ? other.emptyField_.Clone() : null;
+      fieldMaskField_ = other.fieldMaskField_ != null ? other.fieldMaskField_.Clone() : null;
+      sourceContextField_ = other.sourceContextField_ != null ? other.sourceContextField_.Clone() : null;
+      structField_ = other.structField_ != null ? other.structField_.Clone() : null;
+      timestampField_ = other.timestampField_ != null ? other.timestampField_.Clone() : null;
+      typeField_ = other.typeField_ != null ? other.typeField_.Clone() : null;
       DoubleField = other.DoubleField;
       FloatField = other.FloatField;
       Int64Field = other.Int64Field;
@@ -222,7 +222,7 @@ namespace Google.Protobuf.TestProtos {
       BoolField = other.BoolField;
       StringField = other.StringField;
       BytesField = other.BytesField;
-      ValueField = other.valueField_ != null ? other.ValueField.Clone() : null;
+      valueField_ = other.valueField_ != null ? other.valueField_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 

+ 10 - 10
csharp/src/Google.Protobuf/Reflection/Descriptor.cs

@@ -350,8 +350,8 @@ namespace Google.Protobuf.Reflection {
       enumType_ = other.enumType_.Clone();
       service_ = other.service_.Clone();
       extension_ = other.extension_.Clone();
-      Options = other.options_ != null ? other.Options.Clone() : null;
-      SourceCodeInfo = other.sourceCodeInfo_ != null ? other.SourceCodeInfo.Clone() : null;
+      options_ = other.options_ != null ? other.options_.Clone() : null;
+      sourceCodeInfo_ = other.sourceCodeInfo_ != null ? other.sourceCodeInfo_.Clone() : null;
       syntax_ = other.syntax_;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
@@ -775,7 +775,7 @@ namespace Google.Protobuf.Reflection {
       enumType_ = other.enumType_.Clone();
       extensionRange_ = other.extensionRange_.Clone();
       oneofDecl_ = other.oneofDecl_.Clone();
-      Options = other.options_ != null ? other.Options.Clone() : null;
+      options_ = other.options_ != null ? other.options_.Clone() : null;
       reservedRange_ = other.reservedRange_.Clone();
       reservedName_ = other.reservedName_.Clone();
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -1099,7 +1099,7 @@ namespace Google.Protobuf.Reflection {
         public ExtensionRange(ExtensionRange other) : this() {
           start_ = other.start_;
           end_ = other.end_;
-          Options = other.options_ != null ? other.Options.Clone() : null;
+          options_ = other.options_ != null ? other.options_.Clone() : null;
           _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
         }
 
@@ -1597,7 +1597,7 @@ namespace Google.Protobuf.Reflection {
       defaultValue_ = other.defaultValue_;
       oneofIndex_ = other.oneofIndex_;
       jsonName_ = other.jsonName_;
-      Options = other.options_ != null ? other.Options.Clone() : null;
+      options_ = other.options_ != null ? other.options_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 
@@ -2078,7 +2078,7 @@ namespace Google.Protobuf.Reflection {
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public OneofDescriptorProto(OneofDescriptorProto other) : this() {
       name_ = other.name_;
-      Options = other.options_ != null ? other.Options.Clone() : null;
+      options_ = other.options_ != null ? other.options_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 
@@ -2245,7 +2245,7 @@ namespace Google.Protobuf.Reflection {
     public EnumDescriptorProto(EnumDescriptorProto other) : this() {
       name_ = other.name_;
       value_ = other.value_.Clone();
-      Options = other.options_ != null ? other.Options.Clone() : null;
+      options_ = other.options_ != null ? other.options_.Clone() : null;
       reservedRange_ = other.reservedRange_.Clone();
       reservedName_ = other.reservedName_.Clone();
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -2658,7 +2658,7 @@ namespace Google.Protobuf.Reflection {
     public EnumValueDescriptorProto(EnumValueDescriptorProto other) : this() {
       name_ = other.name_;
       number_ = other.number_;
-      Options = other.options_ != null ? other.Options.Clone() : null;
+      options_ = other.options_ != null ? other.options_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 
@@ -2852,7 +2852,7 @@ namespace Google.Protobuf.Reflection {
     public ServiceDescriptorProto(ServiceDescriptorProto other) : this() {
       name_ = other.name_;
       method_ = other.method_.Clone();
-      Options = other.options_ != null ? other.Options.Clone() : null;
+      options_ = other.options_ != null ? other.options_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 
@@ -3039,7 +3039,7 @@ namespace Google.Protobuf.Reflection {
       name_ = other.name_;
       inputType_ = other.inputType_;
       outputType_ = other.outputType_;
-      Options = other.options_ != null ? other.Options.Clone() : null;
+      options_ = other.options_ != null ? other.options_.Clone() : null;
       clientStreaming_ = other.clientStreaming_;
       serverStreaming_ = other.serverStreaming_;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);

+ 1 - 1
csharp/src/Google.Protobuf/WellKnownTypes/Api.cs

@@ -93,7 +93,7 @@ namespace Google.Protobuf.WellKnownTypes {
       methods_ = other.methods_.Clone();
       options_ = other.options_.Clone();
       version_ = other.version_;
-      SourceContext = other.sourceContext_ != null ? other.SourceContext.Clone() : null;
+      sourceContext_ = other.sourceContext_ != null ? other.sourceContext_.Clone() : null;
       mixins_ = other.mixins_.Clone();
       syntax_ = other.syntax_;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);

+ 3 - 3
csharp/src/Google.Protobuf/WellKnownTypes/Type.cs

@@ -123,7 +123,7 @@ namespace Google.Protobuf.WellKnownTypes {
       fields_ = other.fields_.Clone();
       oneofs_ = other.oneofs_.Clone();
       options_ = other.options_.Clone();
-      SourceContext = other.sourceContext_ != null ? other.SourceContext.Clone() : null;
+      sourceContext_ = other.sourceContext_ != null ? other.sourceContext_.Clone() : null;
       syntax_ = other.syntax_;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
@@ -913,7 +913,7 @@ namespace Google.Protobuf.WellKnownTypes {
       name_ = other.name_;
       enumvalue_ = other.enumvalue_.Clone();
       options_ = other.options_.Clone();
-      SourceContext = other.sourceContext_ != null ? other.SourceContext.Clone() : null;
+      sourceContext_ = other.sourceContext_ != null ? other.sourceContext_.Clone() : null;
       syntax_ = other.syntax_;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
@@ -1350,7 +1350,7 @@ namespace Google.Protobuf.WellKnownTypes {
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
     public Option(Option other) : this() {
       name_ = other.name_;
-      Value = other.value_ != null ? other.Value.Clone() : null;
+      value_ = other.value_ != null ? other.value_.Clone() : null;
       _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
     }
 

+ 1 - 1
src/google/protobuf/compiler/csharp/csharp_message_field.cc

@@ -133,7 +133,7 @@ void MessageFieldGenerator::WriteToString(io::Printer* printer) {
 
 void MessageFieldGenerator::GenerateCloningCode(io::Printer* printer) {
   printer->Print(variables_,
-    "$property_name$ = other.$has_property_check$ ? other.$property_name$.Clone() : null;\n");
+    "$name$_ = other.$has_property_check$ ? other.$name$_.Clone() : null;\n");
 }
 
 void MessageFieldGenerator::GenerateFreezingCode(io::Printer* printer) {