Skip to content

Commit

Permalink
Write messages to backing field in generated C# cloning code (protoco…
Browse files Browse the repository at this point in the history
…lbuffers#4440)

* Edited MessageFieldGenerator to clone to backing field instead of property

* Generated C# proto code
  • Loading branch information
ObsidianMinor authored and anandolee committed Apr 19, 2018
1 parent 0dc4d75 commit 4ca46ed
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion csharp/src/AddressBook/Addressbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Person(Person other) : this() {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ public TestMapSubmessage() {

[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);
}

Expand Down
20 changes: 10 additions & 10 deletions csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ public TestAllTypesProto3(TestAllTypesProto3 other) : this() {
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();
Expand Down Expand Up @@ -338,12 +338,12 @@ public TestAllTypesProto3(TestAllTypesProto3 other) : this() {
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();
Expand Down Expand Up @@ -3455,7 +3455,7 @@ public NestedMessage() {
[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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1740,9 +1740,9 @@ public ComplexOptionType2() {

[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);
}
Expand Down Expand Up @@ -2331,7 +2331,7 @@ public Aggregate() {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public DeprecatedFieldsMessage() {
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();
Expand Down
24 changes: 12 additions & 12 deletions csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ public TestAllTypes(TestAllTypes other) : this() {
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();
Expand Down Expand Up @@ -1786,8 +1786,8 @@ public NestedTestAllTypes() {

[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);
}
Expand Down Expand Up @@ -2342,7 +2342,7 @@ public TestForeignNested() {

[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);
}

Expand Down Expand Up @@ -2641,7 +2641,7 @@ public TestRecursiveMessage() {

[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);
}
Expand Down Expand Up @@ -2807,7 +2807,7 @@ public TestMutualRecursionA() {

[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);
}

Expand Down Expand Up @@ -2942,7 +2942,7 @@ public TestMutualRecursionB() {

[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);
}
Expand Down Expand Up @@ -3241,7 +3241,7 @@ public TestCamelCaseFieldNames(TestCamelCaseFieldNames other) : this() {
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();
Expand Down Expand Up @@ -3546,7 +3546,7 @@ public TestFieldOrderings(TestFieldOrderings other) : this() {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ public TestWellKnownTypes() {

[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;
Expand All @@ -222,7 +222,7 @@ public TestWellKnownTypes(TestWellKnownTypes other) : this() {
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);
}

Expand Down
20 changes: 10 additions & 10 deletions csharp/src/Google.Protobuf/Reflection/Descriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ public FileDescriptorProto(FileDescriptorProto other) : this() {
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);
}
Expand Down Expand Up @@ -775,7 +775,7 @@ public DescriptorProto(DescriptorProto other) : this() {
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);
Expand Down Expand Up @@ -1099,7 +1099,7 @@ public ExtensionRange() {
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);
}

Expand Down Expand Up @@ -1597,7 +1597,7 @@ public FieldDescriptorProto(FieldDescriptorProto other) : this() {
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);
}

Expand Down Expand Up @@ -2078,7 +2078,7 @@ public OneofDescriptorProto() {
[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);
}

Expand Down Expand Up @@ -2245,7 +2245,7 @@ public EnumDescriptorProto() {
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);
Expand Down Expand Up @@ -2658,7 +2658,7 @@ public EnumValueDescriptorProto() {
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);
}

Expand Down Expand Up @@ -2852,7 +2852,7 @@ public ServiceDescriptorProto() {
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);
}

Expand Down Expand Up @@ -3039,7 +3039,7 @@ public MethodDescriptorProto(MethodDescriptorProto other) : this() {
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);
Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Api(Api other) : this() {
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);
Expand Down
6 changes: 3 additions & 3 deletions csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Type(Type other) : this() {
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);
}
Expand Down Expand Up @@ -913,7 +913,7 @@ public Enum(Enum other) : this() {
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);
}
Expand Down Expand Up @@ -1350,7 +1350,7 @@ public Option() {
[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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4ca46ed

Please sign in to comment.