From 1a0764ab27ae7189ae4b2b8a1d9f7a0599568282 Mon Sep 17 00:00:00 2001 From: csharptest Date: Fri, 9 Sep 2011 21:05:29 -0500 Subject: [PATCH 1/4] First pass at implementation and testing of reusable builders. --- src/AddressBook/AddressBookProtos.cs | 176 +- src/ProtoGen/EnumFieldGenerator.cs | 2 + src/ProtoGen/MessageFieldGenerator.cs | 4 + src/ProtoGen/MessageGenerator.cs | 55 +- src/ProtoGen/PrimitiveFieldGenerator.cs | 2 + src/ProtoGen/RepeatedEnumFieldGenerator.cs | 6 +- src/ProtoGen/RepeatedMessageFieldGenerator.cs | 8 +- .../RepeatedPrimitiveFieldGenerator.cs | 6 +- .../GeneratedMessageTest.cs | 16 - .../ProtocolBuffers.Test.csproj | 1 + .../ReusableBuilderTest.cs | 117 + .../UnitTestCSharpOptionsProtoFile.cs | 56 +- .../UnitTestCustomOptionsProtoFile.cs | 880 ++++-- .../UnitTestEmbedOptimizeForProtoFile.cs | 62 +- .../UnitTestExtrasIssuesProtoFile.cs | 208 +- .../TestProtos/UnitTestGoogleSizeProtoFile.cs | 514 ++- .../UnitTestGoogleSpeedProtoFile.cs | 524 +++- .../TestProtos/UnitTestImportLiteProtoFile.cs | 52 +- .../TestProtos/UnitTestImportProtoFile.cs | 52 +- .../TestProtos/UnitTestMessageSetProtoFile.cs | 320 +- .../UnitTestNoGenericServicesProtoFile.cs | 52 +- .../UnitTestOptimizeForProtoFile.cs | 156 +- .../TestProtos/UnitTestProtoFile.cs | 2780 ++++++++++++++--- .../TestProtos/UnitTestRpcInterop.cs | 228 +- .../UnitTestXmlSerializerTestProtoFile.cs | 352 ++- .../DescriptorProtos/CSharpOptions.cs | 232 +- .../DescriptorProtos/DescriptorProtoFile.cs | 1172 +++++-- src/ProtocolBuffers/GeneratedBuilder.cs | 11 +- src/ProtocolBuffers/GeneratedBuilderLite.cs | 7 +- .../TestProtos/UnitTestExtrasFullProtoFile.cs | 462 ++- .../TestProtos/UnitTestExtrasLiteProtoFile.cs | 298 +- .../TestProtos/UnitTestImportLiteProtoFile.cs | 52 +- .../TestProtos/UnitTestImportProtoFile.cs | 52 +- .../UnitTestLiteImportNonLiteProtoFile.cs | 54 +- .../TestProtos/UnitTestLiteProtoFile.cs | 1130 +++++-- .../TestProtos/UnitTestProtoFile.cs | 2780 ++++++++++++++--- 36 files changed, 10475 insertions(+), 2404 deletions(-) create mode 100644 src/ProtocolBuffers.Test/ReusableBuilderTest.cs diff --git a/src/AddressBook/AddressBookProtos.cs b/src/AddressBook/AddressBookProtos.cs index 4d391f0fe1..8bb19df6c3 100644 --- a/src/AddressBook/AddressBookProtos.cs +++ b/src/AddressBook/AddressBookProtos.cs @@ -223,7 +223,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(PhoneNumber prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -233,21 +233,48 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new PhoneNumber(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(PhoneNumber cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - PhoneNumber result = new PhoneNumber(); + bool builderIsReadOnly; + PhoneNumber result; + + private PhoneNumber PrepareBuilder() { + if (builderIsReadOnly) { + PhoneNumber original = result; + result = new PhoneNumber(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override PhoneNumber MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new PhoneNumber(); + result = DefaultInstance ?? new PhoneNumber(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -259,12 +286,11 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public override PhoneNumber BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - PhoneNumber returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -278,6 +304,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { public override Builder MergeFrom(PhoneNumber other) { if (other == global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.DefaultInstance) return this; + PrepareBuilder(); if (other.HasNumber) { Number = other.Number; } @@ -293,6 +320,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -361,11 +389,13 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public Builder SetNumber(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasNumber = true; result.number_ = value; return this; } public Builder ClearNumber() { + PrepareBuilder(); result.hasNumber = false; result.number_ = ""; return this; @@ -379,11 +409,13 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { set { SetType(value); } } public Builder SetType(global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType value) { + PrepareBuilder(); result.hasType = true; result.type_ = value; return this; } public Builder ClearType() { + PrepareBuilder(); result.hasType = false; result.type_ = global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType.HOME; return this; @@ -527,7 +559,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Person prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -537,21 +569,48 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Person(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Person cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - Person result = new Person(); + bool builderIsReadOnly; + Person result; + + private Person PrepareBuilder() { + if (builderIsReadOnly) { + Person original = result; + result = new Person(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Person MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Person(); + result = DefaultInstance ?? new Person(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -563,13 +622,12 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public override Person BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.phone_.MakeReadOnly(); - Person returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -583,6 +641,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { public override Builder MergeFrom(Person other) { if (other == global::Google.ProtocolBuffers.Examples.AddressBook.Person.DefaultInstance) return this; + PrepareBuilder(); if (other.HasName) { Name = other.Name; } @@ -604,6 +663,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -672,11 +732,13 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -690,11 +752,13 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { set { SetId(value); } } public Builder SetId(int value) { + PrepareBuilder(); result.hasId = true; result.id_ = value; return this; } public Builder ClearId() { + PrepareBuilder(); result.hasId = false; result.id_ = 0; return this; @@ -709,18 +773,20 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public Builder SetEmail(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasEmail = true; result.email_ = value; return this; } public Builder ClearEmail() { + PrepareBuilder(); result.hasEmail = false; result.email_ = ""; return this; } public pbc::IPopsicleList PhoneList { - get { return result.phone_; } + get { return PrepareBuilder().phone_; } } public int PhoneCount { get { return result.PhoneCount; } @@ -730,29 +796,35 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public Builder SetPhone(int index, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.phone_[index] = value; return this; } public Builder SetPhone(int index, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.phone_[index] = builderForValue.Build(); return this; } public Builder AddPhone(global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.phone_.Add(value); return this; } public Builder AddPhone(global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.phone_.Add(builderForValue.Build()); return this; } public Builder AddRangePhone(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.phone_); return this; } public Builder ClearPhone() { + PrepareBuilder(); result.phone_.Clear(); return this; } @@ -869,7 +941,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(AddressBook prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -879,21 +951,48 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new AddressBook(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(AddressBook cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - AddressBook result = new AddressBook(); + bool builderIsReadOnly; + AddressBook result; + + private AddressBook PrepareBuilder() { + if (builderIsReadOnly) { + AddressBook original = result; + result = new AddressBook(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override AddressBook MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new AddressBook(); + result = DefaultInstance ?? new AddressBook(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -905,13 +1004,12 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public override AddressBook BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.person_.MakeReadOnly(); - AddressBook returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -925,6 +1023,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { public override Builder MergeFrom(AddressBook other) { if (other == global::Google.ProtocolBuffers.Examples.AddressBook.AddressBook.DefaultInstance) return this; + PrepareBuilder(); if (other.person_.Count != 0) { base.AddRange(other.person_, result.person_); } @@ -937,6 +1036,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -985,7 +1085,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { public pbc::IPopsicleList PersonList { - get { return result.person_; } + get { return PrepareBuilder().person_; } } public int PersonCount { get { return result.PersonCount; } @@ -995,29 +1095,35 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { } public Builder SetPerson(int index, global::Google.ProtocolBuffers.Examples.AddressBook.Person value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.person_[index] = value; return this; } public Builder SetPerson(int index, global::Google.ProtocolBuffers.Examples.AddressBook.Person.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.person_[index] = builderForValue.Build(); return this; } public Builder AddPerson(global::Google.ProtocolBuffers.Examples.AddressBook.Person value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.person_.Add(value); return this; } public Builder AddPerson(global::Google.ProtocolBuffers.Examples.AddressBook.Person.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.person_.Add(builderForValue.Build()); return this; } public Builder AddRangePerson(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.person_); return this; } public Builder ClearPerson() { + PrepareBuilder(); result.person_.Clear(); return this; } diff --git a/src/ProtoGen/EnumFieldGenerator.cs b/src/ProtoGen/EnumFieldGenerator.cs index 8b56b9e96b..84e677ed0d 100644 --- a/src/ProtoGen/EnumFieldGenerator.cs +++ b/src/ProtoGen/EnumFieldGenerator.cs @@ -70,11 +70,13 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("}"); AddClsComplianceCheck(writer); writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.{0}_ = value;", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Clear{0}() {{", PropertyName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.has{0} = false;", PropertyName); writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue); writer.WriteLine(" return this;"); diff --git a/src/ProtoGen/MessageFieldGenerator.cs b/src/ProtoGen/MessageFieldGenerator.cs index b86f2c9adf..fab0f29e49 100644 --- a/src/ProtoGen/MessageFieldGenerator.cs +++ b/src/ProtoGen/MessageFieldGenerator.cs @@ -68,18 +68,21 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("}"); writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName); AddNullCheck(writer); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.{0}_ = value;", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Set{0}({1}.Builder builderForValue) {{", PropertyName, TypeName); AddNullCheck(writer, "builderForValue"); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.{0}_ = builderForValue.Build();", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Merge{0}({1} value) {{", PropertyName, TypeName); AddNullCheck(writer); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" if (result.has{0} &&", PropertyName); writer.WriteLine(" result.{0}_ != {1}) {{", Name, DefaultValue); writer.WriteLine(" result.{0}_ = {1}.CreateBuilder(result.{0}_).MergeFrom(value).BuildPartial();", Name, @@ -91,6 +94,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Clear{0}() {{", PropertyName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.has{0} = false;", PropertyName); writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue); writer.WriteLine(" return this;"); diff --git a/src/ProtoGen/MessageGenerator.cs b/src/ProtoGen/MessageGenerator.cs index 01d47ce216..f191da4fff 100644 --- a/src/ProtoGen/MessageGenerator.cs +++ b/src/ProtoGen/MessageGenerator.cs @@ -551,7 +551,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("public override Builder ToBuilder() { return CreateBuilder(this); }"); writer.WriteLine("public override Builder CreateBuilderForType() { return new Builder(); }"); writer.WriteLine("public static Builder CreateBuilder({0} prototype) {{", ClassName); - writer.WriteLine(" return (Builder) new Builder().MergeFrom(prototype);"); + writer.WriteLine(" return new Builder(prototype);"); writer.WriteLine("}"); writer.WriteLine(); writer.WriteLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); @@ -582,21 +582,52 @@ namespace Google.ProtocolBuffers.ProtoGen private void GenerateCommonBuilderMethods(TextGenerator writer) { - writer.WriteLine("public Builder() {{}}", ClassAccessLevel); + //default constructor + writer.WriteLine("public Builder() {"); + //Durring static initialization of message, DefaultInstance is expected to return null. + writer.WriteLine(" result = DefaultInstance ?? new {0}();", ClassName); + writer.WriteLine(" builderIsReadOnly = result == DefaultInstance;"); + writer.WriteLine("}"); + //clone constructor + writer.WriteLine("internal Builder({0} cloneFrom) {{", ClassName); + writer.WriteLine(" result = cloneFrom;"); + writer.WriteLine(" builderIsReadOnly = true;"); + writer.WriteLine("}"); + writer.WriteLine(); + writer.WriteLine("bool builderIsReadOnly;"); + writer.WriteLine("{0} result;", ClassName); + writer.WriteLine(); + writer.WriteLine("private {0} PrepareBuilder() {{", ClassName); + writer.WriteLine(" if (builderIsReadOnly) {"); + writer.WriteLine(" {0} original = result;", ClassName); + writer.WriteLine(" result = new {0}();", ClassName); + writer.WriteLine(" builderIsReadOnly = false;"); + writer.WriteLine(" MergeFrom(original);"); + writer.WriteLine(" }"); + writer.WriteLine(" return result;"); + writer.WriteLine("}"); writer.WriteLine(); - writer.WriteLine("{0} result = new {0}();", ClassName); + writer.WriteLine("public override bool IsInitialized {"); + writer.WriteLine(" get { return result.IsInitialized; }"); + writer.WriteLine("}"); writer.WriteLine(); writer.WriteLine("protected override {0} MessageBeingBuilt {{", ClassName); - writer.WriteLine(" get { return result; }"); + writer.WriteLine(" get { return PrepareBuilder(); }"); writer.WriteLine("}"); writer.WriteLine(); + //Not actually expecting that DefaultInstance would ever be null here; however, we will ensure it does not break writer.WriteLine("public override Builder Clear() {"); - writer.WriteLine(" result = new {0}();", ClassName); + writer.WriteLine(" result = DefaultInstance ?? new {0}();", ClassName); + writer.WriteLine(" builderIsReadOnly = true;"); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine(); writer.WriteLine("public override Builder Clone() {"); - writer.WriteLine(" return new Builder().MergeFrom(result);"); + writer.WriteLine(" if (builderIsReadOnly) {"); + writer.WriteLine(" return new Builder(result);"); + writer.WriteLine(" } else {"); + writer.WriteLine(" return new Builder().MergeFrom(result);"); + writer.WriteLine(" }"); writer.WriteLine("}"); writer.WriteLine(); if (!UseLiteRuntime) @@ -613,17 +644,15 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("public override {0} BuildPartial() {{", ClassName); writer.Indent(); - writer.WriteLine("if (result == null) {"); - writer.WriteLine( - " throw new global::System.InvalidOperationException(\"build() has already been called on this Builder\");"); + writer.WriteLine("if (builderIsReadOnly) {"); + writer.WriteLine(" return result;"); writer.WriteLine("}"); foreach (FieldDescriptor field in Descriptor.Fields) { CreateFieldGenerator(field).GenerateBuildingCode(writer); } - writer.WriteLine("{0} returnMe = result;", ClassName); - writer.WriteLine("result = null;"); - writer.WriteLine("return returnMe;"); + writer.WriteLine("builderIsReadOnly = true;"); + writer.WriteLine("return result;"); writer.Outdent(); writer.WriteLine("}"); writer.WriteLine(); @@ -644,6 +673,7 @@ namespace Google.ProtocolBuffers.ProtoGen // fields are set so we can skip the merge. writer.Indent(); writer.WriteLine("if (other == {0}.DefaultInstance) return this;", FullClassName); + writer.WriteLine("PrepareBuilder();"); foreach (FieldDescriptor field in Descriptor.Fields) { CreateFieldGenerator(field).GenerateMergingCode(writer); @@ -676,6 +706,7 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine( "public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {"); writer.Indent(); + writer.WriteLine("PrepareBuilder();"); if (!UseLiteRuntime) { writer.WriteLine("pb::UnknownFieldSet.Builder unknownFields = null;"); diff --git a/src/ProtoGen/PrimitiveFieldGenerator.cs b/src/ProtoGen/PrimitiveFieldGenerator.cs index e945bf877f..b9aee8651d 100644 --- a/src/ProtoGen/PrimitiveFieldGenerator.cs +++ b/src/ProtoGen/PrimitiveFieldGenerator.cs @@ -72,11 +72,13 @@ namespace Google.ProtocolBuffers.ProtoGen AddClsComplianceCheck(writer); writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName); AddNullCheck(writer); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.{0}_ = value;", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Clear{0}() {{", PropertyName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.has{0} = false;", PropertyName); writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue); writer.WriteLine(" return this;"); diff --git a/src/ProtoGen/RepeatedEnumFieldGenerator.cs b/src/ProtoGen/RepeatedEnumFieldGenerator.cs index 5880390b99..ae1ed2408f 100644 --- a/src/ProtoGen/RepeatedEnumFieldGenerator.cs +++ b/src/ProtoGen/RepeatedEnumFieldGenerator.cs @@ -71,7 +71,7 @@ namespace Google.ProtocolBuffers.ProtoGen // Note: We can return the original list here, because we make it unmodifiable when we build // We return it via IPopsicleList so that collection initializers work more pleasantly. writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName); - writer.WriteLine(" get {{ return result.{0}_; }}", Name); + writer.WriteLine(" get {{ return PrepareBuilder().{0}_; }}", Name); writer.WriteLine("}"); writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName); @@ -80,18 +80,22 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine(" return result.Get{0}(index);", PropertyName); writer.WriteLine("}"); writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_[index] = value;", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" base.AddRange(values, result.{0}_);", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Clear{0}() {{", PropertyName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_.Clear();", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); diff --git a/src/ProtoGen/RepeatedMessageFieldGenerator.cs b/src/ProtoGen/RepeatedMessageFieldGenerator.cs index bfa0763f6f..c184b34554 100644 --- a/src/ProtoGen/RepeatedMessageFieldGenerator.cs +++ b/src/ProtoGen/RepeatedMessageFieldGenerator.cs @@ -67,7 +67,7 @@ namespace Google.ProtocolBuffers.ProtoGen // Note: We can return the original list here, because we make it unmodifiable when we build // We return it via IPopsicleList so that collection initializers work more pleasantly. writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName); - writer.WriteLine(" get {{ return result.{0}_; }}", Name); + writer.WriteLine(" get {{ return PrepareBuilder().{0}_; }}", Name); writer.WriteLine("}"); writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName); @@ -77,31 +77,37 @@ namespace Google.ProtocolBuffers.ProtoGen writer.WriteLine("}"); writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName); AddNullCheck(writer); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_[index] = value;", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); // Extra overload for builder (just on messages) writer.WriteLine("public Builder Set{0}(int index, {1}.Builder builderForValue) {{", PropertyName, TypeName); AddNullCheck(writer, "builderForValue"); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_[index] = builderForValue.Build();", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName); AddNullCheck(writer); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName); writer.WriteLine(" return this;"); writer.WriteLine("}"); // Extra overload for builder (just on messages) writer.WriteLine("public Builder Add{0}({1}.Builder builderForValue) {{", PropertyName, TypeName); AddNullCheck(writer, "builderForValue"); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_.Add(builderForValue.Build());", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" base.AddRange(values, result.{0}_);", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Clear{0}() {{", PropertyName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_.Clear();", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); diff --git a/src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs b/src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs index 9e7f5f641f..3bbcff52bf 100644 --- a/src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs +++ b/src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs @@ -74,7 +74,7 @@ namespace Google.ProtocolBuffers.ProtoGen // We return it via IPopsicleList so that collection initializers work more pleasantly. AddClsComplianceCheck(writer); writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName); - writer.WriteLine(" get {{ return result.{0}_; }}", Name); + writer.WriteLine(" get {{ return PrepareBuilder().{0}_; }}", Name); writer.WriteLine("}"); writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName); @@ -86,21 +86,25 @@ namespace Google.ProtocolBuffers.ProtoGen AddClsComplianceCheck(writer); writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName); AddNullCheck(writer); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_[index] = value;", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); AddClsComplianceCheck(writer); writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName); AddNullCheck(writer); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName); writer.WriteLine(" return this;"); writer.WriteLine("}"); AddClsComplianceCheck(writer); writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" base.AddRange(values, result.{0}_);", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); writer.WriteLine("public Builder Clear{0}() {{", PropertyName); + writer.WriteLine(" PrepareBuilder();"); writer.WriteLine(" result.{0}_.Clear();", Name); writer.WriteLine(" return this;"); writer.WriteLine("}"); diff --git a/src/ProtocolBuffers.Test/GeneratedMessageTest.cs b/src/ProtocolBuffers.Test/GeneratedMessageTest.cs index 410452d327..12224e9b32 100644 --- a/src/ProtocolBuffers.Test/GeneratedMessageTest.cs +++ b/src/ProtocolBuffers.Test/GeneratedMessageTest.cs @@ -111,22 +111,6 @@ namespace Google.ProtocolBuffers } } - [Test] - public void DoubleBuildError() - { - TestAllTypes.Builder builder = new TestAllTypes.Builder(); - builder.Build(); - try - { - builder.Build(); - Assert.Fail("Should have thrown exception."); - } - catch (InvalidOperationException) - { - // Success. - } - } - [Test] public void DefaultInstance() { diff --git a/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj b/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj index 95ab0b9c63..b1a7e55977 100644 --- a/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj +++ b/src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj @@ -105,6 +105,7 @@ + diff --git a/src/ProtocolBuffers.Test/ReusableBuilderTest.cs b/src/ProtocolBuffers.Test/ReusableBuilderTest.cs new file mode 100644 index 0000000000..4184971f08 --- /dev/null +++ b/src/ProtocolBuffers.Test/ReusableBuilderTest.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using Google.ProtocolBuffers.TestProtos; + +namespace Google.ProtocolBuffers +{ + [TestFixture] + public class ReusableBuilderTest + { + [Test] + public void TestUnmodifiedDefaultInstance() + { + //Simply calling ToBuilder().Build() no longer creates a copy of the message + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + + [Test] + public void BuildMultipleWithoutChange() + { + //Calling Build() or BuildPartial() does not require a copy of the message + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + builder.SetDefaultBool(true); + + TestAllTypes first = builder.BuildPartial(); + //Still the same instance? + Assert.IsTrue(ReferenceEquals(first, builder.Build())); + //Still the same instance? + Assert.IsTrue(ReferenceEquals(first, builder.BuildPartial().ToBuilder().Build())); + } + + [Test] + public void MergeFromDefaultInstance() + { + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + builder.MergeFrom(TestAllTypes.DefaultInstance); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + + [Test] + public void BuildNewBuilderIsDefaultInstance() + { + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, new TestAllTypes.Builder().Build())); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, TestAllTypes.CreateBuilder().Build())); + //last test, if you clear a builder it reverts to default instance + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, + TestAllTypes.CreateBuilder().SetOptionalBool(true).Build().ToBuilder().Clear().Build())); + } + + [Test] + public void CloneOnChangePrimitive() + { + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + builder.SetDefaultBool(true); + Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + + [Test] + public void CloneOnAddRepeatedBool() + { + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + builder.AddRepeatedBool(true); + Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + + [Test] + public void CloneOnChangeMessage() + { + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + builder.SetOptionalForeignMessage(new ForeignMessage.Builder()); + Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + + [Test] + public void CloneOnClearMessage() + { + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + builder.ClearOptionalForeignMessage(); + Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + + [Test] + public void CloneOnAddRepeatedForeignMessage() + { + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + builder.AddRepeatedForeignMessage(ForeignMessage.DefaultInstance); + Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + + [Test] + public void CloneOnChangeEnumValue() + { + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + builder.SetOptionalForeignEnum(ForeignEnum.FOREIGN_BAR); + Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + + [Test] + public void CloneOnAddRepeatedForeignEnum() + { + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + builder.AddRepeatedForeignEnum(ForeignEnum.FOREIGN_BAR); + Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + + } +} diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestCSharpOptionsProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestCSharpOptionsProtoFile.cs index ff726d65de..215b9b4fd2 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestCSharpOptionsProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestCSharpOptionsProtoFile.cs @@ -190,7 +190,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OptionsMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -200,21 +200,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OptionsMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OptionsMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + OptionsMessage result; - OptionsMessage result = new OptionsMessage(); + private OptionsMessage PrepareBuilder() { + if (builderIsReadOnly) { + OptionsMessage original = result; + result = new OptionsMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OptionsMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OptionsMessage(); + result = DefaultInstance ?? new OptionsMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -226,12 +253,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OptionsMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OptionsMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -245,6 +271,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OptionsMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.OptionsMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasNormal) { Normal = other.Normal; } @@ -263,6 +290,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -327,11 +355,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetNormal(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasNormal = true; result.normal_ = value; return this; } public Builder ClearNormal() { + PrepareBuilder(); result.hasNormal = false; result.normal_ = ""; return this; @@ -346,11 +376,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionsMessage_(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionsMessage_ = true; result.optionsMessage_ = value; return this; } public Builder ClearOptionsMessage_() { + PrepareBuilder(); result.hasOptionsMessage_ = false; result.optionsMessage_ = ""; return this; @@ -365,11 +397,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetCustomName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasCustomName = true; result.customized_ = value; return this; } public Builder ClearCustomName() { + PrepareBuilder(); result.hasCustomName = false; result.customized_ = ""; return this; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestCustomOptionsProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestCustomOptionsProtoFile.cs index 0b1be422a6..bc29da2640 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestCustomOptionsProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestCustomOptionsProtoFile.cs @@ -513,7 +513,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMessageWithCustomOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -523,21 +523,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMessageWithCustomOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMessageWithCustomOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestMessageWithCustomOptions result; + + private TestMessageWithCustomOptions PrepareBuilder() { + if (builderIsReadOnly) { + TestMessageWithCustomOptions original = result; + result = new TestMessageWithCustomOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestMessageWithCustomOptions result = new TestMessageWithCustomOptions(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMessageWithCustomOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMessageWithCustomOptions(); + result = DefaultInstance ?? new TestMessageWithCustomOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -549,12 +576,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMessageWithCustomOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMessageWithCustomOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -568,6 +594,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMessageWithCustomOptions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMessageWithCustomOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasField1) { Field1 = other.Field1; } @@ -580,6 +607,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -636,11 +664,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField1(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField1 = true; result.field1_ = value; return this; } public Builder ClearField1() { + PrepareBuilder(); result.hasField1 = false; result.field1_ = ""; return this; @@ -737,7 +767,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(CustomOptionFooRequest prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -747,21 +777,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new CustomOptionFooRequest(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(CustomOptionFooRequest cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + CustomOptionFooRequest result; + + private CustomOptionFooRequest PrepareBuilder() { + if (builderIsReadOnly) { + CustomOptionFooRequest original = result; + result = new CustomOptionFooRequest(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - CustomOptionFooRequest result = new CustomOptionFooRequest(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override CustomOptionFooRequest MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new CustomOptionFooRequest(); + result = DefaultInstance ?? new CustomOptionFooRequest(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -773,12 +830,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override CustomOptionFooRequest BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - CustomOptionFooRequest returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -792,6 +848,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(CustomOptionFooRequest other) { if (other == global::Google.ProtocolBuffers.TestProtos.CustomOptionFooRequest.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -801,6 +858,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -935,7 +993,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(CustomOptionFooResponse prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -945,21 +1003,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new CustomOptionFooResponse(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(CustomOptionFooResponse cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - CustomOptionFooResponse result = new CustomOptionFooResponse(); + bool builderIsReadOnly; + CustomOptionFooResponse result; + + private CustomOptionFooResponse PrepareBuilder() { + if (builderIsReadOnly) { + CustomOptionFooResponse original = result; + result = new CustomOptionFooResponse(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override CustomOptionFooResponse MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new CustomOptionFooResponse(); + result = DefaultInstance ?? new CustomOptionFooResponse(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -971,12 +1056,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override CustomOptionFooResponse BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - CustomOptionFooResponse returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -990,6 +1074,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(CustomOptionFooResponse other) { if (other == global::Google.ProtocolBuffers.TestProtos.CustomOptionFooResponse.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -999,6 +1084,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1148,7 +1234,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(DummyMessageContainingEnum prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1158,21 +1244,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new DummyMessageContainingEnum(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(DummyMessageContainingEnum cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - DummyMessageContainingEnum result = new DummyMessageContainingEnum(); + bool builderIsReadOnly; + DummyMessageContainingEnum result; + + private DummyMessageContainingEnum PrepareBuilder() { + if (builderIsReadOnly) { + DummyMessageContainingEnum original = result; + result = new DummyMessageContainingEnum(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override DummyMessageContainingEnum MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new DummyMessageContainingEnum(); + result = DefaultInstance ?? new DummyMessageContainingEnum(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1184,12 +1297,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override DummyMessageContainingEnum BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - DummyMessageContainingEnum returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1203,6 +1315,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(DummyMessageContainingEnum other) { if (other == global::Google.ProtocolBuffers.TestProtos.DummyMessageContainingEnum.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -1212,6 +1325,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1346,7 +1460,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(DummyMessageInvalidAsOptionType prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1356,21 +1470,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new DummyMessageInvalidAsOptionType(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(DummyMessageInvalidAsOptionType cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - DummyMessageInvalidAsOptionType result = new DummyMessageInvalidAsOptionType(); + bool builderIsReadOnly; + DummyMessageInvalidAsOptionType result; + + private DummyMessageInvalidAsOptionType PrepareBuilder() { + if (builderIsReadOnly) { + DummyMessageInvalidAsOptionType original = result; + result = new DummyMessageInvalidAsOptionType(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override DummyMessageInvalidAsOptionType MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new DummyMessageInvalidAsOptionType(); + result = DefaultInstance ?? new DummyMessageInvalidAsOptionType(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1382,12 +1523,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override DummyMessageInvalidAsOptionType BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - DummyMessageInvalidAsOptionType returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1401,6 +1541,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(DummyMessageInvalidAsOptionType other) { if (other == global::Google.ProtocolBuffers.TestProtos.DummyMessageInvalidAsOptionType.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -1410,6 +1551,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1544,7 +1686,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(CustomOptionMinIntegerValues prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1554,21 +1696,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new CustomOptionMinIntegerValues(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(CustomOptionMinIntegerValues cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - CustomOptionMinIntegerValues result = new CustomOptionMinIntegerValues(); + bool builderIsReadOnly; + CustomOptionMinIntegerValues result; + + private CustomOptionMinIntegerValues PrepareBuilder() { + if (builderIsReadOnly) { + CustomOptionMinIntegerValues original = result; + result = new CustomOptionMinIntegerValues(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override CustomOptionMinIntegerValues MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new CustomOptionMinIntegerValues(); + result = DefaultInstance ?? new CustomOptionMinIntegerValues(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1580,12 +1749,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override CustomOptionMinIntegerValues BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - CustomOptionMinIntegerValues returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1599,6 +1767,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(CustomOptionMinIntegerValues other) { if (other == global::Google.ProtocolBuffers.TestProtos.CustomOptionMinIntegerValues.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -1608,6 +1777,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1742,7 +1912,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(CustomOptionMaxIntegerValues prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1752,21 +1922,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new CustomOptionMaxIntegerValues(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(CustomOptionMaxIntegerValues cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + CustomOptionMaxIntegerValues result; + + private CustomOptionMaxIntegerValues PrepareBuilder() { + if (builderIsReadOnly) { + CustomOptionMaxIntegerValues original = result; + result = new CustomOptionMaxIntegerValues(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - CustomOptionMaxIntegerValues result = new CustomOptionMaxIntegerValues(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override CustomOptionMaxIntegerValues MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new CustomOptionMaxIntegerValues(); + result = DefaultInstance ?? new CustomOptionMaxIntegerValues(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1778,12 +1975,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override CustomOptionMaxIntegerValues BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - CustomOptionMaxIntegerValues returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1797,6 +1993,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(CustomOptionMaxIntegerValues other) { if (other == global::Google.ProtocolBuffers.TestProtos.CustomOptionMaxIntegerValues.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -1806,6 +2003,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1940,7 +2138,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(CustomOptionOtherValues prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1950,21 +2148,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new CustomOptionOtherValues(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(CustomOptionOtherValues cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + CustomOptionOtherValues result; - CustomOptionOtherValues result = new CustomOptionOtherValues(); + private CustomOptionOtherValues PrepareBuilder() { + if (builderIsReadOnly) { + CustomOptionOtherValues original = result; + result = new CustomOptionOtherValues(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override CustomOptionOtherValues MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new CustomOptionOtherValues(); + result = DefaultInstance ?? new CustomOptionOtherValues(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1976,12 +2201,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override CustomOptionOtherValues BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - CustomOptionOtherValues returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1995,6 +2219,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(CustomOptionOtherValues other) { if (other == global::Google.ProtocolBuffers.TestProtos.CustomOptionOtherValues.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -2004,6 +2229,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -2138,7 +2364,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SettingRealsFromPositiveInts prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -2148,21 +2374,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SettingRealsFromPositiveInts(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SettingRealsFromPositiveInts cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + SettingRealsFromPositiveInts result; - SettingRealsFromPositiveInts result = new SettingRealsFromPositiveInts(); + private SettingRealsFromPositiveInts PrepareBuilder() { + if (builderIsReadOnly) { + SettingRealsFromPositiveInts original = result; + result = new SettingRealsFromPositiveInts(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SettingRealsFromPositiveInts MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SettingRealsFromPositiveInts(); + result = DefaultInstance ?? new SettingRealsFromPositiveInts(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -2174,12 +2427,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SettingRealsFromPositiveInts BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - SettingRealsFromPositiveInts returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -2193,6 +2445,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(SettingRealsFromPositiveInts other) { if (other == global::Google.ProtocolBuffers.TestProtos.SettingRealsFromPositiveInts.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -2202,6 +2455,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -2336,7 +2590,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SettingRealsFromNegativeInts prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -2346,21 +2600,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SettingRealsFromNegativeInts(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SettingRealsFromNegativeInts cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - SettingRealsFromNegativeInts result = new SettingRealsFromNegativeInts(); + bool builderIsReadOnly; + SettingRealsFromNegativeInts result; + + private SettingRealsFromNegativeInts PrepareBuilder() { + if (builderIsReadOnly) { + SettingRealsFromNegativeInts original = result; + result = new SettingRealsFromNegativeInts(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SettingRealsFromNegativeInts MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SettingRealsFromNegativeInts(); + result = DefaultInstance ?? new SettingRealsFromNegativeInts(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -2372,12 +2653,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SettingRealsFromNegativeInts BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - SettingRealsFromNegativeInts returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -2391,6 +2671,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(SettingRealsFromNegativeInts other) { if (other == global::Google.ProtocolBuffers.TestProtos.SettingRealsFromNegativeInts.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -2400,6 +2681,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -2586,7 +2868,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ComplexOptionType1 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -2596,21 +2878,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ComplexOptionType1(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ComplexOptionType1 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ComplexOptionType1 result; + + private ComplexOptionType1 PrepareBuilder() { + if (builderIsReadOnly) { + ComplexOptionType1 original = result; + result = new ComplexOptionType1(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - ComplexOptionType1 result = new ComplexOptionType1(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ComplexOptionType1 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ComplexOptionType1(); + result = DefaultInstance ?? new ComplexOptionType1(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -2622,12 +2931,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ComplexOptionType1 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ComplexOptionType1 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -2641,6 +2949,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ComplexOptionType1 other) { if (other == global::Google.ProtocolBuffers.TestProtos.ComplexOptionType1.DefaultInstance) return this; + PrepareBuilder(); if (other.HasFoo) { Foo = other.Foo; } @@ -2660,6 +2969,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -2723,11 +3033,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetFoo(value); } } public Builder SetFoo(int value) { + PrepareBuilder(); result.hasFoo = true; result.foo_ = value; return this; } public Builder ClearFoo() { + PrepareBuilder(); result.hasFoo = false; result.foo_ = 0; return this; @@ -2741,11 +3053,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetFoo2(value); } } public Builder SetFoo2(int value) { + PrepareBuilder(); result.hasFoo2 = true; result.foo2_ = value; return this; } public Builder ClearFoo2() { + PrepareBuilder(); result.hasFoo2 = false; result.foo2_ = 0; return this; @@ -2759,11 +3073,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetFoo3(value); } } public Builder SetFoo3(int value) { + PrepareBuilder(); result.hasFoo3 = true; result.foo3_ = value; return this; } public Builder ClearFoo3() { + PrepareBuilder(); result.hasFoo3 = false; result.foo3_ = 0; return this; @@ -2910,7 +3226,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ComplexOptionType4 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -2920,21 +3236,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ComplexOptionType4(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ComplexOptionType4 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - ComplexOptionType4 result = new ComplexOptionType4(); + bool builderIsReadOnly; + ComplexOptionType4 result; + + private ComplexOptionType4 PrepareBuilder() { + if (builderIsReadOnly) { + ComplexOptionType4 original = result; + result = new ComplexOptionType4(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ComplexOptionType4 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ComplexOptionType4(); + result = DefaultInstance ?? new ComplexOptionType4(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -2946,12 +3289,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ComplexOptionType4 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ComplexOptionType4 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -2965,6 +3307,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ComplexOptionType4 other) { if (other == global::Google.ProtocolBuffers.TestProtos.ComplexOptionType2.Types.ComplexOptionType4.DefaultInstance) return this; + PrepareBuilder(); if (other.HasWaldo) { Waldo = other.Waldo; } @@ -2977,6 +3320,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -3032,11 +3376,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetWaldo(value); } } public Builder SetWaldo(int value) { + PrepareBuilder(); result.hasWaldo = true; result.waldo_ = value; return this; } public Builder ClearWaldo() { + PrepareBuilder(); result.hasWaldo = false; result.waldo_ = 0; return this; @@ -3164,7 +3510,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ComplexOptionType2 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3174,21 +3520,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ComplexOptionType2(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ComplexOptionType2 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ComplexOptionType2 result; - ComplexOptionType2 result = new ComplexOptionType2(); + private ComplexOptionType2 PrepareBuilder() { + if (builderIsReadOnly) { + ComplexOptionType2 original = result; + result = new ComplexOptionType2(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ComplexOptionType2 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ComplexOptionType2(); + result = DefaultInstance ?? new ComplexOptionType2(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3200,12 +3573,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ComplexOptionType2 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ComplexOptionType2 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -3219,6 +3591,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ComplexOptionType2 other) { if (other == global::Google.ProtocolBuffers.TestProtos.ComplexOptionType2.DefaultInstance) return this; + PrepareBuilder(); if (other.HasBar) { MergeBar(other.Bar); } @@ -3238,6 +3611,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -3312,18 +3686,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetBar(global::Google.ProtocolBuffers.TestProtos.ComplexOptionType1 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasBar = true; result.bar_ = value; return this; } public Builder SetBar(global::Google.ProtocolBuffers.TestProtos.ComplexOptionType1.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasBar = true; result.bar_ = builderForValue.Build(); return this; } public Builder MergeBar(global::Google.ProtocolBuffers.TestProtos.ComplexOptionType1 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasBar && result.bar_ != global::Google.ProtocolBuffers.TestProtos.ComplexOptionType1.DefaultInstance) { result.bar_ = global::Google.ProtocolBuffers.TestProtos.ComplexOptionType1.CreateBuilder(result.bar_).MergeFrom(value).BuildPartial(); @@ -3334,6 +3711,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearBar() { + PrepareBuilder(); result.hasBar = false; result.bar_ = global::Google.ProtocolBuffers.TestProtos.ComplexOptionType1.DefaultInstance; return this; @@ -3347,11 +3725,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetBaz(value); } } public Builder SetBaz(int value) { + PrepareBuilder(); result.hasBaz = true; result.baz_ = value; return this; } public Builder ClearBaz() { + PrepareBuilder(); result.hasBaz = false; result.baz_ = 0; return this; @@ -3366,18 +3746,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetFred(global::Google.ProtocolBuffers.TestProtos.ComplexOptionType2.Types.ComplexOptionType4 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasFred = true; result.fred_ = value; return this; } public Builder SetFred(global::Google.ProtocolBuffers.TestProtos.ComplexOptionType2.Types.ComplexOptionType4.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasFred = true; result.fred_ = builderForValue.Build(); return this; } public Builder MergeFred(global::Google.ProtocolBuffers.TestProtos.ComplexOptionType2.Types.ComplexOptionType4 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasFred && result.fred_ != global::Google.ProtocolBuffers.TestProtos.ComplexOptionType2.Types.ComplexOptionType4.DefaultInstance) { result.fred_ = global::Google.ProtocolBuffers.TestProtos.ComplexOptionType2.Types.ComplexOptionType4.CreateBuilder(result.fred_).MergeFrom(value).BuildPartial(); @@ -3388,6 +3771,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearFred() { + PrepareBuilder(); result.hasFred = false; result.fred_ = global::Google.ProtocolBuffers.TestProtos.ComplexOptionType2.Types.ComplexOptionType4.DefaultInstance; return this; @@ -3532,7 +3916,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ComplexOptionType5 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3542,21 +3926,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ComplexOptionType5(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ComplexOptionType5 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ComplexOptionType5 result; + + private ComplexOptionType5 PrepareBuilder() { + if (builderIsReadOnly) { + ComplexOptionType5 original = result; + result = new ComplexOptionType5(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - ComplexOptionType5 result = new ComplexOptionType5(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ComplexOptionType5 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ComplexOptionType5(); + result = DefaultInstance ?? new ComplexOptionType5(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3568,12 +3979,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ComplexOptionType5 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ComplexOptionType5 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -3587,6 +3997,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ComplexOptionType5 other) { if (other == global::Google.ProtocolBuffers.TestProtos.ComplexOptionType3.Types.ComplexOptionType5.DefaultInstance) return this; + PrepareBuilder(); if (other.HasPlugh) { Plugh = other.Plugh; } @@ -3599,6 +4010,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -3654,11 +4066,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetPlugh(value); } } public Builder SetPlugh(int value) { + PrepareBuilder(); result.hasPlugh = true; result.plugh_ = value; return this; } public Builder ClearPlugh() { + PrepareBuilder(); result.hasPlugh = false; result.plugh_ = 0; return this; @@ -3763,7 +4177,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ComplexOptionType3 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3773,21 +4187,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ComplexOptionType3(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ComplexOptionType3 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - ComplexOptionType3 result = new ComplexOptionType3(); + bool builderIsReadOnly; + ComplexOptionType3 result; + + private ComplexOptionType3 PrepareBuilder() { + if (builderIsReadOnly) { + ComplexOptionType3 original = result; + result = new ComplexOptionType3(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ComplexOptionType3 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ComplexOptionType3(); + result = DefaultInstance ?? new ComplexOptionType3(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3799,12 +4240,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ComplexOptionType3 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ComplexOptionType3 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -3818,6 +4258,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ComplexOptionType3 other) { if (other == global::Google.ProtocolBuffers.TestProtos.ComplexOptionType3.DefaultInstance) return this; + PrepareBuilder(); if (other.HasQux) { Qux = other.Qux; } @@ -3833,6 +4274,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -3897,11 +4339,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetQux(value); } } public Builder SetQux(int value) { + PrepareBuilder(); result.hasQux = true; result.qux_ = value; return this; } public Builder ClearQux() { + PrepareBuilder(); result.hasQux = false; result.qux_ = 0; return this; @@ -3916,18 +4360,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetComplexOptionType5(global::Google.ProtocolBuffers.TestProtos.ComplexOptionType3.Types.ComplexOptionType5 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasComplexOptionType5 = true; result.complexOptionType5_ = value; return this; } public Builder SetComplexOptionType5(global::Google.ProtocolBuffers.TestProtos.ComplexOptionType3.Types.ComplexOptionType5.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasComplexOptionType5 = true; result.complexOptionType5_ = builderForValue.Build(); return this; } public Builder MergeComplexOptionType5(global::Google.ProtocolBuffers.TestProtos.ComplexOptionType3.Types.ComplexOptionType5 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasComplexOptionType5 && result.complexOptionType5_ != global::Google.ProtocolBuffers.TestProtos.ComplexOptionType3.Types.ComplexOptionType5.DefaultInstance) { result.complexOptionType5_ = global::Google.ProtocolBuffers.TestProtos.ComplexOptionType3.Types.ComplexOptionType5.CreateBuilder(result.complexOptionType5_).MergeFrom(value).BuildPartial(); @@ -3938,6 +4385,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearComplexOptionType5() { + PrepareBuilder(); result.hasComplexOptionType5 = false; result.complexOptionType5_ = global::Google.ProtocolBuffers.TestProtos.ComplexOptionType3.Types.ComplexOptionType5.DefaultInstance; return this; @@ -4050,7 +4498,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ComplexOpt6 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -4060,21 +4508,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ComplexOpt6(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ComplexOpt6 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ComplexOpt6 result; + + private ComplexOpt6 PrepareBuilder() { + if (builderIsReadOnly) { + ComplexOpt6 original = result; + result = new ComplexOpt6(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - ComplexOpt6 result = new ComplexOpt6(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ComplexOpt6 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ComplexOpt6(); + result = DefaultInstance ?? new ComplexOpt6(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -4086,12 +4561,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ComplexOpt6 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ComplexOpt6 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -4105,6 +4579,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ComplexOpt6 other) { if (other == global::Google.ProtocolBuffers.TestProtos.ComplexOpt6.DefaultInstance) return this; + PrepareBuilder(); if (other.HasXyzzy) { Xyzzy = other.Xyzzy; } @@ -4117,6 +4592,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -4172,11 +4648,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetXyzzy(value); } } public Builder SetXyzzy(int value) { + PrepareBuilder(); result.hasXyzzy = true; result.xyzzy_ = value; return this; } public Builder ClearXyzzy() { + PrepareBuilder(); result.hasXyzzy = false; result.xyzzy_ = 0; return this; @@ -4273,7 +4751,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(VariousComplexOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -4283,21 +4761,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new VariousComplexOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(VariousComplexOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + VariousComplexOptions result; - VariousComplexOptions result = new VariousComplexOptions(); + private VariousComplexOptions PrepareBuilder() { + if (builderIsReadOnly) { + VariousComplexOptions original = result; + result = new VariousComplexOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override VariousComplexOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new VariousComplexOptions(); + result = DefaultInstance ?? new VariousComplexOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -4309,12 +4814,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override VariousComplexOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - VariousComplexOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -4328,6 +4832,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(VariousComplexOptions other) { if (other == global::Google.ProtocolBuffers.TestProtos.VariousComplexOptions.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -4337,6 +4842,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestEmbedOptimizeForProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestEmbedOptimizeForProtoFile.cs index 09ecdd63d4..466cce7327 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestEmbedOptimizeForProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestEmbedOptimizeForProtoFile.cs @@ -186,7 +186,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestEmbedOptimizedForSize prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -196,21 +196,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestEmbedOptimizedForSize(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestEmbedOptimizedForSize cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestEmbedOptimizedForSize result; - TestEmbedOptimizedForSize result = new TestEmbedOptimizedForSize(); + private TestEmbedOptimizedForSize PrepareBuilder() { + if (builderIsReadOnly) { + TestEmbedOptimizedForSize original = result; + result = new TestEmbedOptimizedForSize(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestEmbedOptimizedForSize MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestEmbedOptimizedForSize(); + result = DefaultInstance ?? new TestEmbedOptimizedForSize(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -222,13 +249,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestEmbedOptimizedForSize BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedMessage_.MakeReadOnly(); - TestEmbedOptimizedForSize returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -242,6 +268,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestEmbedOptimizedForSize other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestEmbedOptimizedForSize.DefaultInstance) return this; + PrepareBuilder(); if (other.HasOptionalMessage) { MergeOptionalMessage(other.OptionalMessage); } @@ -257,6 +284,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -322,18 +350,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalMessage = true; result.optionalMessage_ = value; return this; } public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalMessage = true; result.optionalMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalMessage && result.optionalMessage_ != global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.DefaultInstance) { result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.CreateBuilder(result.optionalMessage_).MergeFrom(value).BuildPartial(); @@ -344,13 +375,14 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalMessage() { + PrepareBuilder(); result.hasOptionalMessage = false; result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.DefaultInstance; return this; } public pbc::IPopsicleList RepeatedMessageList { - get { return result.repeatedMessage_; } + get { return PrepareBuilder().repeatedMessage_; } } public int RepeatedMessageCount { get { return result.RepeatedMessageCount; } @@ -360,29 +392,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessage_[index] = value; return this; } public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessage_.Add(value); return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedMessage_); return this; } public Builder ClearRepeatedMessage() { + PrepareBuilder(); result.repeatedMessage_.Clear(); return this; } diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs index db56e8b919..7791759a2a 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs @@ -175,7 +175,7 @@ namespace UnitTest.Issues.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(A prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -185,21 +185,48 @@ namespace UnitTest.Issues.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new A(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(A cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + A result; - A result = new A(); + private A PrepareBuilder() { + if (builderIsReadOnly) { + A original = result; + result = new A(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override A MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new A(); + result = DefaultInstance ?? new A(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -211,12 +238,11 @@ namespace UnitTest.Issues.TestProtos { } public override A BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - A returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -230,6 +256,7 @@ namespace UnitTest.Issues.TestProtos { public override Builder MergeFrom(A other) { if (other == global::UnitTest.Issues.TestProtos.A.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA_) { A_ = other.A_; } @@ -242,6 +269,7 @@ namespace UnitTest.Issues.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -297,11 +325,13 @@ namespace UnitTest.Issues.TestProtos { set { SetA_(value); } } public Builder SetA_(int value) { + PrepareBuilder(); result.hasA_ = true; result.a_ = value; return this; } public Builder ClearA_() { + PrepareBuilder(); result.hasA_ = false; result.a_ = 0; return this; @@ -414,7 +444,7 @@ namespace UnitTest.Issues.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(B prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -424,21 +454,48 @@ namespace UnitTest.Issues.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new B(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(B cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + B result; - B result = new B(); + private B PrepareBuilder() { + if (builderIsReadOnly) { + B original = result; + result = new B(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override B MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new B(); + result = DefaultInstance ?? new B(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -450,12 +507,11 @@ namespace UnitTest.Issues.TestProtos { } public override B BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - B returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -469,6 +525,7 @@ namespace UnitTest.Issues.TestProtos { public override Builder MergeFrom(B other) { if (other == global::UnitTest.Issues.TestProtos.B.DefaultInstance) return this; + PrepareBuilder(); if (other.HasB_) { B_ = other.B_; } @@ -481,6 +538,7 @@ namespace UnitTest.Issues.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -536,11 +594,13 @@ namespace UnitTest.Issues.TestProtos { set { SetB_(value); } } public Builder SetB_(int value) { + PrepareBuilder(); result.hasB_ = true; result.b_ = value; return this; } public Builder ClearB_() { + PrepareBuilder(); result.hasB_ = false; result.b_ = 0; return this; @@ -653,7 +713,7 @@ namespace UnitTest.Issues.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(AB prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -663,21 +723,48 @@ namespace UnitTest.Issues.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new AB(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(AB cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + AB result; - AB result = new AB(); + private AB PrepareBuilder() { + if (builderIsReadOnly) { + AB original = result; + result = new AB(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override AB MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new AB(); + result = DefaultInstance ?? new AB(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -689,12 +776,11 @@ namespace UnitTest.Issues.TestProtos { } public override AB BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - AB returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -708,6 +794,7 @@ namespace UnitTest.Issues.TestProtos { public override Builder MergeFrom(AB other) { if (other == global::UnitTest.Issues.TestProtos.AB.DefaultInstance) return this; + PrepareBuilder(); if (other.HasAB_) { AB_ = other.AB_; } @@ -720,6 +807,7 @@ namespace UnitTest.Issues.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -775,11 +863,13 @@ namespace UnitTest.Issues.TestProtos { set { SetAB_(value); } } public Builder SetAB_(int value) { + PrepareBuilder(); result.hasAB_ = true; result.aB_ = value; return this; } public Builder ClearAB_() { + PrepareBuilder(); result.hasAB_ = false; result.aB_ = 0; return this; @@ -894,7 +984,7 @@ namespace UnitTest.Issues.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(NumberField prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -904,21 +994,48 @@ namespace UnitTest.Issues.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new NumberField(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(NumberField cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + NumberField result; - NumberField result = new NumberField(); + private NumberField PrepareBuilder() { + if (builderIsReadOnly) { + NumberField original = result; + result = new NumberField(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override NumberField MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new NumberField(); + result = DefaultInstance ?? new NumberField(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -930,12 +1047,11 @@ namespace UnitTest.Issues.TestProtos { } public override NumberField BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - NumberField returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -949,6 +1065,7 @@ namespace UnitTest.Issues.TestProtos { public override Builder MergeFrom(NumberField other) { if (other == global::UnitTest.Issues.TestProtos.NumberField.DefaultInstance) return this; + PrepareBuilder(); if (other.Has_01) { _01 = other._01; } @@ -961,6 +1078,7 @@ namespace UnitTest.Issues.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1018,11 +1136,13 @@ namespace UnitTest.Issues.TestProtos { } [global::System.CLSCompliant(false)] public Builder Set_01(int value) { + PrepareBuilder(); result.has_01 = true; result._01_ = value; return this; } public Builder Clear_01() { + PrepareBuilder(); result.has_01 = false; result._01_ = 0; return this; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestGoogleSizeProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestGoogleSizeProtoFile.cs index 77635f2132..64046eebf5 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestGoogleSizeProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestGoogleSizeProtoFile.cs @@ -606,7 +606,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SizeMessage1 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -616,21 +616,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SizeMessage1(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SizeMessage1 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + SizeMessage1 result; + + private SizeMessage1 PrepareBuilder() { + if (builderIsReadOnly) { + SizeMessage1 original = result; + result = new SizeMessage1(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - SizeMessage1 result = new SizeMessage1(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SizeMessage1 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SizeMessage1(); + result = DefaultInstance ?? new SizeMessage1(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -642,13 +669,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SizeMessage1 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.field5_.MakeReadOnly(); - SizeMessage1 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -661,11 +687,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField1(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField1 = true; result.field1_ = value; return this; } public Builder ClearField1() { + PrepareBuilder(); result.hasField1 = false; result.field1_ = ""; return this; @@ -680,11 +708,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField9(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField9 = true; result.field9_ = value; return this; } public Builder ClearField9() { + PrepareBuilder(); result.hasField9 = false; result.field9_ = ""; return this; @@ -699,11 +729,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField18(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField18 = true; result.field18_ = value; return this; } public Builder ClearField18() { + PrepareBuilder(); result.hasField18 = false; result.field18_ = ""; return this; @@ -717,11 +749,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField80(value); } } public Builder SetField80(bool value) { + PrepareBuilder(); result.hasField80 = true; result.field80_ = value; return this; } public Builder ClearField80() { + PrepareBuilder(); result.hasField80 = false; result.field80_ = false; return this; @@ -735,11 +769,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField81(value); } } public Builder SetField81(bool value) { + PrepareBuilder(); result.hasField81 = true; result.field81_ = value; return this; } public Builder ClearField81() { + PrepareBuilder(); result.hasField81 = false; result.field81_ = true; return this; @@ -753,11 +789,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField2(value); } } public Builder SetField2(int value) { + PrepareBuilder(); result.hasField2 = true; result.field2_ = value; return this; } public Builder ClearField2() { + PrepareBuilder(); result.hasField2 = false; result.field2_ = 0; return this; @@ -771,11 +809,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField3(value); } } public Builder SetField3(int value) { + PrepareBuilder(); result.hasField3 = true; result.field3_ = value; return this; } public Builder ClearField3() { + PrepareBuilder(); result.hasField3 = false; result.field3_ = 0; return this; @@ -789,11 +829,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField280(value); } } public Builder SetField280(int value) { + PrepareBuilder(); result.hasField280 = true; result.field280_ = value; return this; } public Builder ClearField280() { + PrepareBuilder(); result.hasField280 = false; result.field280_ = 0; return this; @@ -807,11 +849,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField6(value); } } public Builder SetField6(int value) { + PrepareBuilder(); result.hasField6 = true; result.field6_ = value; return this; } public Builder ClearField6() { + PrepareBuilder(); result.hasField6 = false; result.field6_ = 0; return this; @@ -825,11 +869,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField22(value); } } public Builder SetField22(long value) { + PrepareBuilder(); result.hasField22 = true; result.field22_ = value; return this; } public Builder ClearField22() { + PrepareBuilder(); result.hasField22 = false; result.field22_ = 0L; return this; @@ -844,11 +890,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField4(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField4 = true; result.field4_ = value; return this; } public Builder ClearField4() { + PrepareBuilder(); result.hasField4 = false; result.field4_ = ""; return this; @@ -856,7 +904,7 @@ namespace Google.ProtocolBuffers.TestProtos { [global::System.CLSCompliant(false)] public pbc::IPopsicleList Field5List { - get { return result.field5_; } + get { return PrepareBuilder().field5_; } } public int Field5Count { get { return result.Field5Count; } @@ -867,20 +915,24 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField5(int index, ulong value) { + PrepareBuilder(); result.field5_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddField5(ulong value) { + PrepareBuilder(); result.field5_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeField5(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field5_); return this; } public Builder ClearField5() { + PrepareBuilder(); result.field5_.Clear(); return this; } @@ -893,11 +945,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField59(value); } } public Builder SetField59(bool value) { + PrepareBuilder(); result.hasField59 = true; result.field59_ = value; return this; } public Builder ClearField59() { + PrepareBuilder(); result.hasField59 = false; result.field59_ = false; return this; @@ -912,11 +966,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField7(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField7 = true; result.field7_ = value; return this; } public Builder ClearField7() { + PrepareBuilder(); result.hasField7 = false; result.field7_ = ""; return this; @@ -930,11 +986,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField16(value); } } public Builder SetField16(int value) { + PrepareBuilder(); result.hasField16 = true; result.field16_ = value; return this; } public Builder ClearField16() { + PrepareBuilder(); result.hasField16 = false; result.field16_ = 0; return this; @@ -948,11 +1006,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField130(value); } } public Builder SetField130(int value) { + PrepareBuilder(); result.hasField130 = true; result.field130_ = value; return this; } public Builder ClearField130() { + PrepareBuilder(); result.hasField130 = false; result.field130_ = 0; return this; @@ -966,11 +1026,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField12(value); } } public Builder SetField12(bool value) { + PrepareBuilder(); result.hasField12 = true; result.field12_ = value; return this; } public Builder ClearField12() { + PrepareBuilder(); result.hasField12 = false; result.field12_ = true; return this; @@ -984,11 +1046,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField17(value); } } public Builder SetField17(bool value) { + PrepareBuilder(); result.hasField17 = true; result.field17_ = value; return this; } public Builder ClearField17() { + PrepareBuilder(); result.hasField17 = false; result.field17_ = true; return this; @@ -1002,11 +1066,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField13(value); } } public Builder SetField13(bool value) { + PrepareBuilder(); result.hasField13 = true; result.field13_ = value; return this; } public Builder ClearField13() { + PrepareBuilder(); result.hasField13 = false; result.field13_ = true; return this; @@ -1020,11 +1086,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField14(value); } } public Builder SetField14(bool value) { + PrepareBuilder(); result.hasField14 = true; result.field14_ = value; return this; } public Builder ClearField14() { + PrepareBuilder(); result.hasField14 = false; result.field14_ = true; return this; @@ -1038,11 +1106,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField104(value); } } public Builder SetField104(int value) { + PrepareBuilder(); result.hasField104 = true; result.field104_ = value; return this; } public Builder ClearField104() { + PrepareBuilder(); result.hasField104 = false; result.field104_ = 0; return this; @@ -1056,11 +1126,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField100(value); } } public Builder SetField100(int value) { + PrepareBuilder(); result.hasField100 = true; result.field100_ = value; return this; } public Builder ClearField100() { + PrepareBuilder(); result.hasField100 = false; result.field100_ = 0; return this; @@ -1074,11 +1146,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField101(value); } } public Builder SetField101(int value) { + PrepareBuilder(); result.hasField101 = true; result.field101_ = value; return this; } public Builder ClearField101() { + PrepareBuilder(); result.hasField101 = false; result.field101_ = 0; return this; @@ -1093,11 +1167,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField102(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField102 = true; result.field102_ = value; return this; } public Builder ClearField102() { + PrepareBuilder(); result.hasField102 = false; result.field102_ = ""; return this; @@ -1112,11 +1188,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField103(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField103 = true; result.field103_ = value; return this; } public Builder ClearField103() { + PrepareBuilder(); result.hasField103 = false; result.field103_ = ""; return this; @@ -1130,11 +1208,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField29(value); } } public Builder SetField29(int value) { + PrepareBuilder(); result.hasField29 = true; result.field29_ = value; return this; } public Builder ClearField29() { + PrepareBuilder(); result.hasField29 = false; result.field29_ = 0; return this; @@ -1148,11 +1228,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField30(value); } } public Builder SetField30(bool value) { + PrepareBuilder(); result.hasField30 = true; result.field30_ = value; return this; } public Builder ClearField30() { + PrepareBuilder(); result.hasField30 = false; result.field30_ = false; return this; @@ -1166,11 +1248,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField60(value); } } public Builder SetField60(int value) { + PrepareBuilder(); result.hasField60 = true; result.field60_ = value; return this; } public Builder ClearField60() { + PrepareBuilder(); result.hasField60 = false; result.field60_ = -1; return this; @@ -1184,11 +1268,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField271(value); } } public Builder SetField271(int value) { + PrepareBuilder(); result.hasField271 = true; result.field271_ = value; return this; } public Builder ClearField271() { + PrepareBuilder(); result.hasField271 = false; result.field271_ = -1; return this; @@ -1202,11 +1288,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField272(value); } } public Builder SetField272(int value) { + PrepareBuilder(); result.hasField272 = true; result.field272_ = value; return this; } public Builder ClearField272() { + PrepareBuilder(); result.hasField272 = false; result.field272_ = -1; return this; @@ -1220,11 +1308,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField150(value); } } public Builder SetField150(int value) { + PrepareBuilder(); result.hasField150 = true; result.field150_ = value; return this; } public Builder ClearField150() { + PrepareBuilder(); result.hasField150 = false; result.field150_ = 0; return this; @@ -1238,11 +1328,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField23(value); } } public Builder SetField23(int value) { + PrepareBuilder(); result.hasField23 = true; result.field23_ = value; return this; } public Builder ClearField23() { + PrepareBuilder(); result.hasField23 = false; result.field23_ = 0; return this; @@ -1256,11 +1348,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField24(value); } } public Builder SetField24(bool value) { + PrepareBuilder(); result.hasField24 = true; result.field24_ = value; return this; } public Builder ClearField24() { + PrepareBuilder(); result.hasField24 = false; result.field24_ = false; return this; @@ -1274,11 +1368,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField25(value); } } public Builder SetField25(int value) { + PrepareBuilder(); result.hasField25 = true; result.field25_ = value; return this; } public Builder ClearField25() { + PrepareBuilder(); result.hasField25 = false; result.field25_ = 0; return this; @@ -1293,18 +1389,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField15(global::Google.ProtocolBuffers.TestProtos.SizeMessage1SubMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField15 = true; result.field15_ = value; return this; } public Builder SetField15(global::Google.ProtocolBuffers.TestProtos.SizeMessage1SubMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasField15 = true; result.field15_ = builderForValue.Build(); return this; } public Builder MergeField15(global::Google.ProtocolBuffers.TestProtos.SizeMessage1SubMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasField15 && result.field15_ != global::Google.ProtocolBuffers.TestProtos.SizeMessage1SubMessage.DefaultInstance) { result.field15_ = global::Google.ProtocolBuffers.TestProtos.SizeMessage1SubMessage.CreateBuilder(result.field15_).MergeFrom(value).BuildPartial(); @@ -1315,6 +1414,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearField15() { + PrepareBuilder(); result.hasField15 = false; result.field15_ = global::Google.ProtocolBuffers.TestProtos.SizeMessage1SubMessage.DefaultInstance; return this; @@ -1328,11 +1428,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField78(value); } } public Builder SetField78(bool value) { + PrepareBuilder(); result.hasField78 = true; result.field78_ = value; return this; } public Builder ClearField78() { + PrepareBuilder(); result.hasField78 = false; result.field78_ = false; return this; @@ -1346,11 +1448,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField67(value); } } public Builder SetField67(int value) { + PrepareBuilder(); result.hasField67 = true; result.field67_ = value; return this; } public Builder ClearField67() { + PrepareBuilder(); result.hasField67 = false; result.field67_ = 0; return this; @@ -1364,11 +1468,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField68(value); } } public Builder SetField68(int value) { + PrepareBuilder(); result.hasField68 = true; result.field68_ = value; return this; } public Builder ClearField68() { + PrepareBuilder(); result.hasField68 = false; result.field68_ = 0; return this; @@ -1382,11 +1488,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField128(value); } } public Builder SetField128(int value) { + PrepareBuilder(); result.hasField128 = true; result.field128_ = value; return this; } public Builder ClearField128() { + PrepareBuilder(); result.hasField128 = false; result.field128_ = 0; return this; @@ -1401,11 +1509,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField129(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField129 = true; result.field129_ = value; return this; } public Builder ClearField129() { + PrepareBuilder(); result.hasField129 = false; result.field129_ = "xxxxxxxxxxxxxxxxxxxxx"; return this; @@ -1419,11 +1529,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField131(value); } } public Builder SetField131(int value) { + PrepareBuilder(); result.hasField131 = true; result.field131_ = value; return this; } public Builder ClearField131() { + PrepareBuilder(); result.hasField131 = false; result.field131_ = 0; return this; @@ -1697,7 +1809,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SizeMessage1SubMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1707,21 +1819,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SizeMessage1SubMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SizeMessage1SubMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - SizeMessage1SubMessage result = new SizeMessage1SubMessage(); + bool builderIsReadOnly; + SizeMessage1SubMessage result; + + private SizeMessage1SubMessage PrepareBuilder() { + if (builderIsReadOnly) { + SizeMessage1SubMessage original = result; + result = new SizeMessage1SubMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SizeMessage1SubMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SizeMessage1SubMessage(); + result = DefaultInstance ?? new SizeMessage1SubMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1733,12 +1872,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SizeMessage1SubMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - SizeMessage1SubMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -1750,11 +1888,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField1(value); } } public Builder SetField1(int value) { + PrepareBuilder(); result.hasField1 = true; result.field1_ = value; return this; } public Builder ClearField1() { + PrepareBuilder(); result.hasField1 = false; result.field1_ = 0; return this; @@ -1768,11 +1908,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField2(value); } } public Builder SetField2(int value) { + PrepareBuilder(); result.hasField2 = true; result.field2_ = value; return this; } public Builder ClearField2() { + PrepareBuilder(); result.hasField2 = false; result.field2_ = 0; return this; @@ -1786,11 +1928,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField3(value); } } public Builder SetField3(int value) { + PrepareBuilder(); result.hasField3 = true; result.field3_ = value; return this; } public Builder ClearField3() { + PrepareBuilder(); result.hasField3 = false; result.field3_ = 0; return this; @@ -1805,11 +1949,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField15(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField15 = true; result.field15_ = value; return this; } public Builder ClearField15() { + PrepareBuilder(); result.hasField15 = false; result.field15_ = ""; return this; @@ -1823,11 +1969,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField12(value); } } public Builder SetField12(bool value) { + PrepareBuilder(); result.hasField12 = true; result.field12_ = value; return this; } public Builder ClearField12() { + PrepareBuilder(); result.hasField12 = false; result.field12_ = true; return this; @@ -1841,11 +1989,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField13(value); } } public Builder SetField13(long value) { + PrepareBuilder(); result.hasField13 = true; result.field13_ = value; return this; } public Builder ClearField13() { + PrepareBuilder(); result.hasField13 = false; result.field13_ = 0L; return this; @@ -1859,11 +2009,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField14(value); } } public Builder SetField14(long value) { + PrepareBuilder(); result.hasField14 = true; result.field14_ = value; return this; } public Builder ClearField14() { + PrepareBuilder(); result.hasField14 = false; result.field14_ = 0L; return this; @@ -1877,11 +2029,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField16(value); } } public Builder SetField16(int value) { + PrepareBuilder(); result.hasField16 = true; result.field16_ = value; return this; } public Builder ClearField16() { + PrepareBuilder(); result.hasField16 = false; result.field16_ = 0; return this; @@ -1895,11 +2049,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField19(value); } } public Builder SetField19(int value) { + PrepareBuilder(); result.hasField19 = true; result.field19_ = value; return this; } public Builder ClearField19() { + PrepareBuilder(); result.hasField19 = false; result.field19_ = 2; return this; @@ -1913,11 +2069,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField20(value); } } public Builder SetField20(bool value) { + PrepareBuilder(); result.hasField20 = true; result.field20_ = value; return this; } public Builder ClearField20() { + PrepareBuilder(); result.hasField20 = false; result.field20_ = true; return this; @@ -1931,11 +2089,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField28(value); } } public Builder SetField28(bool value) { + PrepareBuilder(); result.hasField28 = true; result.field28_ = value; return this; } public Builder ClearField28() { + PrepareBuilder(); result.hasField28 = false; result.field28_ = true; return this; @@ -1951,11 +2111,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField21(ulong value) { + PrepareBuilder(); result.hasField21 = true; result.field21_ = value; return this; } public Builder ClearField21() { + PrepareBuilder(); result.hasField21 = false; result.field21_ = 0; return this; @@ -1969,11 +2131,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField22(value); } } public Builder SetField22(int value) { + PrepareBuilder(); result.hasField22 = true; result.field22_ = value; return this; } public Builder ClearField22() { + PrepareBuilder(); result.hasField22 = false; result.field22_ = 0; return this; @@ -1987,11 +2151,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField23(value); } } public Builder SetField23(bool value) { + PrepareBuilder(); result.hasField23 = true; result.field23_ = value; return this; } public Builder ClearField23() { + PrepareBuilder(); result.hasField23 = false; result.field23_ = false; return this; @@ -2005,11 +2171,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField206(value); } } public Builder SetField206(bool value) { + PrepareBuilder(); result.hasField206 = true; result.field206_ = value; return this; } public Builder ClearField206() { + PrepareBuilder(); result.hasField206 = false; result.field206_ = false; return this; @@ -2025,11 +2193,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField203(uint value) { + PrepareBuilder(); result.hasField203 = true; result.field203_ = value; return this; } public Builder ClearField203() { + PrepareBuilder(); result.hasField203 = false; result.field203_ = 0; return this; @@ -2043,11 +2213,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField204(value); } } public Builder SetField204(int value) { + PrepareBuilder(); result.hasField204 = true; result.field204_ = value; return this; } public Builder ClearField204() { + PrepareBuilder(); result.hasField204 = false; result.field204_ = 0; return this; @@ -2062,11 +2234,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField205(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField205 = true; result.field205_ = value; return this; } public Builder ClearField205() { + PrepareBuilder(); result.hasField205 = false; result.field205_ = ""; return this; @@ -2082,11 +2256,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField207(ulong value) { + PrepareBuilder(); result.hasField207 = true; result.field207_ = value; return this; } public Builder ClearField207() { + PrepareBuilder(); result.hasField207 = false; result.field207_ = 0UL; return this; @@ -2102,11 +2278,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField300(ulong value) { + PrepareBuilder(); result.hasField300 = true; result.field300_ = value; return this; } public Builder ClearField300() { + PrepareBuilder(); result.hasField300 = false; result.field300_ = 0UL; return this; @@ -2373,7 +2551,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Group1 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -2383,21 +2561,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Group1(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Group1 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + Group1 result; - Group1 result = new Group1(); + private Group1 PrepareBuilder() { + if (builderIsReadOnly) { + Group1 original = result; + result = new Group1(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Group1 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Group1(); + result = DefaultInstance ?? new Group1(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -2409,15 +2614,14 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Group1 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.field14_.MakeReadOnly(); result.field22_.MakeReadOnly(); result.field73_.MakeReadOnly(); - Group1 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -2429,11 +2633,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField11(value); } } public Builder SetField11(float value) { + PrepareBuilder(); result.hasField11 = true; result.field11_ = value; return this; } public Builder ClearField11() { + PrepareBuilder(); result.hasField11 = false; result.field11_ = 0F; return this; @@ -2447,11 +2653,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField26(value); } } public Builder SetField26(float value) { + PrepareBuilder(); result.hasField26 = true; result.field26_ = value; return this; } public Builder ClearField26() { + PrepareBuilder(); result.hasField26 = false; result.field26_ = 0F; return this; @@ -2466,11 +2674,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField12(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField12 = true; result.field12_ = value; return this; } public Builder ClearField12() { + PrepareBuilder(); result.hasField12 = false; result.field12_ = ""; return this; @@ -2485,18 +2695,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField13(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField13 = true; result.field13_ = value; return this; } public Builder ClearField13() { + PrepareBuilder(); result.hasField13 = false; result.field13_ = ""; return this; } public pbc::IPopsicleList Field14List { - get { return result.field14_; } + get { return PrepareBuilder().field14_; } } public int Field14Count { get { return result.Field14Count; } @@ -2506,19 +2718,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField14(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field14_[index] = value; return this; } public Builder AddField14(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field14_.Add(value); return this; } public Builder AddRangeField14(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field14_); return this; } public Builder ClearField14() { + PrepareBuilder(); result.field14_.Clear(); return this; } @@ -2533,11 +2749,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField15(ulong value) { + PrepareBuilder(); result.hasField15 = true; result.field15_ = value; return this; } public Builder ClearField15() { + PrepareBuilder(); result.hasField15 = false; result.field15_ = 0UL; return this; @@ -2551,11 +2769,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField5(value); } } public Builder SetField5(int value) { + PrepareBuilder(); result.hasField5 = true; result.field5_ = value; return this; } public Builder ClearField5() { + PrepareBuilder(); result.hasField5 = false; result.field5_ = 0; return this; @@ -2570,11 +2790,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField27(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField27 = true; result.field27_ = value; return this; } public Builder ClearField27() { + PrepareBuilder(); result.hasField27 = false; result.field27_ = ""; return this; @@ -2588,11 +2810,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField28(value); } } public Builder SetField28(int value) { + PrepareBuilder(); result.hasField28 = true; result.field28_ = value; return this; } public Builder ClearField28() { + PrepareBuilder(); result.hasField28 = false; result.field28_ = 0; return this; @@ -2607,11 +2831,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField29(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField29 = true; result.field29_ = value; return this; } public Builder ClearField29() { + PrepareBuilder(); result.hasField29 = false; result.field29_ = ""; return this; @@ -2626,18 +2852,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField16(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField16 = true; result.field16_ = value; return this; } public Builder ClearField16() { + PrepareBuilder(); result.hasField16 = false; result.field16_ = ""; return this; } public pbc::IPopsicleList Field22List { - get { return result.field22_; } + get { return PrepareBuilder().field22_; } } public int Field22Count { get { return result.Field22Count; } @@ -2647,25 +2875,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField22(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field22_[index] = value; return this; } public Builder AddField22(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field22_.Add(value); return this; } public Builder AddRangeField22(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field22_); return this; } public Builder ClearField22() { + PrepareBuilder(); result.field22_.Clear(); return this; } public pbc::IPopsicleList Field73List { - get { return result.field73_; } + get { return PrepareBuilder().field73_; } } public int Field73Count { get { return result.Field73Count; } @@ -2674,18 +2906,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetField73(index); } public Builder SetField73(int index, int value) { + PrepareBuilder(); result.field73_[index] = value; return this; } public Builder AddField73(int value) { + PrepareBuilder(); result.field73_.Add(value); return this; } public Builder AddRangeField73(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field73_); return this; } public Builder ClearField73() { + PrepareBuilder(); result.field73_.Clear(); return this; } @@ -2698,11 +2934,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField20(value); } } public Builder SetField20(int value) { + PrepareBuilder(); result.hasField20 = true; result.field20_ = value; return this; } public Builder ClearField20() { + PrepareBuilder(); result.hasField20 = false; result.field20_ = 0; return this; @@ -2717,11 +2955,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField24(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField24 = true; result.field24_ = value; return this; } public Builder ClearField24() { + PrepareBuilder(); result.hasField24 = false; result.field24_ = ""; return this; @@ -2736,18 +2976,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField31(global::Google.ProtocolBuffers.TestProtos.SizeMessage2GroupedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField31 = true; result.field31_ = value; return this; } public Builder SetField31(global::Google.ProtocolBuffers.TestProtos.SizeMessage2GroupedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasField31 = true; result.field31_ = builderForValue.Build(); return this; } public Builder MergeField31(global::Google.ProtocolBuffers.TestProtos.SizeMessage2GroupedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasField31 && result.field31_ != global::Google.ProtocolBuffers.TestProtos.SizeMessage2GroupedMessage.DefaultInstance) { result.field31_ = global::Google.ProtocolBuffers.TestProtos.SizeMessage2GroupedMessage.CreateBuilder(result.field31_).MergeFrom(value).BuildPartial(); @@ -2758,6 +3001,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearField31() { + PrepareBuilder(); result.hasField31 = false; result.field31_ = global::Google.ProtocolBuffers.TestProtos.SizeMessage2GroupedMessage.DefaultInstance; return this; @@ -3113,7 +3357,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SizeMessage2 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3123,21 +3367,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SizeMessage2(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SizeMessage2 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - SizeMessage2 result = new SizeMessage2(); + bool builderIsReadOnly; + SizeMessage2 result; + + private SizeMessage2 PrepareBuilder() { + if (builderIsReadOnly) { + SizeMessage2 original = result; + result = new SizeMessage2(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SizeMessage2 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SizeMessage2(); + result = DefaultInstance ?? new SizeMessage2(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3149,16 +3420,15 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SizeMessage2 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.group1_.MakeReadOnly(); result.field128_.MakeReadOnly(); result.field127_.MakeReadOnly(); result.field130_.MakeReadOnly(); - SizeMessage2 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -3171,11 +3441,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField1(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField1 = true; result.field1_ = value; return this; } public Builder ClearField1() { + PrepareBuilder(); result.hasField1 = false; result.field1_ = ""; return this; @@ -3189,11 +3461,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField3(value); } } public Builder SetField3(long value) { + PrepareBuilder(); result.hasField3 = true; result.field3_ = value; return this; } public Builder ClearField3() { + PrepareBuilder(); result.hasField3 = false; result.field3_ = 0L; return this; @@ -3207,11 +3481,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField4(value); } } public Builder SetField4(long value) { + PrepareBuilder(); result.hasField4 = true; result.field4_ = value; return this; } public Builder ClearField4() { + PrepareBuilder(); result.hasField4 = false; result.field4_ = 0L; return this; @@ -3225,11 +3501,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField30(value); } } public Builder SetField30(long value) { + PrepareBuilder(); result.hasField30 = true; result.field30_ = value; return this; } public Builder ClearField30() { + PrepareBuilder(); result.hasField30 = false; result.field30_ = 0L; return this; @@ -3243,11 +3521,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField75(value); } } public Builder SetField75(bool value) { + PrepareBuilder(); result.hasField75 = true; result.field75_ = value; return this; } public Builder ClearField75() { + PrepareBuilder(); result.hasField75 = false; result.field75_ = false; return this; @@ -3262,11 +3542,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField6(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField6 = true; result.field6_ = value; return this; } public Builder ClearField6() { + PrepareBuilder(); result.hasField6 = false; result.field6_ = ""; return this; @@ -3281,11 +3563,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField2(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField2 = true; result.field2_ = value; return this; } public Builder ClearField2() { + PrepareBuilder(); result.hasField2 = false; result.field2_ = pb::ByteString.Empty; return this; @@ -3299,11 +3583,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField21(value); } } public Builder SetField21(int value) { + PrepareBuilder(); result.hasField21 = true; result.field21_ = value; return this; } public Builder ClearField21() { + PrepareBuilder(); result.hasField21 = false; result.field21_ = 0; return this; @@ -3317,11 +3603,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField71(value); } } public Builder SetField71(int value) { + PrepareBuilder(); result.hasField71 = true; result.field71_ = value; return this; } public Builder ClearField71() { + PrepareBuilder(); result.hasField71 = false; result.field71_ = 0; return this; @@ -3335,11 +3623,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField25(value); } } public Builder SetField25(float value) { + PrepareBuilder(); result.hasField25 = true; result.field25_ = value; return this; } public Builder ClearField25() { + PrepareBuilder(); result.hasField25 = false; result.field25_ = 0F; return this; @@ -3353,11 +3643,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField109(value); } } public Builder SetField109(int value) { + PrepareBuilder(); result.hasField109 = true; result.field109_ = value; return this; } public Builder ClearField109() { + PrepareBuilder(); result.hasField109 = false; result.field109_ = 0; return this; @@ -3371,11 +3663,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField210(value); } } public Builder SetField210(int value) { + PrepareBuilder(); result.hasField210 = true; result.field210_ = value; return this; } public Builder ClearField210() { + PrepareBuilder(); result.hasField210 = false; result.field210_ = 0; return this; @@ -3389,11 +3683,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField211(value); } } public Builder SetField211(int value) { + PrepareBuilder(); result.hasField211 = true; result.field211_ = value; return this; } public Builder ClearField211() { + PrepareBuilder(); result.hasField211 = false; result.field211_ = 0; return this; @@ -3407,11 +3703,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField212(value); } } public Builder SetField212(int value) { + PrepareBuilder(); result.hasField212 = true; result.field212_ = value; return this; } public Builder ClearField212() { + PrepareBuilder(); result.hasField212 = false; result.field212_ = 0; return this; @@ -3425,11 +3723,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField213(value); } } public Builder SetField213(int value) { + PrepareBuilder(); result.hasField213 = true; result.field213_ = value; return this; } public Builder ClearField213() { + PrepareBuilder(); result.hasField213 = false; result.field213_ = 0; return this; @@ -3443,11 +3743,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField216(value); } } public Builder SetField216(int value) { + PrepareBuilder(); result.hasField216 = true; result.field216_ = value; return this; } public Builder ClearField216() { + PrepareBuilder(); result.hasField216 = false; result.field216_ = 0; return this; @@ -3461,11 +3763,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField217(value); } } public Builder SetField217(int value) { + PrepareBuilder(); result.hasField217 = true; result.field217_ = value; return this; } public Builder ClearField217() { + PrepareBuilder(); result.hasField217 = false; result.field217_ = 0; return this; @@ -3479,11 +3783,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField218(value); } } public Builder SetField218(int value) { + PrepareBuilder(); result.hasField218 = true; result.field218_ = value; return this; } public Builder ClearField218() { + PrepareBuilder(); result.hasField218 = false; result.field218_ = 0; return this; @@ -3497,11 +3803,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField220(value); } } public Builder SetField220(int value) { + PrepareBuilder(); result.hasField220 = true; result.field220_ = value; return this; } public Builder ClearField220() { + PrepareBuilder(); result.hasField220 = false; result.field220_ = 0; return this; @@ -3515,11 +3823,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField221(value); } } public Builder SetField221(int value) { + PrepareBuilder(); result.hasField221 = true; result.field221_ = value; return this; } public Builder ClearField221() { + PrepareBuilder(); result.hasField221 = false; result.field221_ = 0; return this; @@ -3533,11 +3843,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField222(value); } } public Builder SetField222(float value) { + PrepareBuilder(); result.hasField222 = true; result.field222_ = value; return this; } public Builder ClearField222() { + PrepareBuilder(); result.hasField222 = false; result.field222_ = 0F; return this; @@ -3551,18 +3863,20 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField63(value); } } public Builder SetField63(int value) { + PrepareBuilder(); result.hasField63 = true; result.field63_ = value; return this; } public Builder ClearField63() { + PrepareBuilder(); result.hasField63 = false; result.field63_ = 0; return this; } public pbc::IPopsicleList Group1List { - get { return result.group1_; } + get { return PrepareBuilder().group1_; } } public int Group1Count { get { return result.Group1Count; } @@ -3572,35 +3886,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetGroup1(int index, global::Google.ProtocolBuffers.TestProtos.SizeMessage2.Types.Group1 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.group1_[index] = value; return this; } public Builder SetGroup1(int index, global::Google.ProtocolBuffers.TestProtos.SizeMessage2.Types.Group1.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.group1_[index] = builderForValue.Build(); return this; } public Builder AddGroup1(global::Google.ProtocolBuffers.TestProtos.SizeMessage2.Types.Group1 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.group1_.Add(value); return this; } public Builder AddGroup1(global::Google.ProtocolBuffers.TestProtos.SizeMessage2.Types.Group1.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.group1_.Add(builderForValue.Build()); return this; } public Builder AddRangeGroup1(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.group1_); return this; } public Builder ClearGroup1() { + PrepareBuilder(); result.group1_.Clear(); return this; } public pbc::IPopsicleList Field128List { - get { return result.field128_; } + get { return PrepareBuilder().field128_; } } public int Field128Count { get { return result.Field128Count; } @@ -3610,19 +3930,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField128(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field128_[index] = value; return this; } public Builder AddField128(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field128_.Add(value); return this; } public Builder AddRangeField128(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field128_); return this; } public Builder ClearField128() { + PrepareBuilder(); result.field128_.Clear(); return this; } @@ -3635,18 +3959,20 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField131(value); } } public Builder SetField131(long value) { + PrepareBuilder(); result.hasField131 = true; result.field131_ = value; return this; } public Builder ClearField131() { + PrepareBuilder(); result.hasField131 = false; result.field131_ = 0L; return this; } public pbc::IPopsicleList Field127List { - get { return result.field127_; } + get { return PrepareBuilder().field127_; } } public int Field127Count { get { return result.Field127Count; } @@ -3656,19 +3982,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField127(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field127_[index] = value; return this; } public Builder AddField127(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field127_.Add(value); return this; } public Builder AddRangeField127(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field127_); return this; } public Builder ClearField127() { + PrepareBuilder(); result.field127_.Clear(); return this; } @@ -3681,18 +4011,20 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField129(value); } } public Builder SetField129(int value) { + PrepareBuilder(); result.hasField129 = true; result.field129_ = value; return this; } public Builder ClearField129() { + PrepareBuilder(); result.hasField129 = false; result.field129_ = 0; return this; } public pbc::IPopsicleList Field130List { - get { return result.field130_; } + get { return PrepareBuilder().field130_; } } public int Field130Count { get { return result.Field130Count; } @@ -3701,18 +4033,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetField130(index); } public Builder SetField130(int index, long value) { + PrepareBuilder(); result.field130_[index] = value; return this; } public Builder AddField130(long value) { + PrepareBuilder(); result.field130_.Add(value); return this; } public Builder AddRangeField130(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field130_); return this; } public Builder ClearField130() { + PrepareBuilder(); result.field130_.Clear(); return this; } @@ -3725,11 +4061,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField205(value); } } public Builder SetField205(bool value) { + PrepareBuilder(); result.hasField205 = true; result.field205_ = value; return this; } public Builder ClearField205() { + PrepareBuilder(); result.hasField205 = false; result.field205_ = false; return this; @@ -3743,11 +4081,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField206(value); } } public Builder SetField206(bool value) { + PrepareBuilder(); result.hasField206 = true; result.field206_ = value; return this; } public Builder ClearField206() { + PrepareBuilder(); result.hasField206 = false; result.field206_ = false; return this; @@ -3927,7 +4267,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SizeMessage2GroupedMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3937,21 +4277,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SizeMessage2GroupedMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SizeMessage2GroupedMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - SizeMessage2GroupedMessage result = new SizeMessage2GroupedMessage(); + bool builderIsReadOnly; + SizeMessage2GroupedMessage result; + + private SizeMessage2GroupedMessage PrepareBuilder() { + if (builderIsReadOnly) { + SizeMessage2GroupedMessage original = result; + result = new SizeMessage2GroupedMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SizeMessage2GroupedMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SizeMessage2GroupedMessage(); + result = DefaultInstance ?? new SizeMessage2GroupedMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3963,12 +4330,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SizeMessage2GroupedMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - SizeMessage2GroupedMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -3980,11 +4346,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField1(value); } } public Builder SetField1(float value) { + PrepareBuilder(); result.hasField1 = true; result.field1_ = value; return this; } public Builder ClearField1() { + PrepareBuilder(); result.hasField1 = false; result.field1_ = 0F; return this; @@ -3998,11 +4366,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField2(value); } } public Builder SetField2(float value) { + PrepareBuilder(); result.hasField2 = true; result.field2_ = value; return this; } public Builder ClearField2() { + PrepareBuilder(); result.hasField2 = false; result.field2_ = 0F; return this; @@ -4016,11 +4386,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField3(value); } } public Builder SetField3(float value) { + PrepareBuilder(); result.hasField3 = true; result.field3_ = value; return this; } public Builder ClearField3() { + PrepareBuilder(); result.hasField3 = false; result.field3_ = 0F; return this; @@ -4034,11 +4406,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField4(value); } } public Builder SetField4(bool value) { + PrepareBuilder(); result.hasField4 = true; result.field4_ = value; return this; } public Builder ClearField4() { + PrepareBuilder(); result.hasField4 = false; result.field4_ = false; return this; @@ -4052,11 +4426,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField5(value); } } public Builder SetField5(bool value) { + PrepareBuilder(); result.hasField5 = true; result.field5_ = value; return this; } public Builder ClearField5() { + PrepareBuilder(); result.hasField5 = false; result.field5_ = false; return this; @@ -4070,11 +4446,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField6(value); } } public Builder SetField6(bool value) { + PrepareBuilder(); result.hasField6 = true; result.field6_ = value; return this; } public Builder ClearField6() { + PrepareBuilder(); result.hasField6 = false; result.field6_ = true; return this; @@ -4088,11 +4466,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField7(value); } } public Builder SetField7(bool value) { + PrepareBuilder(); result.hasField7 = true; result.field7_ = value; return this; } public Builder ClearField7() { + PrepareBuilder(); result.hasField7 = false; result.field7_ = false; return this; @@ -4106,11 +4486,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField8(value); } } public Builder SetField8(float value) { + PrepareBuilder(); result.hasField8 = true; result.field8_ = value; return this; } public Builder ClearField8() { + PrepareBuilder(); result.hasField8 = false; result.field8_ = 0F; return this; @@ -4124,11 +4506,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField9(value); } } public Builder SetField9(bool value) { + PrepareBuilder(); result.hasField9 = true; result.field9_ = value; return this; } public Builder ClearField9() { + PrepareBuilder(); result.hasField9 = false; result.field9_ = false; return this; @@ -4142,11 +4526,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField10(value); } } public Builder SetField10(float value) { + PrepareBuilder(); result.hasField10 = true; result.field10_ = value; return this; } public Builder ClearField10() { + PrepareBuilder(); result.hasField10 = false; result.field10_ = 0F; return this; @@ -4160,11 +4546,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField11(value); } } public Builder SetField11(long value) { + PrepareBuilder(); result.hasField11 = true; result.field11_ = value; return this; } public Builder ClearField11() { + PrepareBuilder(); result.hasField11 = false; result.field11_ = 0L; return this; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestGoogleSpeedProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestGoogleSpeedProtoFile.cs index 918be643ec..379a86f9a5 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestGoogleSpeedProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestGoogleSpeedProtoFile.cs @@ -885,7 +885,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SpeedMessage1 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -895,21 +895,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SpeedMessage1(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SpeedMessage1 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + SpeedMessage1 result; - SpeedMessage1 result = new SpeedMessage1(); + private SpeedMessage1 PrepareBuilder() { + if (builderIsReadOnly) { + SpeedMessage1 original = result; + result = new SpeedMessage1(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SpeedMessage1 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SpeedMessage1(); + result = DefaultInstance ?? new SpeedMessage1(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -921,13 +948,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SpeedMessage1 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.field5_.MakeReadOnly(); - SpeedMessage1 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -941,6 +967,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(SpeedMessage1 other) { if (other == global::Google.ProtocolBuffers.TestProtos.SpeedMessage1.DefaultInstance) return this; + PrepareBuilder(); if (other.HasField1) { Field1 = other.Field1; } @@ -1073,6 +1100,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1295,11 +1323,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField1(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField1 = true; result.field1_ = value; return this; } public Builder ClearField1() { + PrepareBuilder(); result.hasField1 = false; result.field1_ = ""; return this; @@ -1314,11 +1344,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField9(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField9 = true; result.field9_ = value; return this; } public Builder ClearField9() { + PrepareBuilder(); result.hasField9 = false; result.field9_ = ""; return this; @@ -1333,11 +1365,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField18(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField18 = true; result.field18_ = value; return this; } public Builder ClearField18() { + PrepareBuilder(); result.hasField18 = false; result.field18_ = ""; return this; @@ -1351,11 +1385,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField80(value); } } public Builder SetField80(bool value) { + PrepareBuilder(); result.hasField80 = true; result.field80_ = value; return this; } public Builder ClearField80() { + PrepareBuilder(); result.hasField80 = false; result.field80_ = false; return this; @@ -1369,11 +1405,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField81(value); } } public Builder SetField81(bool value) { + PrepareBuilder(); result.hasField81 = true; result.field81_ = value; return this; } public Builder ClearField81() { + PrepareBuilder(); result.hasField81 = false; result.field81_ = true; return this; @@ -1387,11 +1425,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField2(value); } } public Builder SetField2(int value) { + PrepareBuilder(); result.hasField2 = true; result.field2_ = value; return this; } public Builder ClearField2() { + PrepareBuilder(); result.hasField2 = false; result.field2_ = 0; return this; @@ -1405,11 +1445,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField3(value); } } public Builder SetField3(int value) { + PrepareBuilder(); result.hasField3 = true; result.field3_ = value; return this; } public Builder ClearField3() { + PrepareBuilder(); result.hasField3 = false; result.field3_ = 0; return this; @@ -1423,11 +1465,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField280(value); } } public Builder SetField280(int value) { + PrepareBuilder(); result.hasField280 = true; result.field280_ = value; return this; } public Builder ClearField280() { + PrepareBuilder(); result.hasField280 = false; result.field280_ = 0; return this; @@ -1441,11 +1485,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField6(value); } } public Builder SetField6(int value) { + PrepareBuilder(); result.hasField6 = true; result.field6_ = value; return this; } public Builder ClearField6() { + PrepareBuilder(); result.hasField6 = false; result.field6_ = 0; return this; @@ -1459,11 +1505,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField22(value); } } public Builder SetField22(long value) { + PrepareBuilder(); result.hasField22 = true; result.field22_ = value; return this; } public Builder ClearField22() { + PrepareBuilder(); result.hasField22 = false; result.field22_ = 0L; return this; @@ -1478,11 +1526,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField4(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField4 = true; result.field4_ = value; return this; } public Builder ClearField4() { + PrepareBuilder(); result.hasField4 = false; result.field4_ = ""; return this; @@ -1490,7 +1540,7 @@ namespace Google.ProtocolBuffers.TestProtos { [global::System.CLSCompliant(false)] public pbc::IPopsicleList Field5List { - get { return result.field5_; } + get { return PrepareBuilder().field5_; } } public int Field5Count { get { return result.Field5Count; } @@ -1501,20 +1551,24 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField5(int index, ulong value) { + PrepareBuilder(); result.field5_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddField5(ulong value) { + PrepareBuilder(); result.field5_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeField5(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field5_); return this; } public Builder ClearField5() { + PrepareBuilder(); result.field5_.Clear(); return this; } @@ -1527,11 +1581,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField59(value); } } public Builder SetField59(bool value) { + PrepareBuilder(); result.hasField59 = true; result.field59_ = value; return this; } public Builder ClearField59() { + PrepareBuilder(); result.hasField59 = false; result.field59_ = false; return this; @@ -1546,11 +1602,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField7(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField7 = true; result.field7_ = value; return this; } public Builder ClearField7() { + PrepareBuilder(); result.hasField7 = false; result.field7_ = ""; return this; @@ -1564,11 +1622,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField16(value); } } public Builder SetField16(int value) { + PrepareBuilder(); result.hasField16 = true; result.field16_ = value; return this; } public Builder ClearField16() { + PrepareBuilder(); result.hasField16 = false; result.field16_ = 0; return this; @@ -1582,11 +1642,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField130(value); } } public Builder SetField130(int value) { + PrepareBuilder(); result.hasField130 = true; result.field130_ = value; return this; } public Builder ClearField130() { + PrepareBuilder(); result.hasField130 = false; result.field130_ = 0; return this; @@ -1600,11 +1662,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField12(value); } } public Builder SetField12(bool value) { + PrepareBuilder(); result.hasField12 = true; result.field12_ = value; return this; } public Builder ClearField12() { + PrepareBuilder(); result.hasField12 = false; result.field12_ = true; return this; @@ -1618,11 +1682,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField17(value); } } public Builder SetField17(bool value) { + PrepareBuilder(); result.hasField17 = true; result.field17_ = value; return this; } public Builder ClearField17() { + PrepareBuilder(); result.hasField17 = false; result.field17_ = true; return this; @@ -1636,11 +1702,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField13(value); } } public Builder SetField13(bool value) { + PrepareBuilder(); result.hasField13 = true; result.field13_ = value; return this; } public Builder ClearField13() { + PrepareBuilder(); result.hasField13 = false; result.field13_ = true; return this; @@ -1654,11 +1722,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField14(value); } } public Builder SetField14(bool value) { + PrepareBuilder(); result.hasField14 = true; result.field14_ = value; return this; } public Builder ClearField14() { + PrepareBuilder(); result.hasField14 = false; result.field14_ = true; return this; @@ -1672,11 +1742,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField104(value); } } public Builder SetField104(int value) { + PrepareBuilder(); result.hasField104 = true; result.field104_ = value; return this; } public Builder ClearField104() { + PrepareBuilder(); result.hasField104 = false; result.field104_ = 0; return this; @@ -1690,11 +1762,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField100(value); } } public Builder SetField100(int value) { + PrepareBuilder(); result.hasField100 = true; result.field100_ = value; return this; } public Builder ClearField100() { + PrepareBuilder(); result.hasField100 = false; result.field100_ = 0; return this; @@ -1708,11 +1782,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField101(value); } } public Builder SetField101(int value) { + PrepareBuilder(); result.hasField101 = true; result.field101_ = value; return this; } public Builder ClearField101() { + PrepareBuilder(); result.hasField101 = false; result.field101_ = 0; return this; @@ -1727,11 +1803,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField102(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField102 = true; result.field102_ = value; return this; } public Builder ClearField102() { + PrepareBuilder(); result.hasField102 = false; result.field102_ = ""; return this; @@ -1746,11 +1824,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField103(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField103 = true; result.field103_ = value; return this; } public Builder ClearField103() { + PrepareBuilder(); result.hasField103 = false; result.field103_ = ""; return this; @@ -1764,11 +1844,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField29(value); } } public Builder SetField29(int value) { + PrepareBuilder(); result.hasField29 = true; result.field29_ = value; return this; } public Builder ClearField29() { + PrepareBuilder(); result.hasField29 = false; result.field29_ = 0; return this; @@ -1782,11 +1864,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField30(value); } } public Builder SetField30(bool value) { + PrepareBuilder(); result.hasField30 = true; result.field30_ = value; return this; } public Builder ClearField30() { + PrepareBuilder(); result.hasField30 = false; result.field30_ = false; return this; @@ -1800,11 +1884,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField60(value); } } public Builder SetField60(int value) { + PrepareBuilder(); result.hasField60 = true; result.field60_ = value; return this; } public Builder ClearField60() { + PrepareBuilder(); result.hasField60 = false; result.field60_ = -1; return this; @@ -1818,11 +1904,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField271(value); } } public Builder SetField271(int value) { + PrepareBuilder(); result.hasField271 = true; result.field271_ = value; return this; } public Builder ClearField271() { + PrepareBuilder(); result.hasField271 = false; result.field271_ = -1; return this; @@ -1836,11 +1924,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField272(value); } } public Builder SetField272(int value) { + PrepareBuilder(); result.hasField272 = true; result.field272_ = value; return this; } public Builder ClearField272() { + PrepareBuilder(); result.hasField272 = false; result.field272_ = -1; return this; @@ -1854,11 +1944,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField150(value); } } public Builder SetField150(int value) { + PrepareBuilder(); result.hasField150 = true; result.field150_ = value; return this; } public Builder ClearField150() { + PrepareBuilder(); result.hasField150 = false; result.field150_ = 0; return this; @@ -1872,11 +1964,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField23(value); } } public Builder SetField23(int value) { + PrepareBuilder(); result.hasField23 = true; result.field23_ = value; return this; } public Builder ClearField23() { + PrepareBuilder(); result.hasField23 = false; result.field23_ = 0; return this; @@ -1890,11 +1984,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField24(value); } } public Builder SetField24(bool value) { + PrepareBuilder(); result.hasField24 = true; result.field24_ = value; return this; } public Builder ClearField24() { + PrepareBuilder(); result.hasField24 = false; result.field24_ = false; return this; @@ -1908,11 +2004,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField25(value); } } public Builder SetField25(int value) { + PrepareBuilder(); result.hasField25 = true; result.field25_ = value; return this; } public Builder ClearField25() { + PrepareBuilder(); result.hasField25 = false; result.field25_ = 0; return this; @@ -1927,18 +2025,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField15(global::Google.ProtocolBuffers.TestProtos.SpeedMessage1SubMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField15 = true; result.field15_ = value; return this; } public Builder SetField15(global::Google.ProtocolBuffers.TestProtos.SpeedMessage1SubMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasField15 = true; result.field15_ = builderForValue.Build(); return this; } public Builder MergeField15(global::Google.ProtocolBuffers.TestProtos.SpeedMessage1SubMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasField15 && result.field15_ != global::Google.ProtocolBuffers.TestProtos.SpeedMessage1SubMessage.DefaultInstance) { result.field15_ = global::Google.ProtocolBuffers.TestProtos.SpeedMessage1SubMessage.CreateBuilder(result.field15_).MergeFrom(value).BuildPartial(); @@ -1949,6 +2050,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearField15() { + PrepareBuilder(); result.hasField15 = false; result.field15_ = global::Google.ProtocolBuffers.TestProtos.SpeedMessage1SubMessage.DefaultInstance; return this; @@ -1962,11 +2064,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField78(value); } } public Builder SetField78(bool value) { + PrepareBuilder(); result.hasField78 = true; result.field78_ = value; return this; } public Builder ClearField78() { + PrepareBuilder(); result.hasField78 = false; result.field78_ = false; return this; @@ -1980,11 +2084,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField67(value); } } public Builder SetField67(int value) { + PrepareBuilder(); result.hasField67 = true; result.field67_ = value; return this; } public Builder ClearField67() { + PrepareBuilder(); result.hasField67 = false; result.field67_ = 0; return this; @@ -1998,11 +2104,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField68(value); } } public Builder SetField68(int value) { + PrepareBuilder(); result.hasField68 = true; result.field68_ = value; return this; } public Builder ClearField68() { + PrepareBuilder(); result.hasField68 = false; result.field68_ = 0; return this; @@ -2016,11 +2124,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField128(value); } } public Builder SetField128(int value) { + PrepareBuilder(); result.hasField128 = true; result.field128_ = value; return this; } public Builder ClearField128() { + PrepareBuilder(); result.hasField128 = false; result.field128_ = 0; return this; @@ -2035,11 +2145,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField129(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField129 = true; result.field129_ = value; return this; } public Builder ClearField129() { + PrepareBuilder(); result.hasField129 = false; result.field129_ = "xxxxxxxxxxxxxxxxxxxxx"; return this; @@ -2053,11 +2165,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField131(value); } } public Builder SetField131(int value) { + PrepareBuilder(); result.hasField131 = true; result.field131_ = value; return this; } public Builder ClearField131() { + PrepareBuilder(); result.hasField131 = false; result.field131_ = 0; return this; @@ -2478,7 +2592,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SpeedMessage1SubMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -2488,21 +2602,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SpeedMessage1SubMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SpeedMessage1SubMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - SpeedMessage1SubMessage result = new SpeedMessage1SubMessage(); + bool builderIsReadOnly; + SpeedMessage1SubMessage result; + + private SpeedMessage1SubMessage PrepareBuilder() { + if (builderIsReadOnly) { + SpeedMessage1SubMessage original = result; + result = new SpeedMessage1SubMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SpeedMessage1SubMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SpeedMessage1SubMessage(); + result = DefaultInstance ?? new SpeedMessage1SubMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -2514,12 +2655,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SpeedMessage1SubMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - SpeedMessage1SubMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -2533,6 +2673,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(SpeedMessage1SubMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.SpeedMessage1SubMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasField1) { Field1 = other.Field1; } @@ -2602,6 +2743,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -2733,11 +2875,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField1(value); } } public Builder SetField1(int value) { + PrepareBuilder(); result.hasField1 = true; result.field1_ = value; return this; } public Builder ClearField1() { + PrepareBuilder(); result.hasField1 = false; result.field1_ = 0; return this; @@ -2751,11 +2895,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField2(value); } } public Builder SetField2(int value) { + PrepareBuilder(); result.hasField2 = true; result.field2_ = value; return this; } public Builder ClearField2() { + PrepareBuilder(); result.hasField2 = false; result.field2_ = 0; return this; @@ -2769,11 +2915,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField3(value); } } public Builder SetField3(int value) { + PrepareBuilder(); result.hasField3 = true; result.field3_ = value; return this; } public Builder ClearField3() { + PrepareBuilder(); result.hasField3 = false; result.field3_ = 0; return this; @@ -2788,11 +2936,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField15(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField15 = true; result.field15_ = value; return this; } public Builder ClearField15() { + PrepareBuilder(); result.hasField15 = false; result.field15_ = ""; return this; @@ -2806,11 +2956,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField12(value); } } public Builder SetField12(bool value) { + PrepareBuilder(); result.hasField12 = true; result.field12_ = value; return this; } public Builder ClearField12() { + PrepareBuilder(); result.hasField12 = false; result.field12_ = true; return this; @@ -2824,11 +2976,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField13(value); } } public Builder SetField13(long value) { + PrepareBuilder(); result.hasField13 = true; result.field13_ = value; return this; } public Builder ClearField13() { + PrepareBuilder(); result.hasField13 = false; result.field13_ = 0L; return this; @@ -2842,11 +2996,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField14(value); } } public Builder SetField14(long value) { + PrepareBuilder(); result.hasField14 = true; result.field14_ = value; return this; } public Builder ClearField14() { + PrepareBuilder(); result.hasField14 = false; result.field14_ = 0L; return this; @@ -2860,11 +3016,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField16(value); } } public Builder SetField16(int value) { + PrepareBuilder(); result.hasField16 = true; result.field16_ = value; return this; } public Builder ClearField16() { + PrepareBuilder(); result.hasField16 = false; result.field16_ = 0; return this; @@ -2878,11 +3036,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField19(value); } } public Builder SetField19(int value) { + PrepareBuilder(); result.hasField19 = true; result.field19_ = value; return this; } public Builder ClearField19() { + PrepareBuilder(); result.hasField19 = false; result.field19_ = 2; return this; @@ -2896,11 +3056,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField20(value); } } public Builder SetField20(bool value) { + PrepareBuilder(); result.hasField20 = true; result.field20_ = value; return this; } public Builder ClearField20() { + PrepareBuilder(); result.hasField20 = false; result.field20_ = true; return this; @@ -2914,11 +3076,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField28(value); } } public Builder SetField28(bool value) { + PrepareBuilder(); result.hasField28 = true; result.field28_ = value; return this; } public Builder ClearField28() { + PrepareBuilder(); result.hasField28 = false; result.field28_ = true; return this; @@ -2934,11 +3098,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField21(ulong value) { + PrepareBuilder(); result.hasField21 = true; result.field21_ = value; return this; } public Builder ClearField21() { + PrepareBuilder(); result.hasField21 = false; result.field21_ = 0; return this; @@ -2952,11 +3118,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField22(value); } } public Builder SetField22(int value) { + PrepareBuilder(); result.hasField22 = true; result.field22_ = value; return this; } public Builder ClearField22() { + PrepareBuilder(); result.hasField22 = false; result.field22_ = 0; return this; @@ -2970,11 +3138,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField23(value); } } public Builder SetField23(bool value) { + PrepareBuilder(); result.hasField23 = true; result.field23_ = value; return this; } public Builder ClearField23() { + PrepareBuilder(); result.hasField23 = false; result.field23_ = false; return this; @@ -2988,11 +3158,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField206(value); } } public Builder SetField206(bool value) { + PrepareBuilder(); result.hasField206 = true; result.field206_ = value; return this; } public Builder ClearField206() { + PrepareBuilder(); result.hasField206 = false; result.field206_ = false; return this; @@ -3008,11 +3180,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField203(uint value) { + PrepareBuilder(); result.hasField203 = true; result.field203_ = value; return this; } public Builder ClearField203() { + PrepareBuilder(); result.hasField203 = false; result.field203_ = 0; return this; @@ -3026,11 +3200,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField204(value); } } public Builder SetField204(int value) { + PrepareBuilder(); result.hasField204 = true; result.field204_ = value; return this; } public Builder ClearField204() { + PrepareBuilder(); result.hasField204 = false; result.field204_ = 0; return this; @@ -3045,11 +3221,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField205(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField205 = true; result.field205_ = value; return this; } public Builder ClearField205() { + PrepareBuilder(); result.hasField205 = false; result.field205_ = ""; return this; @@ -3065,11 +3243,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField207(ulong value) { + PrepareBuilder(); result.hasField207 = true; result.field207_ = value; return this; } public Builder ClearField207() { + PrepareBuilder(); result.hasField207 = false; result.field207_ = 0UL; return this; @@ -3085,11 +3265,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField300(ulong value) { + PrepareBuilder(); result.hasField300 = true; result.field300_ = value; return this; } public Builder ClearField300() { + PrepareBuilder(); result.hasField300 = false; result.field300_ = 0UL; return this; @@ -3498,7 +3680,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Group1 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3508,21 +3690,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Group1(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Group1 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + Group1 result; + + private Group1 PrepareBuilder() { + if (builderIsReadOnly) { + Group1 original = result; + result = new Group1(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - Group1 result = new Group1(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Group1 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Group1(); + result = DefaultInstance ?? new Group1(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3534,15 +3743,14 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Group1 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.field14_.MakeReadOnly(); result.field22_.MakeReadOnly(); result.field73_.MakeReadOnly(); - Group1 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -3556,6 +3764,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(Group1 other) { if (other == global::Google.ProtocolBuffers.TestProtos.SpeedMessage2.Types.Group1.DefaultInstance) return this; + PrepareBuilder(); if (other.HasField11) { Field11 = other.Field11; } @@ -3613,6 +3822,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -3734,11 +3944,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField11(value); } } public Builder SetField11(float value) { + PrepareBuilder(); result.hasField11 = true; result.field11_ = value; return this; } public Builder ClearField11() { + PrepareBuilder(); result.hasField11 = false; result.field11_ = 0F; return this; @@ -3752,11 +3964,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField26(value); } } public Builder SetField26(float value) { + PrepareBuilder(); result.hasField26 = true; result.field26_ = value; return this; } public Builder ClearField26() { + PrepareBuilder(); result.hasField26 = false; result.field26_ = 0F; return this; @@ -3771,11 +3985,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField12(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField12 = true; result.field12_ = value; return this; } public Builder ClearField12() { + PrepareBuilder(); result.hasField12 = false; result.field12_ = ""; return this; @@ -3790,18 +4006,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField13(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField13 = true; result.field13_ = value; return this; } public Builder ClearField13() { + PrepareBuilder(); result.hasField13 = false; result.field13_ = ""; return this; } public pbc::IPopsicleList Field14List { - get { return result.field14_; } + get { return PrepareBuilder().field14_; } } public int Field14Count { get { return result.Field14Count; } @@ -3811,19 +4029,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField14(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field14_[index] = value; return this; } public Builder AddField14(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field14_.Add(value); return this; } public Builder AddRangeField14(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field14_); return this; } public Builder ClearField14() { + PrepareBuilder(); result.field14_.Clear(); return this; } @@ -3838,11 +4060,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetField15(ulong value) { + PrepareBuilder(); result.hasField15 = true; result.field15_ = value; return this; } public Builder ClearField15() { + PrepareBuilder(); result.hasField15 = false; result.field15_ = 0UL; return this; @@ -3856,11 +4080,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField5(value); } } public Builder SetField5(int value) { + PrepareBuilder(); result.hasField5 = true; result.field5_ = value; return this; } public Builder ClearField5() { + PrepareBuilder(); result.hasField5 = false; result.field5_ = 0; return this; @@ -3875,11 +4101,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField27(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField27 = true; result.field27_ = value; return this; } public Builder ClearField27() { + PrepareBuilder(); result.hasField27 = false; result.field27_ = ""; return this; @@ -3893,11 +4121,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField28(value); } } public Builder SetField28(int value) { + PrepareBuilder(); result.hasField28 = true; result.field28_ = value; return this; } public Builder ClearField28() { + PrepareBuilder(); result.hasField28 = false; result.field28_ = 0; return this; @@ -3912,11 +4142,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField29(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField29 = true; result.field29_ = value; return this; } public Builder ClearField29() { + PrepareBuilder(); result.hasField29 = false; result.field29_ = ""; return this; @@ -3931,18 +4163,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField16(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField16 = true; result.field16_ = value; return this; } public Builder ClearField16() { + PrepareBuilder(); result.hasField16 = false; result.field16_ = ""; return this; } public pbc::IPopsicleList Field22List { - get { return result.field22_; } + get { return PrepareBuilder().field22_; } } public int Field22Count { get { return result.Field22Count; } @@ -3952,25 +4186,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField22(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field22_[index] = value; return this; } public Builder AddField22(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field22_.Add(value); return this; } public Builder AddRangeField22(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field22_); return this; } public Builder ClearField22() { + PrepareBuilder(); result.field22_.Clear(); return this; } public pbc::IPopsicleList Field73List { - get { return result.field73_; } + get { return PrepareBuilder().field73_; } } public int Field73Count { get { return result.Field73Count; } @@ -3979,18 +4217,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetField73(index); } public Builder SetField73(int index, int value) { + PrepareBuilder(); result.field73_[index] = value; return this; } public Builder AddField73(int value) { + PrepareBuilder(); result.field73_.Add(value); return this; } public Builder AddRangeField73(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field73_); return this; } public Builder ClearField73() { + PrepareBuilder(); result.field73_.Clear(); return this; } @@ -4003,11 +4245,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField20(value); } } public Builder SetField20(int value) { + PrepareBuilder(); result.hasField20 = true; result.field20_ = value; return this; } public Builder ClearField20() { + PrepareBuilder(); result.hasField20 = false; result.field20_ = 0; return this; @@ -4022,11 +4266,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField24(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField24 = true; result.field24_ = value; return this; } public Builder ClearField24() { + PrepareBuilder(); result.hasField24 = false; result.field24_ = ""; return this; @@ -4041,18 +4287,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField31(global::Google.ProtocolBuffers.TestProtos.SpeedMessage2GroupedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField31 = true; result.field31_ = value; return this; } public Builder SetField31(global::Google.ProtocolBuffers.TestProtos.SpeedMessage2GroupedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasField31 = true; result.field31_ = builderForValue.Build(); return this; } public Builder MergeField31(global::Google.ProtocolBuffers.TestProtos.SpeedMessage2GroupedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasField31 && result.field31_ != global::Google.ProtocolBuffers.TestProtos.SpeedMessage2GroupedMessage.DefaultInstance) { result.field31_ = global::Google.ProtocolBuffers.TestProtos.SpeedMessage2GroupedMessage.CreateBuilder(result.field31_).MergeFrom(value).BuildPartial(); @@ -4063,6 +4312,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearField31() { + PrepareBuilder(); result.hasField31 = false; result.field31_ = global::Google.ProtocolBuffers.TestProtos.SpeedMessage2GroupedMessage.DefaultInstance; return this; @@ -4638,7 +4888,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SpeedMessage2 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -4648,21 +4898,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SpeedMessage2(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SpeedMessage2 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - SpeedMessage2 result = new SpeedMessage2(); + bool builderIsReadOnly; + SpeedMessage2 result; + + private SpeedMessage2 PrepareBuilder() { + if (builderIsReadOnly) { + SpeedMessage2 original = result; + result = new SpeedMessage2(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SpeedMessage2 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SpeedMessage2(); + result = DefaultInstance ?? new SpeedMessage2(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -4674,16 +4951,15 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SpeedMessage2 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.group1_.MakeReadOnly(); result.field128_.MakeReadOnly(); result.field127_.MakeReadOnly(); result.field130_.MakeReadOnly(); - SpeedMessage2 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -4697,6 +4973,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(SpeedMessage2 other) { if (other == global::Google.ProtocolBuffers.TestProtos.SpeedMessage2.DefaultInstance) return this; + PrepareBuilder(); if (other.HasField1) { Field1 = other.Field1; } @@ -4796,6 +5073,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -4969,11 +5247,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField1(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField1 = true; result.field1_ = value; return this; } public Builder ClearField1() { + PrepareBuilder(); result.hasField1 = false; result.field1_ = ""; return this; @@ -4987,11 +5267,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField3(value); } } public Builder SetField3(long value) { + PrepareBuilder(); result.hasField3 = true; result.field3_ = value; return this; } public Builder ClearField3() { + PrepareBuilder(); result.hasField3 = false; result.field3_ = 0L; return this; @@ -5005,11 +5287,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField4(value); } } public Builder SetField4(long value) { + PrepareBuilder(); result.hasField4 = true; result.field4_ = value; return this; } public Builder ClearField4() { + PrepareBuilder(); result.hasField4 = false; result.field4_ = 0L; return this; @@ -5023,11 +5307,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField30(value); } } public Builder SetField30(long value) { + PrepareBuilder(); result.hasField30 = true; result.field30_ = value; return this; } public Builder ClearField30() { + PrepareBuilder(); result.hasField30 = false; result.field30_ = 0L; return this; @@ -5041,11 +5327,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField75(value); } } public Builder SetField75(bool value) { + PrepareBuilder(); result.hasField75 = true; result.field75_ = value; return this; } public Builder ClearField75() { + PrepareBuilder(); result.hasField75 = false; result.field75_ = false; return this; @@ -5060,11 +5348,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField6(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField6 = true; result.field6_ = value; return this; } public Builder ClearField6() { + PrepareBuilder(); result.hasField6 = false; result.field6_ = ""; return this; @@ -5079,11 +5369,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField2(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasField2 = true; result.field2_ = value; return this; } public Builder ClearField2() { + PrepareBuilder(); result.hasField2 = false; result.field2_ = pb::ByteString.Empty; return this; @@ -5097,11 +5389,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField21(value); } } public Builder SetField21(int value) { + PrepareBuilder(); result.hasField21 = true; result.field21_ = value; return this; } public Builder ClearField21() { + PrepareBuilder(); result.hasField21 = false; result.field21_ = 0; return this; @@ -5115,11 +5409,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField71(value); } } public Builder SetField71(int value) { + PrepareBuilder(); result.hasField71 = true; result.field71_ = value; return this; } public Builder ClearField71() { + PrepareBuilder(); result.hasField71 = false; result.field71_ = 0; return this; @@ -5133,11 +5429,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField25(value); } } public Builder SetField25(float value) { + PrepareBuilder(); result.hasField25 = true; result.field25_ = value; return this; } public Builder ClearField25() { + PrepareBuilder(); result.hasField25 = false; result.field25_ = 0F; return this; @@ -5151,11 +5449,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField109(value); } } public Builder SetField109(int value) { + PrepareBuilder(); result.hasField109 = true; result.field109_ = value; return this; } public Builder ClearField109() { + PrepareBuilder(); result.hasField109 = false; result.field109_ = 0; return this; @@ -5169,11 +5469,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField210(value); } } public Builder SetField210(int value) { + PrepareBuilder(); result.hasField210 = true; result.field210_ = value; return this; } public Builder ClearField210() { + PrepareBuilder(); result.hasField210 = false; result.field210_ = 0; return this; @@ -5187,11 +5489,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField211(value); } } public Builder SetField211(int value) { + PrepareBuilder(); result.hasField211 = true; result.field211_ = value; return this; } public Builder ClearField211() { + PrepareBuilder(); result.hasField211 = false; result.field211_ = 0; return this; @@ -5205,11 +5509,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField212(value); } } public Builder SetField212(int value) { + PrepareBuilder(); result.hasField212 = true; result.field212_ = value; return this; } public Builder ClearField212() { + PrepareBuilder(); result.hasField212 = false; result.field212_ = 0; return this; @@ -5223,11 +5529,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField213(value); } } public Builder SetField213(int value) { + PrepareBuilder(); result.hasField213 = true; result.field213_ = value; return this; } public Builder ClearField213() { + PrepareBuilder(); result.hasField213 = false; result.field213_ = 0; return this; @@ -5241,11 +5549,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField216(value); } } public Builder SetField216(int value) { + PrepareBuilder(); result.hasField216 = true; result.field216_ = value; return this; } public Builder ClearField216() { + PrepareBuilder(); result.hasField216 = false; result.field216_ = 0; return this; @@ -5259,11 +5569,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField217(value); } } public Builder SetField217(int value) { + PrepareBuilder(); result.hasField217 = true; result.field217_ = value; return this; } public Builder ClearField217() { + PrepareBuilder(); result.hasField217 = false; result.field217_ = 0; return this; @@ -5277,11 +5589,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField218(value); } } public Builder SetField218(int value) { + PrepareBuilder(); result.hasField218 = true; result.field218_ = value; return this; } public Builder ClearField218() { + PrepareBuilder(); result.hasField218 = false; result.field218_ = 0; return this; @@ -5295,11 +5609,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField220(value); } } public Builder SetField220(int value) { + PrepareBuilder(); result.hasField220 = true; result.field220_ = value; return this; } public Builder ClearField220() { + PrepareBuilder(); result.hasField220 = false; result.field220_ = 0; return this; @@ -5313,11 +5629,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField221(value); } } public Builder SetField221(int value) { + PrepareBuilder(); result.hasField221 = true; result.field221_ = value; return this; } public Builder ClearField221() { + PrepareBuilder(); result.hasField221 = false; result.field221_ = 0; return this; @@ -5331,11 +5649,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField222(value); } } public Builder SetField222(float value) { + PrepareBuilder(); result.hasField222 = true; result.field222_ = value; return this; } public Builder ClearField222() { + PrepareBuilder(); result.hasField222 = false; result.field222_ = 0F; return this; @@ -5349,18 +5669,20 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField63(value); } } public Builder SetField63(int value) { + PrepareBuilder(); result.hasField63 = true; result.field63_ = value; return this; } public Builder ClearField63() { + PrepareBuilder(); result.hasField63 = false; result.field63_ = 0; return this; } public pbc::IPopsicleList Group1List { - get { return result.group1_; } + get { return PrepareBuilder().group1_; } } public int Group1Count { get { return result.Group1Count; } @@ -5370,35 +5692,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetGroup1(int index, global::Google.ProtocolBuffers.TestProtos.SpeedMessage2.Types.Group1 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.group1_[index] = value; return this; } public Builder SetGroup1(int index, global::Google.ProtocolBuffers.TestProtos.SpeedMessage2.Types.Group1.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.group1_[index] = builderForValue.Build(); return this; } public Builder AddGroup1(global::Google.ProtocolBuffers.TestProtos.SpeedMessage2.Types.Group1 value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.group1_.Add(value); return this; } public Builder AddGroup1(global::Google.ProtocolBuffers.TestProtos.SpeedMessage2.Types.Group1.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.group1_.Add(builderForValue.Build()); return this; } public Builder AddRangeGroup1(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.group1_); return this; } public Builder ClearGroup1() { + PrepareBuilder(); result.group1_.Clear(); return this; } public pbc::IPopsicleList Field128List { - get { return result.field128_; } + get { return PrepareBuilder().field128_; } } public int Field128Count { get { return result.Field128Count; } @@ -5408,19 +5736,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField128(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field128_[index] = value; return this; } public Builder AddField128(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field128_.Add(value); return this; } public Builder AddRangeField128(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field128_); return this; } public Builder ClearField128() { + PrepareBuilder(); result.field128_.Clear(); return this; } @@ -5433,18 +5765,20 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField131(value); } } public Builder SetField131(long value) { + PrepareBuilder(); result.hasField131 = true; result.field131_ = value; return this; } public Builder ClearField131() { + PrepareBuilder(); result.hasField131 = false; result.field131_ = 0L; return this; } public pbc::IPopsicleList Field127List { - get { return result.field127_; } + get { return PrepareBuilder().field127_; } } public int Field127Count { get { return result.Field127Count; } @@ -5454,19 +5788,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetField127(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field127_[index] = value; return this; } public Builder AddField127(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field127_.Add(value); return this; } public Builder AddRangeField127(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field127_); return this; } public Builder ClearField127() { + PrepareBuilder(); result.field127_.Clear(); return this; } @@ -5479,18 +5817,20 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField129(value); } } public Builder SetField129(int value) { + PrepareBuilder(); result.hasField129 = true; result.field129_ = value; return this; } public Builder ClearField129() { + PrepareBuilder(); result.hasField129 = false; result.field129_ = 0; return this; } public pbc::IPopsicleList Field130List { - get { return result.field130_; } + get { return PrepareBuilder().field130_; } } public int Field130Count { get { return result.Field130Count; } @@ -5499,18 +5839,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetField130(index); } public Builder SetField130(int index, long value) { + PrepareBuilder(); result.field130_[index] = value; return this; } public Builder AddField130(long value) { + PrepareBuilder(); result.field130_.Add(value); return this; } public Builder AddRangeField130(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field130_); return this; } public Builder ClearField130() { + PrepareBuilder(); result.field130_.Clear(); return this; } @@ -5523,11 +5867,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField205(value); } } public Builder SetField205(bool value) { + PrepareBuilder(); result.hasField205 = true; result.field205_ = value; return this; } public Builder ClearField205() { + PrepareBuilder(); result.hasField205 = false; result.field205_ = false; return this; @@ -5541,11 +5887,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField206(value); } } public Builder SetField206(bool value) { + PrepareBuilder(); result.hasField206 = true; result.field206_ = value; return this; } public Builder ClearField206() { + PrepareBuilder(); result.hasField206 = false; result.field206_ = false; return this; @@ -5818,7 +6166,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SpeedMessage2GroupedMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -5828,21 +6176,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SpeedMessage2GroupedMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SpeedMessage2GroupedMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - SpeedMessage2GroupedMessage result = new SpeedMessage2GroupedMessage(); + bool builderIsReadOnly; + SpeedMessage2GroupedMessage result; + + private SpeedMessage2GroupedMessage PrepareBuilder() { + if (builderIsReadOnly) { + SpeedMessage2GroupedMessage original = result; + result = new SpeedMessage2GroupedMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SpeedMessage2GroupedMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SpeedMessage2GroupedMessage(); + result = DefaultInstance ?? new SpeedMessage2GroupedMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -5854,12 +6229,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SpeedMessage2GroupedMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - SpeedMessage2GroupedMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -5873,6 +6247,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(SpeedMessage2GroupedMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.SpeedMessage2GroupedMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasField1) { Field1 = other.Field1; } @@ -5915,6 +6290,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6010,11 +6386,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField1(value); } } public Builder SetField1(float value) { + PrepareBuilder(); result.hasField1 = true; result.field1_ = value; return this; } public Builder ClearField1() { + PrepareBuilder(); result.hasField1 = false; result.field1_ = 0F; return this; @@ -6028,11 +6406,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField2(value); } } public Builder SetField2(float value) { + PrepareBuilder(); result.hasField2 = true; result.field2_ = value; return this; } public Builder ClearField2() { + PrepareBuilder(); result.hasField2 = false; result.field2_ = 0F; return this; @@ -6046,11 +6426,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField3(value); } } public Builder SetField3(float value) { + PrepareBuilder(); result.hasField3 = true; result.field3_ = value; return this; } public Builder ClearField3() { + PrepareBuilder(); result.hasField3 = false; result.field3_ = 0F; return this; @@ -6064,11 +6446,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField4(value); } } public Builder SetField4(bool value) { + PrepareBuilder(); result.hasField4 = true; result.field4_ = value; return this; } public Builder ClearField4() { + PrepareBuilder(); result.hasField4 = false; result.field4_ = false; return this; @@ -6082,11 +6466,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField5(value); } } public Builder SetField5(bool value) { + PrepareBuilder(); result.hasField5 = true; result.field5_ = value; return this; } public Builder ClearField5() { + PrepareBuilder(); result.hasField5 = false; result.field5_ = false; return this; @@ -6100,11 +6486,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField6(value); } } public Builder SetField6(bool value) { + PrepareBuilder(); result.hasField6 = true; result.field6_ = value; return this; } public Builder ClearField6() { + PrepareBuilder(); result.hasField6 = false; result.field6_ = true; return this; @@ -6118,11 +6506,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField7(value); } } public Builder SetField7(bool value) { + PrepareBuilder(); result.hasField7 = true; result.field7_ = value; return this; } public Builder ClearField7() { + PrepareBuilder(); result.hasField7 = false; result.field7_ = false; return this; @@ -6136,11 +6526,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField8(value); } } public Builder SetField8(float value) { + PrepareBuilder(); result.hasField8 = true; result.field8_ = value; return this; } public Builder ClearField8() { + PrepareBuilder(); result.hasField8 = false; result.field8_ = 0F; return this; @@ -6154,11 +6546,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField9(value); } } public Builder SetField9(bool value) { + PrepareBuilder(); result.hasField9 = true; result.field9_ = value; return this; } public Builder ClearField9() { + PrepareBuilder(); result.hasField9 = false; result.field9_ = false; return this; @@ -6172,11 +6566,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField10(value); } } public Builder SetField10(float value) { + PrepareBuilder(); result.hasField10 = true; result.field10_ = value; return this; } public Builder ClearField10() { + PrepareBuilder(); result.hasField10 = false; result.field10_ = 0F; return this; @@ -6190,11 +6586,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetField11(value); } } public Builder SetField11(long value) { + PrepareBuilder(); result.hasField11 = true; result.field11_ = value; return this; } public Builder ClearField11() { + PrepareBuilder(); result.hasField11 = false; result.field11_ = 0L; return this; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestImportLiteProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestImportLiteProtoFile.cs index a96833bef0..0df40f4248 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestImportLiteProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestImportLiteProtoFile.cs @@ -150,7 +150,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ImportMessageLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -160,21 +160,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ImportMessageLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ImportMessageLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ImportMessageLite result; - ImportMessageLite result = new ImportMessageLite(); + private ImportMessageLite PrepareBuilder() { + if (builderIsReadOnly) { + ImportMessageLite original = result; + result = new ImportMessageLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ImportMessageLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ImportMessageLite(); + result = DefaultInstance ?? new ImportMessageLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override ImportMessageLite DefaultInstanceForType { @@ -182,12 +209,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ImportMessageLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ImportMessageLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -201,6 +227,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ImportMessageLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasD) { D = other.D; } @@ -212,6 +239,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -254,11 +282,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetD(value); } } public Builder SetD(int value) { + PrepareBuilder(); result.hasD = true; result.d_ = value; return this; } public Builder ClearD() { + PrepareBuilder(); result.hasD = false; result.d_ = 0; return this; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestImportProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestImportProtoFile.cs index 5749c97f88..75e746a840 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestImportProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestImportProtoFile.cs @@ -169,7 +169,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ImportMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -179,21 +179,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ImportMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ImportMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ImportMessage result; - ImportMessage result = new ImportMessage(); + private ImportMessage PrepareBuilder() { + if (builderIsReadOnly) { + ImportMessage original = result; + result = new ImportMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ImportMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ImportMessage(); + result = DefaultInstance ?? new ImportMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -205,12 +232,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ImportMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ImportMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -224,6 +250,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ImportMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasD) { D = other.D; } @@ -236,6 +263,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -291,11 +319,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetD(value); } } public Builder SetD(int value) { + PrepareBuilder(); result.hasD = true; result.d_ = value; return this; } public Builder ClearD() { + PrepareBuilder(); result.hasD = false; result.d_ = 0; return this; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs index 8a6bb58929..f51b2f424e 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs @@ -189,7 +189,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMessageSet prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -199,21 +199,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMessageSet(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMessageSet cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestMessageSet result = new TestMessageSet(); + bool builderIsReadOnly; + TestMessageSet result; + + private TestMessageSet PrepareBuilder() { + if (builderIsReadOnly) { + TestMessageSet original = result; + result = new TestMessageSet(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMessageSet MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMessageSet(); + result = DefaultInstance ?? new TestMessageSet(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -225,12 +252,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMessageSet BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMessageSet returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -244,6 +270,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMessageSet other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMessageSet.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -254,6 +281,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -404,7 +432,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMessageSetContainer prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -414,21 +442,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMessageSetContainer(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMessageSetContainer cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestMessageSetContainer result = new TestMessageSetContainer(); + bool builderIsReadOnly; + TestMessageSetContainer result; + + private TestMessageSetContainer PrepareBuilder() { + if (builderIsReadOnly) { + TestMessageSetContainer original = result; + result = new TestMessageSetContainer(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMessageSetContainer MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMessageSetContainer(); + result = DefaultInstance ?? new TestMessageSetContainer(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -440,12 +495,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMessageSetContainer BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMessageSetContainer returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -459,6 +513,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMessageSetContainer other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMessageSetContainer.DefaultInstance) return this; + PrepareBuilder(); if (other.HasMessageSet) { MergeMessageSet(other.MessageSet); } @@ -471,6 +526,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -532,18 +588,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMessageSet(global::Google.ProtocolBuffers.TestProtos.TestMessageSet value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMessageSet = true; result.messageSet_ = value; return this; } public Builder SetMessageSet(global::Google.ProtocolBuffers.TestProtos.TestMessageSet.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasMessageSet = true; result.messageSet_ = builderForValue.Build(); return this; } public Builder MergeMessageSet(global::Google.ProtocolBuffers.TestProtos.TestMessageSet value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasMessageSet && result.messageSet_ != global::Google.ProtocolBuffers.TestProtos.TestMessageSet.DefaultInstance) { result.messageSet_ = global::Google.ProtocolBuffers.TestProtos.TestMessageSet.CreateBuilder(result.messageSet_).MergeFrom(value).BuildPartial(); @@ -554,6 +613,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearMessageSet() { + PrepareBuilder(); result.hasMessageSet = false; result.messageSet_ = global::Google.ProtocolBuffers.TestProtos.TestMessageSet.DefaultInstance; return this; @@ -668,7 +728,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMessageSetExtension1 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -678,21 +738,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMessageSetExtension1(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMessageSetExtension1 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestMessageSetExtension1 result = new TestMessageSetExtension1(); + bool builderIsReadOnly; + TestMessageSetExtension1 result; + + private TestMessageSetExtension1 PrepareBuilder() { + if (builderIsReadOnly) { + TestMessageSetExtension1 original = result; + result = new TestMessageSetExtension1(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMessageSetExtension1 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMessageSetExtension1(); + result = DefaultInstance ?? new TestMessageSetExtension1(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -704,12 +791,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMessageSetExtension1 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMessageSetExtension1 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -723,6 +809,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMessageSetExtension1 other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMessageSetExtension1.DefaultInstance) return this; + PrepareBuilder(); if (other.HasI) { I = other.I; } @@ -735,6 +822,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -790,11 +878,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetI(value); } } public Builder SetI(int value) { + PrepareBuilder(); result.hasI = true; result.i_ = value; return this; } public Builder ClearI() { + PrepareBuilder(); result.hasI = false; result.i_ = 0; return this; @@ -909,7 +999,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMessageSetExtension2 prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -919,21 +1009,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMessageSetExtension2(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMessageSetExtension2 cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestMessageSetExtension2 result = new TestMessageSetExtension2(); + bool builderIsReadOnly; + TestMessageSetExtension2 result; + + private TestMessageSetExtension2 PrepareBuilder() { + if (builderIsReadOnly) { + TestMessageSetExtension2 original = result; + result = new TestMessageSetExtension2(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMessageSetExtension2 MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMessageSetExtension2(); + result = DefaultInstance ?? new TestMessageSetExtension2(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -945,12 +1062,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMessageSetExtension2 BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMessageSetExtension2 returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -964,6 +1080,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMessageSetExtension2 other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMessageSetExtension2.DefaultInstance) return this; + PrepareBuilder(); if (other.HasStr) { Str = other.Str; } @@ -976,6 +1093,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1032,11 +1150,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetStr(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasStr = true; result.str_ = value; return this; } public Builder ClearStr() { + PrepareBuilder(); result.hasStr = false; result.str_ = ""; return this; @@ -1199,7 +1319,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Item prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1209,21 +1329,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Item(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Item cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - Item result = new Item(); + bool builderIsReadOnly; + Item result; + + private Item PrepareBuilder() { + if (builderIsReadOnly) { + Item original = result; + result = new Item(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Item MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Item(); + result = DefaultInstance ?? new Item(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1235,12 +1382,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Item BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - Item returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1254,6 +1400,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(Item other) { if (other == global::Google.ProtocolBuffers.TestProtos.RawMessageSet.Types.Item.DefaultInstance) return this; + PrepareBuilder(); if (other.HasTypeId) { TypeId = other.TypeId; } @@ -1269,6 +1416,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1328,11 +1476,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetTypeId(value); } } public Builder SetTypeId(int value) { + PrepareBuilder(); result.hasTypeId = true; result.typeId_ = value; return this; } public Builder ClearTypeId() { + PrepareBuilder(); result.hasTypeId = false; result.typeId_ = 0; return this; @@ -1347,11 +1497,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMessage(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMessage = true; result.message_ = value; return this; } public Builder ClearMessage() { + PrepareBuilder(); result.hasMessage = false; result.message_ = pb::ByteString.Empty; return this; @@ -1442,7 +1594,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(RawMessageSet prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1452,21 +1604,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new RawMessageSet(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(RawMessageSet cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - RawMessageSet result = new RawMessageSet(); + bool builderIsReadOnly; + RawMessageSet result; + + private RawMessageSet PrepareBuilder() { + if (builderIsReadOnly) { + RawMessageSet original = result; + result = new RawMessageSet(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override RawMessageSet MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new RawMessageSet(); + result = DefaultInstance ?? new RawMessageSet(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1478,13 +1657,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override RawMessageSet BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.item_.MakeReadOnly(); - RawMessageSet returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1498,6 +1676,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(RawMessageSet other) { if (other == global::Google.ProtocolBuffers.TestProtos.RawMessageSet.DefaultInstance) return this; + PrepareBuilder(); if (other.item_.Count != 0) { base.AddRange(other.item_, result.item_); } @@ -1510,6 +1689,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1558,7 +1738,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList ItemList { - get { return result.item_; } + get { return PrepareBuilder().item_; } } public int ItemCount { get { return result.ItemCount; } @@ -1568,29 +1748,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetItem(int index, global::Google.ProtocolBuffers.TestProtos.RawMessageSet.Types.Item value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.item_[index] = value; return this; } public Builder SetItem(int index, global::Google.ProtocolBuffers.TestProtos.RawMessageSet.Types.Item.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.item_[index] = builderForValue.Build(); return this; } public Builder AddItem(global::Google.ProtocolBuffers.TestProtos.RawMessageSet.Types.Item value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.item_.Add(value); return this; } public Builder AddItem(global::Google.ProtocolBuffers.TestProtos.RawMessageSet.Types.Item.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.item_.Add(builderForValue.Build()); return this; } public Builder AddRangeItem(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.item_); return this; } public Builder ClearItem() { + PrepareBuilder(); result.item_.Clear(); return this; } diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestNoGenericServicesProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestNoGenericServicesProtoFile.cs index 74d6af60eb..ca401926e3 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestNoGenericServicesProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestNoGenericServicesProtoFile.cs @@ -183,7 +183,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -193,21 +193,48 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestMessage result; - TestMessage result = new TestMessage(); + private TestMessage PrepareBuilder() { + if (builderIsReadOnly) { + TestMessage original = result; + result = new TestMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMessage(); + result = DefaultInstance ?? new TestMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -219,12 +246,11 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { } public override TestMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -238,6 +264,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { public override Builder MergeFrom(TestMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.NoGenericService.TestMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -251,6 +278,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -306,11 +334,13 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs index c7153abc4c..967d549adf 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs @@ -164,7 +164,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestOptimizedForSize prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -174,21 +174,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestOptimizedForSize(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestOptimizedForSize cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestOptimizedForSize result = new TestOptimizedForSize(); + bool builderIsReadOnly; + TestOptimizedForSize result; + + private TestOptimizedForSize PrepareBuilder() { + if (builderIsReadOnly) { + TestOptimizedForSize original = result; + result = new TestOptimizedForSize(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestOptimizedForSize MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestOptimizedForSize(); + result = DefaultInstance ?? new TestOptimizedForSize(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -200,12 +227,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestOptimizedForSize BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestOptimizedForSize returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -217,11 +243,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetI(value); } } public Builder SetI(int value) { + PrepareBuilder(); result.hasI = true; result.i_ = value; return this; } public Builder ClearI() { + PrepareBuilder(); result.hasI = false; result.i_ = 0; return this; @@ -236,18 +264,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMsg(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMsg = true; result.msg_ = value; return this; } public Builder SetMsg(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasMsg = true; result.msg_ = builderForValue.Build(); return this; } public Builder MergeMsg(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasMsg && result.msg_ != global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) { result.msg_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.CreateBuilder(result.msg_).MergeFrom(value).BuildPartial(); @@ -258,6 +289,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearMsg() { + PrepareBuilder(); result.hasMsg = false; result.msg_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance; return this; @@ -337,7 +369,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRequiredOptimizedForSize prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -347,21 +379,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRequiredOptimizedForSize(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRequiredOptimizedForSize cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestRequiredOptimizedForSize result = new TestRequiredOptimizedForSize(); + bool builderIsReadOnly; + TestRequiredOptimizedForSize result; + + private TestRequiredOptimizedForSize PrepareBuilder() { + if (builderIsReadOnly) { + TestRequiredOptimizedForSize original = result; + result = new TestRequiredOptimizedForSize(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRequiredOptimizedForSize MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRequiredOptimizedForSize(); + result = DefaultInstance ?? new TestRequiredOptimizedForSize(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -373,12 +432,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRequiredOptimizedForSize BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestRequiredOptimizedForSize returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -390,11 +448,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetX(value); } } public Builder SetX(int value) { + PrepareBuilder(); result.hasX = true; result.x_ = value; return this; } public Builder ClearX() { + PrepareBuilder(); result.hasX = false; result.x_ = 0; return this; @@ -474,7 +534,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestOptionalOptimizedForSize prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -484,21 +544,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestOptionalOptimizedForSize(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestOptionalOptimizedForSize cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestOptionalOptimizedForSize result = new TestOptionalOptimizedForSize(); + bool builderIsReadOnly; + TestOptionalOptimizedForSize result; + + private TestOptionalOptimizedForSize PrepareBuilder() { + if (builderIsReadOnly) { + TestOptionalOptimizedForSize original = result; + result = new TestOptionalOptimizedForSize(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestOptionalOptimizedForSize MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestOptionalOptimizedForSize(); + result = DefaultInstance ?? new TestOptionalOptimizedForSize(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -510,12 +597,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestOptionalOptimizedForSize BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestOptionalOptimizedForSize returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -528,18 +614,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetO(global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasO = true; result.o_ = value; return this; } public Builder SetO(global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasO = true; result.o_ = builderForValue.Build(); return this; } public Builder MergeO(global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasO && result.o_ != global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize.DefaultInstance) { result.o_ = global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize.CreateBuilder(result.o_).MergeFrom(value).BuildPartial(); @@ -550,6 +639,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearO() { + PrepareBuilder(); result.hasO = false; result.o_ = global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize.DefaultInstance; return this; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs index d8824d49a4..aeea673d57 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs @@ -1260,7 +1260,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(NestedMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1270,21 +1270,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(NestedMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + NestedMessage result; + + private NestedMessage PrepareBuilder() { + if (builderIsReadOnly) { + NestedMessage original = result; + result = new NestedMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - NestedMessage result = new NestedMessage(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override NestedMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new NestedMessage(); + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1296,12 +1323,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override NestedMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - NestedMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1315,6 +1341,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(NestedMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasBb) { Bb = other.Bb; } @@ -1327,6 +1354,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1382,11 +1410,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetBb(value); } } public Builder SetBb(int value) { + PrepareBuilder(); result.hasBb = true; result.bb_ = value; return this; } public Builder ClearBb() { + PrepareBuilder(); result.hasBb = false; result.bb_ = 0; return this; @@ -1499,7 +1529,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OptionalGroup prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1509,21 +1539,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OptionalGroup(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OptionalGroup cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + OptionalGroup result; + + private OptionalGroup PrepareBuilder() { + if (builderIsReadOnly) { + OptionalGroup original = result; + result = new OptionalGroup(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - OptionalGroup result = new OptionalGroup(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OptionalGroup MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OptionalGroup(); + result = DefaultInstance ?? new OptionalGroup(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1535,12 +1592,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OptionalGroup BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OptionalGroup returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1554,6 +1610,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OptionalGroup other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -1566,6 +1623,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1621,11 +1679,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -1738,7 +1798,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(RepeatedGroup prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1748,21 +1808,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new RepeatedGroup(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(RepeatedGroup cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + RepeatedGroup result; - RepeatedGroup result = new RepeatedGroup(); + private RepeatedGroup PrepareBuilder() { + if (builderIsReadOnly) { + RepeatedGroup original = result; + result = new RepeatedGroup(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override RepeatedGroup MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new RepeatedGroup(); + result = DefaultInstance ?? new RepeatedGroup(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1774,12 +1861,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override RepeatedGroup BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - RepeatedGroup returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1793,6 +1879,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(RepeatedGroup other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -1805,6 +1892,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1860,11 +1948,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -3181,7 +3271,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestAllTypes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3191,21 +3281,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestAllTypes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestAllTypes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestAllTypes result; + + private TestAllTypes PrepareBuilder() { + if (builderIsReadOnly) { + TestAllTypes original = result; + result = new TestAllTypes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestAllTypes result = new TestAllTypes(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestAllTypes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestAllTypes(); + result = DefaultInstance ?? new TestAllTypes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3217,8 +3334,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestAllTypes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedInt32_.MakeReadOnly(); result.repeatedInt64_.MakeReadOnly(); @@ -3244,9 +3361,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.repeatedImportEnum_.MakeReadOnly(); result.repeatedStringPiece_.MakeReadOnly(); result.repeatedCord_.MakeReadOnly(); - TestAllTypes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -3260,6 +3376,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestAllTypes other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance) return this; + PrepareBuilder(); if (other.HasOptionalInt32) { OptionalInt32 = other.OptionalInt32; } @@ -3473,6 +3590,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -3907,11 +4025,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalInt32(value); } } public Builder SetOptionalInt32(int value) { + PrepareBuilder(); result.hasOptionalInt32 = true; result.optionalInt32_ = value; return this; } public Builder ClearOptionalInt32() { + PrepareBuilder(); result.hasOptionalInt32 = false; result.optionalInt32_ = 0; return this; @@ -3925,11 +4045,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalInt64(value); } } public Builder SetOptionalInt64(long value) { + PrepareBuilder(); result.hasOptionalInt64 = true; result.optionalInt64_ = value; return this; } public Builder ClearOptionalInt64() { + PrepareBuilder(); result.hasOptionalInt64 = false; result.optionalInt64_ = 0L; return this; @@ -3945,11 +4067,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalUint32(uint value) { + PrepareBuilder(); result.hasOptionalUint32 = true; result.optionalUint32_ = value; return this; } public Builder ClearOptionalUint32() { + PrepareBuilder(); result.hasOptionalUint32 = false; result.optionalUint32_ = 0; return this; @@ -3965,11 +4089,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalUint64(ulong value) { + PrepareBuilder(); result.hasOptionalUint64 = true; result.optionalUint64_ = value; return this; } public Builder ClearOptionalUint64() { + PrepareBuilder(); result.hasOptionalUint64 = false; result.optionalUint64_ = 0UL; return this; @@ -3983,11 +4109,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSint32(value); } } public Builder SetOptionalSint32(int value) { + PrepareBuilder(); result.hasOptionalSint32 = true; result.optionalSint32_ = value; return this; } public Builder ClearOptionalSint32() { + PrepareBuilder(); result.hasOptionalSint32 = false; result.optionalSint32_ = 0; return this; @@ -4001,11 +4129,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSint64(value); } } public Builder SetOptionalSint64(long value) { + PrepareBuilder(); result.hasOptionalSint64 = true; result.optionalSint64_ = value; return this; } public Builder ClearOptionalSint64() { + PrepareBuilder(); result.hasOptionalSint64 = false; result.optionalSint64_ = 0; return this; @@ -4021,11 +4151,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalFixed32(uint value) { + PrepareBuilder(); result.hasOptionalFixed32 = true; result.optionalFixed32_ = value; return this; } public Builder ClearOptionalFixed32() { + PrepareBuilder(); result.hasOptionalFixed32 = false; result.optionalFixed32_ = 0; return this; @@ -4041,11 +4173,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalFixed64(ulong value) { + PrepareBuilder(); result.hasOptionalFixed64 = true; result.optionalFixed64_ = value; return this; } public Builder ClearOptionalFixed64() { + PrepareBuilder(); result.hasOptionalFixed64 = false; result.optionalFixed64_ = 0; return this; @@ -4059,11 +4193,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSfixed32(value); } } public Builder SetOptionalSfixed32(int value) { + PrepareBuilder(); result.hasOptionalSfixed32 = true; result.optionalSfixed32_ = value; return this; } public Builder ClearOptionalSfixed32() { + PrepareBuilder(); result.hasOptionalSfixed32 = false; result.optionalSfixed32_ = 0; return this; @@ -4077,11 +4213,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSfixed64(value); } } public Builder SetOptionalSfixed64(long value) { + PrepareBuilder(); result.hasOptionalSfixed64 = true; result.optionalSfixed64_ = value; return this; } public Builder ClearOptionalSfixed64() { + PrepareBuilder(); result.hasOptionalSfixed64 = false; result.optionalSfixed64_ = 0; return this; @@ -4095,11 +4233,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalFloat(value); } } public Builder SetOptionalFloat(float value) { + PrepareBuilder(); result.hasOptionalFloat = true; result.optionalFloat_ = value; return this; } public Builder ClearOptionalFloat() { + PrepareBuilder(); result.hasOptionalFloat = false; result.optionalFloat_ = 0F; return this; @@ -4113,11 +4253,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalDouble(value); } } public Builder SetOptionalDouble(double value) { + PrepareBuilder(); result.hasOptionalDouble = true; result.optionalDouble_ = value; return this; } public Builder ClearOptionalDouble() { + PrepareBuilder(); result.hasOptionalDouble = false; result.optionalDouble_ = 0D; return this; @@ -4131,11 +4273,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalBool(value); } } public Builder SetOptionalBool(bool value) { + PrepareBuilder(); result.hasOptionalBool = true; result.optionalBool_ = value; return this; } public Builder ClearOptionalBool() { + PrepareBuilder(); result.hasOptionalBool = false; result.optionalBool_ = false; return this; @@ -4150,11 +4294,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalString = true; result.optionalString_ = value; return this; } public Builder ClearOptionalString() { + PrepareBuilder(); result.hasOptionalString = false; result.optionalString_ = ""; return this; @@ -4169,11 +4315,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalBytes = true; result.optionalBytes_ = value; return this; } public Builder ClearOptionalBytes() { + PrepareBuilder(); result.hasOptionalBytes = false; result.optionalBytes_ = pb::ByteString.Empty; return this; @@ -4188,18 +4336,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalGroup = true; result.optionalGroup_ = value; return this; } public Builder SetOptionalGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalGroup = true; result.optionalGroup_ = builderForValue.Build(); return this; } public Builder MergeOptionalGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalGroup && result.optionalGroup_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.DefaultInstance) { result.optionalGroup_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.CreateBuilder(result.optionalGroup_).MergeFrom(value).BuildPartial(); @@ -4210,6 +4361,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalGroup() { + PrepareBuilder(); result.hasOptionalGroup = false; result.optionalGroup_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.DefaultInstance; return this; @@ -4224,18 +4376,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = value; return this; } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalNestedMessage && result.optionalNestedMessage_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance) { result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.CreateBuilder(result.optionalNestedMessage_).MergeFrom(value).BuildPartial(); @@ -4246,6 +4401,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalNestedMessage() { + PrepareBuilder(); result.hasOptionalNestedMessage = false; result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance; return this; @@ -4260,18 +4416,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalForeignMessage = true; result.optionalForeignMessage_ = value; return this; } public Builder SetOptionalForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalForeignMessage = true; result.optionalForeignMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalForeignMessage && result.optionalForeignMessage_ != global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) { result.optionalForeignMessage_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.CreateBuilder(result.optionalForeignMessage_).MergeFrom(value).BuildPartial(); @@ -4282,6 +4441,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalForeignMessage() { + PrepareBuilder(); result.hasOptionalForeignMessage = false; result.optionalForeignMessage_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance; return this; @@ -4296,18 +4456,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalImportMessage = true; result.optionalImportMessage_ = value; return this; } public Builder SetOptionalImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalImportMessage = true; result.optionalImportMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalImportMessage && result.optionalImportMessage_ != global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) { result.optionalImportMessage_ = global::Google.ProtocolBuffers.TestProtos.ImportMessage.CreateBuilder(result.optionalImportMessage_).MergeFrom(value).BuildPartial(); @@ -4318,6 +4481,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalImportMessage() { + PrepareBuilder(); result.hasOptionalImportMessage = false; result.optionalImportMessage_ = global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance; return this; @@ -4331,11 +4495,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalNestedEnum(value); } } public Builder SetOptionalNestedEnum(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum value) { + PrepareBuilder(); result.hasOptionalNestedEnum = true; result.optionalNestedEnum_ = value; return this; } public Builder ClearOptionalNestedEnum() { + PrepareBuilder(); result.hasOptionalNestedEnum = false; result.optionalNestedEnum_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum.FOO; return this; @@ -4349,11 +4515,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalForeignEnum(value); } } public Builder SetOptionalForeignEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.hasOptionalForeignEnum = true; result.optionalForeignEnum_ = value; return this; } public Builder ClearOptionalForeignEnum() { + PrepareBuilder(); result.hasOptionalForeignEnum = false; result.optionalForeignEnum_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnum.FOREIGN_FOO; return this; @@ -4367,11 +4535,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalImportEnum(value); } } public Builder SetOptionalImportEnum(global::Google.ProtocolBuffers.TestProtos.ImportEnum value) { + PrepareBuilder(); result.hasOptionalImportEnum = true; result.optionalImportEnum_ = value; return this; } public Builder ClearOptionalImportEnum() { + PrepareBuilder(); result.hasOptionalImportEnum = false; result.optionalImportEnum_ = global::Google.ProtocolBuffers.TestProtos.ImportEnum.IMPORT_FOO; return this; @@ -4386,11 +4556,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalStringPiece(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalStringPiece = true; result.optionalStringPiece_ = value; return this; } public Builder ClearOptionalStringPiece() { + PrepareBuilder(); result.hasOptionalStringPiece = false; result.optionalStringPiece_ = ""; return this; @@ -4405,18 +4577,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalCord(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalCord = true; result.optionalCord_ = value; return this; } public Builder ClearOptionalCord() { + PrepareBuilder(); result.hasOptionalCord = false; result.optionalCord_ = ""; return this; } public pbc::IPopsicleList RepeatedInt32List { - get { return result.repeatedInt32_; } + get { return PrepareBuilder().repeatedInt32_; } } public int RepeatedInt32Count { get { return result.RepeatedInt32Count; } @@ -4425,24 +4599,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt32(index); } public Builder SetRepeatedInt32(int index, int value) { + PrepareBuilder(); result.repeatedInt32_[index] = value; return this; } public Builder AddRepeatedInt32(int value) { + PrepareBuilder(); result.repeatedInt32_.Add(value); return this; } public Builder AddRangeRepeatedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt32_); return this; } public Builder ClearRepeatedInt32() { + PrepareBuilder(); result.repeatedInt32_.Clear(); return this; } public pbc::IPopsicleList RepeatedInt64List { - get { return result.repeatedInt64_; } + get { return PrepareBuilder().repeatedInt64_; } } public int RepeatedInt64Count { get { return result.RepeatedInt64Count; } @@ -4451,25 +4629,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt64(index); } public Builder SetRepeatedInt64(int index, long value) { + PrepareBuilder(); result.repeatedInt64_[index] = value; return this; } public Builder AddRepeatedInt64(long value) { + PrepareBuilder(); result.repeatedInt64_.Add(value); return this; } public Builder AddRangeRepeatedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt64_); return this; } public Builder ClearRepeatedInt64() { + PrepareBuilder(); result.repeatedInt64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedUint32List { - get { return result.repeatedUint32_; } + get { return PrepareBuilder().repeatedUint32_; } } public int RepeatedUint32Count { get { return result.RepeatedUint32Count; } @@ -4480,27 +4662,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedUint32(int index, uint value) { + PrepareBuilder(); result.repeatedUint32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedUint32(uint value) { + PrepareBuilder(); result.repeatedUint32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedUint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedUint32_); return this; } public Builder ClearRepeatedUint32() { + PrepareBuilder(); result.repeatedUint32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedUint64List { - get { return result.repeatedUint64_; } + get { return PrepareBuilder().repeatedUint64_; } } public int RepeatedUint64Count { get { return result.RepeatedUint64Count; } @@ -4511,26 +4697,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedUint64(int index, ulong value) { + PrepareBuilder(); result.repeatedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedUint64(ulong value) { + PrepareBuilder(); result.repeatedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedUint64_); return this; } public Builder ClearRepeatedUint64() { + PrepareBuilder(); result.repeatedUint64_.Clear(); return this; } public pbc::IPopsicleList RepeatedSint32List { - get { return result.repeatedSint32_; } + get { return PrepareBuilder().repeatedSint32_; } } public int RepeatedSint32Count { get { return result.RepeatedSint32Count; } @@ -4539,24 +4729,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSint32(index); } public Builder SetRepeatedSint32(int index, int value) { + PrepareBuilder(); result.repeatedSint32_[index] = value; return this; } public Builder AddRepeatedSint32(int value) { + PrepareBuilder(); result.repeatedSint32_.Add(value); return this; } public Builder AddRangeRepeatedSint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSint32_); return this; } public Builder ClearRepeatedSint32() { + PrepareBuilder(); result.repeatedSint32_.Clear(); return this; } public pbc::IPopsicleList RepeatedSint64List { - get { return result.repeatedSint64_; } + get { return PrepareBuilder().repeatedSint64_; } } public int RepeatedSint64Count { get { return result.RepeatedSint64Count; } @@ -4565,25 +4759,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSint64(index); } public Builder SetRepeatedSint64(int index, long value) { + PrepareBuilder(); result.repeatedSint64_[index] = value; return this; } public Builder AddRepeatedSint64(long value) { + PrepareBuilder(); result.repeatedSint64_.Add(value); return this; } public Builder AddRangeRepeatedSint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSint64_); return this; } public Builder ClearRepeatedSint64() { + PrepareBuilder(); result.repeatedSint64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed32List { - get { return result.repeatedFixed32_; } + get { return PrepareBuilder().repeatedFixed32_; } } public int RepeatedFixed32Count { get { return result.RepeatedFixed32Count; } @@ -4594,27 +4792,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed32(int index, uint value) { + PrepareBuilder(); result.repeatedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed32(uint value) { + PrepareBuilder(); result.repeatedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed32_); return this; } public Builder ClearRepeatedFixed32() { + PrepareBuilder(); result.repeatedFixed32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed64List { - get { return result.repeatedFixed64_; } + get { return PrepareBuilder().repeatedFixed64_; } } public int RepeatedFixed64Count { get { return result.RepeatedFixed64Count; } @@ -4625,26 +4827,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed64(int index, ulong value) { + PrepareBuilder(); result.repeatedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed64(ulong value) { + PrepareBuilder(); result.repeatedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed64_); return this; } public Builder ClearRepeatedFixed64() { + PrepareBuilder(); result.repeatedFixed64_.Clear(); return this; } public pbc::IPopsicleList RepeatedSfixed32List { - get { return result.repeatedSfixed32_; } + get { return PrepareBuilder().repeatedSfixed32_; } } public int RepeatedSfixed32Count { get { return result.RepeatedSfixed32Count; } @@ -4653,24 +4859,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSfixed32(index); } public Builder SetRepeatedSfixed32(int index, int value) { + PrepareBuilder(); result.repeatedSfixed32_[index] = value; return this; } public Builder AddRepeatedSfixed32(int value) { + PrepareBuilder(); result.repeatedSfixed32_.Add(value); return this; } public Builder AddRangeRepeatedSfixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSfixed32_); return this; } public Builder ClearRepeatedSfixed32() { + PrepareBuilder(); result.repeatedSfixed32_.Clear(); return this; } public pbc::IPopsicleList RepeatedSfixed64List { - get { return result.repeatedSfixed64_; } + get { return PrepareBuilder().repeatedSfixed64_; } } public int RepeatedSfixed64Count { get { return result.RepeatedSfixed64Count; } @@ -4679,24 +4889,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSfixed64(index); } public Builder SetRepeatedSfixed64(int index, long value) { + PrepareBuilder(); result.repeatedSfixed64_[index] = value; return this; } public Builder AddRepeatedSfixed64(long value) { + PrepareBuilder(); result.repeatedSfixed64_.Add(value); return this; } public Builder AddRangeRepeatedSfixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSfixed64_); return this; } public Builder ClearRepeatedSfixed64() { + PrepareBuilder(); result.repeatedSfixed64_.Clear(); return this; } public pbc::IPopsicleList RepeatedFloatList { - get { return result.repeatedFloat_; } + get { return PrepareBuilder().repeatedFloat_; } } public int RepeatedFloatCount { get { return result.RepeatedFloatCount; } @@ -4705,24 +4919,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedFloat(index); } public Builder SetRepeatedFloat(int index, float value) { + PrepareBuilder(); result.repeatedFloat_[index] = value; return this; } public Builder AddRepeatedFloat(float value) { + PrepareBuilder(); result.repeatedFloat_.Add(value); return this; } public Builder AddRangeRepeatedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFloat_); return this; } public Builder ClearRepeatedFloat() { + PrepareBuilder(); result.repeatedFloat_.Clear(); return this; } public pbc::IPopsicleList RepeatedDoubleList { - get { return result.repeatedDouble_; } + get { return PrepareBuilder().repeatedDouble_; } } public int RepeatedDoubleCount { get { return result.RepeatedDoubleCount; } @@ -4731,24 +4949,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedDouble(index); } public Builder SetRepeatedDouble(int index, double value) { + PrepareBuilder(); result.repeatedDouble_[index] = value; return this; } public Builder AddRepeatedDouble(double value) { + PrepareBuilder(); result.repeatedDouble_.Add(value); return this; } public Builder AddRangeRepeatedDouble(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedDouble_); return this; } public Builder ClearRepeatedDouble() { + PrepareBuilder(); result.repeatedDouble_.Clear(); return this; } public pbc::IPopsicleList RepeatedBoolList { - get { return result.repeatedBool_; } + get { return PrepareBuilder().repeatedBool_; } } public int RepeatedBoolCount { get { return result.RepeatedBoolCount; } @@ -4757,24 +4979,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedBool(index); } public Builder SetRepeatedBool(int index, bool value) { + PrepareBuilder(); result.repeatedBool_[index] = value; return this; } public Builder AddRepeatedBool(bool value) { + PrepareBuilder(); result.repeatedBool_.Add(value); return this; } public Builder AddRangeRepeatedBool(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedBool_); return this; } public Builder ClearRepeatedBool() { + PrepareBuilder(); result.repeatedBool_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringList { - get { return result.repeatedString_; } + get { return PrepareBuilder().repeatedString_; } } public int RepeatedStringCount { get { return result.RepeatedStringCount; } @@ -4784,25 +5010,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedString(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedString_[index] = value; return this; } public Builder AddRepeatedString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedString_.Add(value); return this; } public Builder AddRangeRepeatedString(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedString_); return this; } public Builder ClearRepeatedString() { + PrepareBuilder(); result.repeatedString_.Clear(); return this; } public pbc::IPopsicleList RepeatedBytesList { - get { return result.repeatedBytes_; } + get { return PrepareBuilder().repeatedBytes_; } } public int RepeatedBytesCount { get { return result.RepeatedBytesCount; } @@ -4812,25 +5042,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedBytes(int index, pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedBytes_[index] = value; return this; } public Builder AddRepeatedBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedBytes_.Add(value); return this; } public Builder AddRangeRepeatedBytes(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedBytes_); return this; } public Builder ClearRepeatedBytes() { + PrepareBuilder(); result.repeatedBytes_.Clear(); return this; } public pbc::IPopsicleList RepeatedGroupList { - get { return result.repeatedGroup_; } + get { return PrepareBuilder().repeatedGroup_; } } public int RepeatedGroupCount { get { return result.RepeatedGroupCount; } @@ -4840,35 +5074,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedGroup(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedGroup_[index] = value; return this; } public Builder SetRepeatedGroup(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedGroup_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedGroup_.Add(value); return this; } public Builder AddRepeatedGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedGroup_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedGroup(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedGroup_); return this; } public Builder ClearRepeatedGroup() { + PrepareBuilder(); result.repeatedGroup_.Clear(); return this; } public pbc::IPopsicleList RepeatedNestedMessageList { - get { return result.repeatedNestedMessage_; } + get { return PrepareBuilder().repeatedNestedMessage_; } } public int RepeatedNestedMessageCount { get { return result.RepeatedNestedMessageCount; } @@ -4878,35 +5118,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedNestedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedNestedMessage_[index] = value; return this; } public Builder SetRepeatedNestedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedNestedMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedNestedMessage_.Add(value); return this; } public Builder AddRepeatedNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedNestedMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedNestedMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedNestedMessage_); return this; } public Builder ClearRepeatedNestedMessage() { + PrepareBuilder(); result.repeatedNestedMessage_.Clear(); return this; } public pbc::IPopsicleList RepeatedForeignMessageList { - get { return result.repeatedForeignMessage_; } + get { return PrepareBuilder().repeatedForeignMessage_; } } public int RepeatedForeignMessageCount { get { return result.RepeatedForeignMessageCount; } @@ -4916,35 +5162,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedForeignMessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedForeignMessage_[index] = value; return this; } public Builder SetRepeatedForeignMessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedForeignMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedForeignMessage_.Add(value); return this; } public Builder AddRepeatedForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedForeignMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedForeignMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedForeignMessage_); return this; } public Builder ClearRepeatedForeignMessage() { + PrepareBuilder(); result.repeatedForeignMessage_.Clear(); return this; } public pbc::IPopsicleList RepeatedImportMessageList { - get { return result.repeatedImportMessage_; } + get { return PrepareBuilder().repeatedImportMessage_; } } public int RepeatedImportMessageCount { get { return result.RepeatedImportMessageCount; } @@ -4954,35 +5206,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedImportMessage(int index, global::Google.ProtocolBuffers.TestProtos.ImportMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedImportMessage_[index] = value; return this; } public Builder SetRepeatedImportMessage(int index, global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedImportMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedImportMessage_.Add(value); return this; } public Builder AddRepeatedImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedImportMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedImportMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedImportMessage_); return this; } public Builder ClearRepeatedImportMessage() { + PrepareBuilder(); result.repeatedImportMessage_.Clear(); return this; } public pbc::IPopsicleList RepeatedNestedEnumList { - get { return result.repeatedNestedEnum_; } + get { return PrepareBuilder().repeatedNestedEnum_; } } public int RepeatedNestedEnumCount { get { return result.RepeatedNestedEnumCount; } @@ -4991,24 +5249,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedNestedEnum(index); } public Builder SetRepeatedNestedEnum(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum value) { + PrepareBuilder(); result.repeatedNestedEnum_[index] = value; return this; } public Builder AddRepeatedNestedEnum(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum value) { + PrepareBuilder(); result.repeatedNestedEnum_.Add(value); return this; } public Builder AddRangeRepeatedNestedEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedNestedEnum_); return this; } public Builder ClearRepeatedNestedEnum() { + PrepareBuilder(); result.repeatedNestedEnum_.Clear(); return this; } public pbc::IPopsicleList RepeatedForeignEnumList { - get { return result.repeatedForeignEnum_; } + get { return PrepareBuilder().repeatedForeignEnum_; } } public int RepeatedForeignEnumCount { get { return result.RepeatedForeignEnumCount; } @@ -5017,24 +5279,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedForeignEnum(index); } public Builder SetRepeatedForeignEnum(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.repeatedForeignEnum_[index] = value; return this; } public Builder AddRepeatedForeignEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.repeatedForeignEnum_.Add(value); return this; } public Builder AddRangeRepeatedForeignEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedForeignEnum_); return this; } public Builder ClearRepeatedForeignEnum() { + PrepareBuilder(); result.repeatedForeignEnum_.Clear(); return this; } public pbc::IPopsicleList RepeatedImportEnumList { - get { return result.repeatedImportEnum_; } + get { return PrepareBuilder().repeatedImportEnum_; } } public int RepeatedImportEnumCount { get { return result.RepeatedImportEnumCount; } @@ -5043,24 +5309,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedImportEnum(index); } public Builder SetRepeatedImportEnum(int index, global::Google.ProtocolBuffers.TestProtos.ImportEnum value) { + PrepareBuilder(); result.repeatedImportEnum_[index] = value; return this; } public Builder AddRepeatedImportEnum(global::Google.ProtocolBuffers.TestProtos.ImportEnum value) { + PrepareBuilder(); result.repeatedImportEnum_.Add(value); return this; } public Builder AddRangeRepeatedImportEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedImportEnum_); return this; } public Builder ClearRepeatedImportEnum() { + PrepareBuilder(); result.repeatedImportEnum_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringPieceList { - get { return result.repeatedStringPiece_; } + get { return PrepareBuilder().repeatedStringPiece_; } } public int RepeatedStringPieceCount { get { return result.RepeatedStringPieceCount; } @@ -5070,25 +5340,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedStringPiece(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPiece_[index] = value; return this; } public Builder AddRepeatedStringPiece(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPiece_.Add(value); return this; } public Builder AddRangeRepeatedStringPiece(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedStringPiece_); return this; } public Builder ClearRepeatedStringPiece() { + PrepareBuilder(); result.repeatedStringPiece_.Clear(); return this; } public pbc::IPopsicleList RepeatedCordList { - get { return result.repeatedCord_; } + get { return PrepareBuilder().repeatedCord_; } } public int RepeatedCordCount { get { return result.RepeatedCordCount; } @@ -5098,19 +5372,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedCord(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCord_[index] = value; return this; } public Builder AddRepeatedCord(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCord_.Add(value); return this; } public Builder AddRangeRepeatedCord(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedCord_); return this; } public Builder ClearRepeatedCord() { + PrepareBuilder(); result.repeatedCord_.Clear(); return this; } @@ -5123,11 +5401,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultInt32(value); } } public Builder SetDefaultInt32(int value) { + PrepareBuilder(); result.hasDefaultInt32 = true; result.defaultInt32_ = value; return this; } public Builder ClearDefaultInt32() { + PrepareBuilder(); result.hasDefaultInt32 = false; result.defaultInt32_ = 41; return this; @@ -5141,11 +5421,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultInt64(value); } } public Builder SetDefaultInt64(long value) { + PrepareBuilder(); result.hasDefaultInt64 = true; result.defaultInt64_ = value; return this; } public Builder ClearDefaultInt64() { + PrepareBuilder(); result.hasDefaultInt64 = false; result.defaultInt64_ = 42L; return this; @@ -5161,11 +5443,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultUint32(uint value) { + PrepareBuilder(); result.hasDefaultUint32 = true; result.defaultUint32_ = value; return this; } public Builder ClearDefaultUint32() { + PrepareBuilder(); result.hasDefaultUint32 = false; result.defaultUint32_ = 43; return this; @@ -5181,11 +5465,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultUint64(ulong value) { + PrepareBuilder(); result.hasDefaultUint64 = true; result.defaultUint64_ = value; return this; } public Builder ClearDefaultUint64() { + PrepareBuilder(); result.hasDefaultUint64 = false; result.defaultUint64_ = 44UL; return this; @@ -5199,11 +5485,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSint32(value); } } public Builder SetDefaultSint32(int value) { + PrepareBuilder(); result.hasDefaultSint32 = true; result.defaultSint32_ = value; return this; } public Builder ClearDefaultSint32() { + PrepareBuilder(); result.hasDefaultSint32 = false; result.defaultSint32_ = -45; return this; @@ -5217,11 +5505,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSint64(value); } } public Builder SetDefaultSint64(long value) { + PrepareBuilder(); result.hasDefaultSint64 = true; result.defaultSint64_ = value; return this; } public Builder ClearDefaultSint64() { + PrepareBuilder(); result.hasDefaultSint64 = false; result.defaultSint64_ = 46; return this; @@ -5237,11 +5527,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultFixed32(uint value) { + PrepareBuilder(); result.hasDefaultFixed32 = true; result.defaultFixed32_ = value; return this; } public Builder ClearDefaultFixed32() { + PrepareBuilder(); result.hasDefaultFixed32 = false; result.defaultFixed32_ = 47; return this; @@ -5257,11 +5549,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultFixed64(ulong value) { + PrepareBuilder(); result.hasDefaultFixed64 = true; result.defaultFixed64_ = value; return this; } public Builder ClearDefaultFixed64() { + PrepareBuilder(); result.hasDefaultFixed64 = false; result.defaultFixed64_ = 48; return this; @@ -5275,11 +5569,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSfixed32(value); } } public Builder SetDefaultSfixed32(int value) { + PrepareBuilder(); result.hasDefaultSfixed32 = true; result.defaultSfixed32_ = value; return this; } public Builder ClearDefaultSfixed32() { + PrepareBuilder(); result.hasDefaultSfixed32 = false; result.defaultSfixed32_ = 49; return this; @@ -5293,11 +5589,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSfixed64(value); } } public Builder SetDefaultSfixed64(long value) { + PrepareBuilder(); result.hasDefaultSfixed64 = true; result.defaultSfixed64_ = value; return this; } public Builder ClearDefaultSfixed64() { + PrepareBuilder(); result.hasDefaultSfixed64 = false; result.defaultSfixed64_ = -50; return this; @@ -5311,11 +5609,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultFloat(value); } } public Builder SetDefaultFloat(float value) { + PrepareBuilder(); result.hasDefaultFloat = true; result.defaultFloat_ = value; return this; } public Builder ClearDefaultFloat() { + PrepareBuilder(); result.hasDefaultFloat = false; result.defaultFloat_ = 51.5F; return this; @@ -5329,11 +5629,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultDouble(value); } } public Builder SetDefaultDouble(double value) { + PrepareBuilder(); result.hasDefaultDouble = true; result.defaultDouble_ = value; return this; } public Builder ClearDefaultDouble() { + PrepareBuilder(); result.hasDefaultDouble = false; result.defaultDouble_ = 52000D; return this; @@ -5347,11 +5649,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultBool(value); } } public Builder SetDefaultBool(bool value) { + PrepareBuilder(); result.hasDefaultBool = true; result.defaultBool_ = value; return this; } public Builder ClearDefaultBool() { + PrepareBuilder(); result.hasDefaultBool = false; result.defaultBool_ = true; return this; @@ -5366,11 +5670,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultString = true; result.defaultString_ = value; return this; } public Builder ClearDefaultString() { + PrepareBuilder(); result.hasDefaultString = false; result.defaultString_ = "hello"; return this; @@ -5385,11 +5691,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultBytes = true; result.defaultBytes_ = value; return this; } public Builder ClearDefaultBytes() { + PrepareBuilder(); result.hasDefaultBytes = false; result.defaultBytes_ = (pb::ByteString) global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Descriptor.Fields[62].DefaultValue; return this; @@ -5403,11 +5711,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultNestedEnum(value); } } public Builder SetDefaultNestedEnum(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum value) { + PrepareBuilder(); result.hasDefaultNestedEnum = true; result.defaultNestedEnum_ = value; return this; } public Builder ClearDefaultNestedEnum() { + PrepareBuilder(); result.hasDefaultNestedEnum = false; result.defaultNestedEnum_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum.BAR; return this; @@ -5421,11 +5731,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultForeignEnum(value); } } public Builder SetDefaultForeignEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.hasDefaultForeignEnum = true; result.defaultForeignEnum_ = value; return this; } public Builder ClearDefaultForeignEnum() { + PrepareBuilder(); result.hasDefaultForeignEnum = false; result.defaultForeignEnum_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnum.FOREIGN_BAR; return this; @@ -5439,11 +5751,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultImportEnum(value); } } public Builder SetDefaultImportEnum(global::Google.ProtocolBuffers.TestProtos.ImportEnum value) { + PrepareBuilder(); result.hasDefaultImportEnum = true; result.defaultImportEnum_ = value; return this; } public Builder ClearDefaultImportEnum() { + PrepareBuilder(); result.hasDefaultImportEnum = false; result.defaultImportEnum_ = global::Google.ProtocolBuffers.TestProtos.ImportEnum.IMPORT_BAR; return this; @@ -5458,11 +5772,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultStringPiece(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultStringPiece = true; result.defaultStringPiece_ = value; return this; } public Builder ClearDefaultStringPiece() { + PrepareBuilder(); result.hasDefaultStringPiece = false; result.defaultStringPiece_ = "abc"; return this; @@ -5477,11 +5793,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultCord(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultCord = true; result.defaultCord_ = value; return this; } public Builder ClearDefaultCord() { + PrepareBuilder(); result.hasDefaultCord = false; result.defaultCord_ = "123"; return this; @@ -5594,7 +5912,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestDeprecatedFields prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -5604,21 +5922,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestDeprecatedFields(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestDeprecatedFields cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestDeprecatedFields result; - TestDeprecatedFields result = new TestDeprecatedFields(); + private TestDeprecatedFields PrepareBuilder() { + if (builderIsReadOnly) { + TestDeprecatedFields original = result; + result = new TestDeprecatedFields(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestDeprecatedFields MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestDeprecatedFields(); + result = DefaultInstance ?? new TestDeprecatedFields(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -5630,12 +5975,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestDeprecatedFields BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestDeprecatedFields returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -5649,6 +5993,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestDeprecatedFields other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDeprecatedFields.DefaultInstance) return this; + PrepareBuilder(); if (other.HasDeprecatedInt32) { DeprecatedInt32 = other.DeprecatedInt32; } @@ -5661,6 +6006,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -5716,11 +6062,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDeprecatedInt32(value); } } public Builder SetDeprecatedInt32(int value) { + PrepareBuilder(); result.hasDeprecatedInt32 = true; result.deprecatedInt32_ = value; return this; } public Builder ClearDeprecatedInt32() { + PrepareBuilder(); result.hasDeprecatedInt32 = false; result.deprecatedInt32_ = 0; return this; @@ -5833,7 +6181,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ForeignMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -5843,21 +6191,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ForeignMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ForeignMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - ForeignMessage result = new ForeignMessage(); + bool builderIsReadOnly; + ForeignMessage result; + + private ForeignMessage PrepareBuilder() { + if (builderIsReadOnly) { + ForeignMessage original = result; + result = new ForeignMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ForeignMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ForeignMessage(); + result = DefaultInstance ?? new ForeignMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -5869,12 +6244,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ForeignMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ForeignMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -5888,6 +6262,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ForeignMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasC) { C = other.C; } @@ -5900,6 +6275,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -5955,11 +6331,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetC(value); } } public Builder SetC(int value) { + PrepareBuilder(); result.hasC = true; result.c_ = value; return this; } public Builder ClearC() { + PrepareBuilder(); result.hasC = false; result.c_ = 0; return this; @@ -6060,7 +6438,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestAllExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6070,21 +6448,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestAllExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestAllExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestAllExtensions result = new TestAllExtensions(); + bool builderIsReadOnly; + TestAllExtensions result; + + private TestAllExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestAllExtensions original = result; + result = new TestAllExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestAllExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestAllExtensions(); + result = DefaultInstance ?? new TestAllExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6096,12 +6501,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestAllExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestAllExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6115,6 +6519,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestAllExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllExtensions.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -6125,6 +6530,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6275,7 +6681,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OptionalGroup_extension prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6285,21 +6691,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OptionalGroup_extension(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OptionalGroup_extension cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - OptionalGroup_extension result = new OptionalGroup_extension(); + bool builderIsReadOnly; + OptionalGroup_extension result; + + private OptionalGroup_extension PrepareBuilder() { + if (builderIsReadOnly) { + OptionalGroup_extension original = result; + result = new OptionalGroup_extension(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OptionalGroup_extension MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OptionalGroup_extension(); + result = DefaultInstance ?? new OptionalGroup_extension(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6311,12 +6744,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OptionalGroup_extension BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OptionalGroup_extension returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6330,6 +6762,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OptionalGroup_extension other) { if (other == global::Google.ProtocolBuffers.TestProtos.OptionalGroup_extension.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -6342,6 +6775,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6397,11 +6831,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -6514,7 +6950,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(RepeatedGroup_extension prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6524,21 +6960,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new RepeatedGroup_extension(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(RepeatedGroup_extension cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + RepeatedGroup_extension result; + + private RepeatedGroup_extension PrepareBuilder() { + if (builderIsReadOnly) { + RepeatedGroup_extension original = result; + result = new RepeatedGroup_extension(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - RepeatedGroup_extension result = new RepeatedGroup_extension(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override RepeatedGroup_extension MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new RepeatedGroup_extension(); + result = DefaultInstance ?? new RepeatedGroup_extension(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6550,12 +7013,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override RepeatedGroup_extension BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - RepeatedGroup_extension returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6569,6 +7031,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(RepeatedGroup_extension other) { if (other == global::Google.ProtocolBuffers.TestProtos.RepeatedGroup_extension.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -6581,6 +7044,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6636,11 +7100,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -6739,7 +7205,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestNestedExtension prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6749,21 +7215,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestNestedExtension(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestNestedExtension cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestNestedExtension result; + + private TestNestedExtension PrepareBuilder() { + if (builderIsReadOnly) { + TestNestedExtension original = result; + result = new TestNestedExtension(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestNestedExtension result = new TestNestedExtension(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestNestedExtension MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestNestedExtension(); + result = DefaultInstance ?? new TestNestedExtension(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6775,12 +7268,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestNestedExtension BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestNestedExtension returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6794,6 +7286,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestNestedExtension other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestNestedExtension.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -6803,6 +7296,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -7472,7 +7966,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRequired prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -7482,21 +7976,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRequired(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRequired cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestRequired result = new TestRequired(); + bool builderIsReadOnly; + TestRequired result; + + private TestRequired PrepareBuilder() { + if (builderIsReadOnly) { + TestRequired original = result; + result = new TestRequired(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRequired MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRequired(); + result = DefaultInstance ?? new TestRequired(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -7508,12 +8029,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRequired BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestRequired returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -7527,6 +8047,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestRequired other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestRequired.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -7635,6 +8156,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -7818,11 +8340,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -7836,11 +8360,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy2(value); } } public Builder SetDummy2(int value) { + PrepareBuilder(); result.hasDummy2 = true; result.dummy2_ = value; return this; } public Builder ClearDummy2() { + PrepareBuilder(); result.hasDummy2 = false; result.dummy2_ = 0; return this; @@ -7854,11 +8380,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetB(value); } } public Builder SetB(int value) { + PrepareBuilder(); result.hasB = true; result.b_ = value; return this; } public Builder ClearB() { + PrepareBuilder(); result.hasB = false; result.b_ = 0; return this; @@ -7872,11 +8400,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy4(value); } } public Builder SetDummy4(int value) { + PrepareBuilder(); result.hasDummy4 = true; result.dummy4_ = value; return this; } public Builder ClearDummy4() { + PrepareBuilder(); result.hasDummy4 = false; result.dummy4_ = 0; return this; @@ -7890,11 +8420,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy5(value); } } public Builder SetDummy5(int value) { + PrepareBuilder(); result.hasDummy5 = true; result.dummy5_ = value; return this; } public Builder ClearDummy5() { + PrepareBuilder(); result.hasDummy5 = false; result.dummy5_ = 0; return this; @@ -7908,11 +8440,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy6(value); } } public Builder SetDummy6(int value) { + PrepareBuilder(); result.hasDummy6 = true; result.dummy6_ = value; return this; } public Builder ClearDummy6() { + PrepareBuilder(); result.hasDummy6 = false; result.dummy6_ = 0; return this; @@ -7926,11 +8460,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy7(value); } } public Builder SetDummy7(int value) { + PrepareBuilder(); result.hasDummy7 = true; result.dummy7_ = value; return this; } public Builder ClearDummy7() { + PrepareBuilder(); result.hasDummy7 = false; result.dummy7_ = 0; return this; @@ -7944,11 +8480,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy8(value); } } public Builder SetDummy8(int value) { + PrepareBuilder(); result.hasDummy8 = true; result.dummy8_ = value; return this; } public Builder ClearDummy8() { + PrepareBuilder(); result.hasDummy8 = false; result.dummy8_ = 0; return this; @@ -7962,11 +8500,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy9(value); } } public Builder SetDummy9(int value) { + PrepareBuilder(); result.hasDummy9 = true; result.dummy9_ = value; return this; } public Builder ClearDummy9() { + PrepareBuilder(); result.hasDummy9 = false; result.dummy9_ = 0; return this; @@ -7980,11 +8520,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy10(value); } } public Builder SetDummy10(int value) { + PrepareBuilder(); result.hasDummy10 = true; result.dummy10_ = value; return this; } public Builder ClearDummy10() { + PrepareBuilder(); result.hasDummy10 = false; result.dummy10_ = 0; return this; @@ -7998,11 +8540,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy11(value); } } public Builder SetDummy11(int value) { + PrepareBuilder(); result.hasDummy11 = true; result.dummy11_ = value; return this; } public Builder ClearDummy11() { + PrepareBuilder(); result.hasDummy11 = false; result.dummy11_ = 0; return this; @@ -8016,11 +8560,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy12(value); } } public Builder SetDummy12(int value) { + PrepareBuilder(); result.hasDummy12 = true; result.dummy12_ = value; return this; } public Builder ClearDummy12() { + PrepareBuilder(); result.hasDummy12 = false; result.dummy12_ = 0; return this; @@ -8034,11 +8580,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy13(value); } } public Builder SetDummy13(int value) { + PrepareBuilder(); result.hasDummy13 = true; result.dummy13_ = value; return this; } public Builder ClearDummy13() { + PrepareBuilder(); result.hasDummy13 = false; result.dummy13_ = 0; return this; @@ -8052,11 +8600,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy14(value); } } public Builder SetDummy14(int value) { + PrepareBuilder(); result.hasDummy14 = true; result.dummy14_ = value; return this; } public Builder ClearDummy14() { + PrepareBuilder(); result.hasDummy14 = false; result.dummy14_ = 0; return this; @@ -8070,11 +8620,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy15(value); } } public Builder SetDummy15(int value) { + PrepareBuilder(); result.hasDummy15 = true; result.dummy15_ = value; return this; } public Builder ClearDummy15() { + PrepareBuilder(); result.hasDummy15 = false; result.dummy15_ = 0; return this; @@ -8088,11 +8640,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy16(value); } } public Builder SetDummy16(int value) { + PrepareBuilder(); result.hasDummy16 = true; result.dummy16_ = value; return this; } public Builder ClearDummy16() { + PrepareBuilder(); result.hasDummy16 = false; result.dummy16_ = 0; return this; @@ -8106,11 +8660,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy17(value); } } public Builder SetDummy17(int value) { + PrepareBuilder(); result.hasDummy17 = true; result.dummy17_ = value; return this; } public Builder ClearDummy17() { + PrepareBuilder(); result.hasDummy17 = false; result.dummy17_ = 0; return this; @@ -8124,11 +8680,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy18(value); } } public Builder SetDummy18(int value) { + PrepareBuilder(); result.hasDummy18 = true; result.dummy18_ = value; return this; } public Builder ClearDummy18() { + PrepareBuilder(); result.hasDummy18 = false; result.dummy18_ = 0; return this; @@ -8142,11 +8700,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy19(value); } } public Builder SetDummy19(int value) { + PrepareBuilder(); result.hasDummy19 = true; result.dummy19_ = value; return this; } public Builder ClearDummy19() { + PrepareBuilder(); result.hasDummy19 = false; result.dummy19_ = 0; return this; @@ -8160,11 +8720,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy20(value); } } public Builder SetDummy20(int value) { + PrepareBuilder(); result.hasDummy20 = true; result.dummy20_ = value; return this; } public Builder ClearDummy20() { + PrepareBuilder(); result.hasDummy20 = false; result.dummy20_ = 0; return this; @@ -8178,11 +8740,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy21(value); } } public Builder SetDummy21(int value) { + PrepareBuilder(); result.hasDummy21 = true; result.dummy21_ = value; return this; } public Builder ClearDummy21() { + PrepareBuilder(); result.hasDummy21 = false; result.dummy21_ = 0; return this; @@ -8196,11 +8760,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy22(value); } } public Builder SetDummy22(int value) { + PrepareBuilder(); result.hasDummy22 = true; result.dummy22_ = value; return this; } public Builder ClearDummy22() { + PrepareBuilder(); result.hasDummy22 = false; result.dummy22_ = 0; return this; @@ -8214,11 +8780,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy23(value); } } public Builder SetDummy23(int value) { + PrepareBuilder(); result.hasDummy23 = true; result.dummy23_ = value; return this; } public Builder ClearDummy23() { + PrepareBuilder(); result.hasDummy23 = false; result.dummy23_ = 0; return this; @@ -8232,11 +8800,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy24(value); } } public Builder SetDummy24(int value) { + PrepareBuilder(); result.hasDummy24 = true; result.dummy24_ = value; return this; } public Builder ClearDummy24() { + PrepareBuilder(); result.hasDummy24 = false; result.dummy24_ = 0; return this; @@ -8250,11 +8820,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy25(value); } } public Builder SetDummy25(int value) { + PrepareBuilder(); result.hasDummy25 = true; result.dummy25_ = value; return this; } public Builder ClearDummy25() { + PrepareBuilder(); result.hasDummy25 = false; result.dummy25_ = 0; return this; @@ -8268,11 +8840,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy26(value); } } public Builder SetDummy26(int value) { + PrepareBuilder(); result.hasDummy26 = true; result.dummy26_ = value; return this; } public Builder ClearDummy26() { + PrepareBuilder(); result.hasDummy26 = false; result.dummy26_ = 0; return this; @@ -8286,11 +8860,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy27(value); } } public Builder SetDummy27(int value) { + PrepareBuilder(); result.hasDummy27 = true; result.dummy27_ = value; return this; } public Builder ClearDummy27() { + PrepareBuilder(); result.hasDummy27 = false; result.dummy27_ = 0; return this; @@ -8304,11 +8880,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy28(value); } } public Builder SetDummy28(int value) { + PrepareBuilder(); result.hasDummy28 = true; result.dummy28_ = value; return this; } public Builder ClearDummy28() { + PrepareBuilder(); result.hasDummy28 = false; result.dummy28_ = 0; return this; @@ -8322,11 +8900,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy29(value); } } public Builder SetDummy29(int value) { + PrepareBuilder(); result.hasDummy29 = true; result.dummy29_ = value; return this; } public Builder ClearDummy29() { + PrepareBuilder(); result.hasDummy29 = false; result.dummy29_ = 0; return this; @@ -8340,11 +8920,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy30(value); } } public Builder SetDummy30(int value) { + PrepareBuilder(); result.hasDummy30 = true; result.dummy30_ = value; return this; } public Builder ClearDummy30() { + PrepareBuilder(); result.hasDummy30 = false; result.dummy30_ = 0; return this; @@ -8358,11 +8940,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy31(value); } } public Builder SetDummy31(int value) { + PrepareBuilder(); result.hasDummy31 = true; result.dummy31_ = value; return this; } public Builder ClearDummy31() { + PrepareBuilder(); result.hasDummy31 = false; result.dummy31_ = 0; return this; @@ -8376,11 +8960,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy32(value); } } public Builder SetDummy32(int value) { + PrepareBuilder(); result.hasDummy32 = true; result.dummy32_ = value; return this; } public Builder ClearDummy32() { + PrepareBuilder(); result.hasDummy32 = false; result.dummy32_ = 0; return this; @@ -8394,11 +8980,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetC(value); } } public Builder SetC(int value) { + PrepareBuilder(); result.hasC = true; result.c_ = value; return this; } public Builder ClearC() { + PrepareBuilder(); result.hasC = false; result.c_ = 0; return this; @@ -8551,7 +9139,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRequiredForeign prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -8561,21 +9149,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRequiredForeign(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRequiredForeign cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestRequiredForeign result; - TestRequiredForeign result = new TestRequiredForeign(); + private TestRequiredForeign PrepareBuilder() { + if (builderIsReadOnly) { + TestRequiredForeign original = result; + result = new TestRequiredForeign(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRequiredForeign MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRequiredForeign(); + result = DefaultInstance ?? new TestRequiredForeign(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -8587,13 +9202,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRequiredForeign BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedMessage_.MakeReadOnly(); - TestRequiredForeign returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -8607,6 +9221,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestRequiredForeign other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestRequiredForeign.DefaultInstance) return this; + PrepareBuilder(); if (other.HasOptionalMessage) { MergeOptionalMessage(other.OptionalMessage); } @@ -8625,6 +9240,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -8694,18 +9310,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalMessage = true; result.optionalMessage_ = value; return this; } public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalMessage = true; result.optionalMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalMessage && result.optionalMessage_ != global::Google.ProtocolBuffers.TestProtos.TestRequired.DefaultInstance) { result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestRequired.CreateBuilder(result.optionalMessage_).MergeFrom(value).BuildPartial(); @@ -8716,13 +9335,14 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalMessage() { + PrepareBuilder(); result.hasOptionalMessage = false; result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestRequired.DefaultInstance; return this; } public pbc::IPopsicleList RepeatedMessageList { - get { return result.repeatedMessage_; } + get { return PrepareBuilder().repeatedMessage_; } } public int RepeatedMessageCount { get { return result.RepeatedMessageCount; } @@ -8732,29 +9352,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestRequired value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessage_[index] = value; return this; } public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestRequired.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessage_.Add(value); return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedMessage_); return this; } public Builder ClearRepeatedMessage() { + PrepareBuilder(); result.repeatedMessage_.Clear(); return this; } @@ -8767,11 +9393,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy(value); } } public Builder SetDummy(int value) { + PrepareBuilder(); result.hasDummy = true; result.dummy_ = value; return this; } public Builder ClearDummy() { + PrepareBuilder(); result.hasDummy = false; result.dummy_ = 0; return this; @@ -8884,7 +9512,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestForeignNested prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -8894,21 +9522,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestForeignNested(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestForeignNested cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestForeignNested result = new TestForeignNested(); + bool builderIsReadOnly; + TestForeignNested result; + + private TestForeignNested PrepareBuilder() { + if (builderIsReadOnly) { + TestForeignNested original = result; + result = new TestForeignNested(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestForeignNested MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestForeignNested(); + result = DefaultInstance ?? new TestForeignNested(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -8920,12 +9575,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestForeignNested BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestForeignNested returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -8939,6 +9593,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestForeignNested other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestForeignNested.DefaultInstance) return this; + PrepareBuilder(); if (other.HasForeignNested) { MergeForeignNested(other.ForeignNested); } @@ -8951,6 +9606,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9012,18 +9668,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetForeignNested(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasForeignNested = true; result.foreignNested_ = value; return this; } public Builder SetForeignNested(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasForeignNested = true; result.foreignNested_ = builderForValue.Build(); return this; } public Builder MergeForeignNested(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasForeignNested && result.foreignNested_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance) { result.foreignNested_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.CreateBuilder(result.foreignNested_).MergeFrom(value).BuildPartial(); @@ -9034,6 +9693,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearForeignNested() { + PrepareBuilder(); result.hasForeignNested = false; result.foreignNested_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance; return this; @@ -9130,7 +9790,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestEmptyMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9140,21 +9800,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestEmptyMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestEmptyMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestEmptyMessage result; + + private TestEmptyMessage PrepareBuilder() { + if (builderIsReadOnly) { + TestEmptyMessage original = result; + result = new TestEmptyMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestEmptyMessage result = new TestEmptyMessage(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestEmptyMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestEmptyMessage(); + result = DefaultInstance ?? new TestEmptyMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -9166,12 +9853,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestEmptyMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestEmptyMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -9185,6 +9871,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestEmptyMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestEmptyMessage.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -9194,6 +9881,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9332,7 +10020,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestEmptyMessageWithExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9342,21 +10030,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestEmptyMessageWithExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestEmptyMessageWithExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestEmptyMessageWithExtensions result = new TestEmptyMessageWithExtensions(); + bool builderIsReadOnly; + TestEmptyMessageWithExtensions result; + + private TestEmptyMessageWithExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestEmptyMessageWithExtensions original = result; + result = new TestEmptyMessageWithExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestEmptyMessageWithExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestEmptyMessageWithExtensions(); + result = DefaultInstance ?? new TestEmptyMessageWithExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -9368,12 +10083,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestEmptyMessageWithExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestEmptyMessageWithExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -9387,6 +10101,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestEmptyMessageWithExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestEmptyMessageWithExtensions.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -9397,6 +10112,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9537,7 +10253,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMultipleExtensionRanges prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9547,21 +10263,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMultipleExtensionRanges(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMultipleExtensionRanges cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestMultipleExtensionRanges result; + + private TestMultipleExtensionRanges PrepareBuilder() { + if (builderIsReadOnly) { + TestMultipleExtensionRanges original = result; + result = new TestMultipleExtensionRanges(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestMultipleExtensionRanges result = new TestMultipleExtensionRanges(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMultipleExtensionRanges MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMultipleExtensionRanges(); + result = DefaultInstance ?? new TestMultipleExtensionRanges(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -9573,12 +10316,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMultipleExtensionRanges BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMultipleExtensionRanges returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -9592,6 +10334,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMultipleExtensionRanges other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMultipleExtensionRanges.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -9602,6 +10345,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9768,7 +10512,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestReallyLargeTagNumber prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9778,21 +10522,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestReallyLargeTagNumber(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestReallyLargeTagNumber cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestReallyLargeTagNumber result; + + private TestReallyLargeTagNumber PrepareBuilder() { + if (builderIsReadOnly) { + TestReallyLargeTagNumber original = result; + result = new TestReallyLargeTagNumber(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestReallyLargeTagNumber result = new TestReallyLargeTagNumber(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestReallyLargeTagNumber MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestReallyLargeTagNumber(); + result = DefaultInstance ?? new TestReallyLargeTagNumber(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -9804,12 +10575,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestReallyLargeTagNumber BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestReallyLargeTagNumber returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -9823,6 +10593,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestReallyLargeTagNumber other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestReallyLargeTagNumber.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -9838,6 +10609,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9897,11 +10669,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -9915,11 +10689,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetBb(value); } } public Builder SetBb(int value) { + PrepareBuilder(); result.hasBb = true; result.bb_ = value; return this; } public Builder ClearBb() { + PrepareBuilder(); result.hasBb = false; result.bb_ = 0; return this; @@ -10048,7 +10824,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRecursiveMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -10058,21 +10834,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRecursiveMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRecursiveMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestRecursiveMessage result = new TestRecursiveMessage(); + bool builderIsReadOnly; + TestRecursiveMessage result; + + private TestRecursiveMessage PrepareBuilder() { + if (builderIsReadOnly) { + TestRecursiveMessage original = result; + result = new TestRecursiveMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRecursiveMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRecursiveMessage(); + result = DefaultInstance ?? new TestRecursiveMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -10084,12 +10887,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRecursiveMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestRecursiveMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -10103,6 +10905,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestRecursiveMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { MergeA(other.A); } @@ -10118,6 +10921,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -10183,18 +10987,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetA(global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder SetA(global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasA = true; result.a_ = builderForValue.Build(); return this; } public Builder MergeA(global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasA && result.a_ != global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.DefaultInstance) { result.a_ = global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.CreateBuilder(result.a_).MergeFrom(value).BuildPartial(); @@ -10205,6 +11012,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.DefaultInstance; return this; @@ -10218,11 +11026,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetI(value); } } public Builder SetI(int value) { + PrepareBuilder(); result.hasI = true; result.i_ = value; return this; } public Builder ClearI() { + PrepareBuilder(); result.hasI = false; result.i_ = 0; return this; @@ -10335,7 +11145,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMutualRecursionA prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -10345,21 +11155,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMutualRecursionA(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMutualRecursionA cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestMutualRecursionA result; + + private TestMutualRecursionA PrepareBuilder() { + if (builderIsReadOnly) { + TestMutualRecursionA original = result; + result = new TestMutualRecursionA(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestMutualRecursionA result = new TestMutualRecursionA(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMutualRecursionA MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMutualRecursionA(); + result = DefaultInstance ?? new TestMutualRecursionA(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -10371,12 +11208,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMutualRecursionA BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMutualRecursionA returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -10390,6 +11226,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMutualRecursionA other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.DefaultInstance) return this; + PrepareBuilder(); if (other.HasBb) { MergeBb(other.Bb); } @@ -10402,6 +11239,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -10463,18 +11301,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetBb(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasBb = true; result.bb_ = value; return this; } public Builder SetBb(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasBb = true; result.bb_ = builderForValue.Build(); return this; } public Builder MergeBb(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasBb && result.bb_ != global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.DefaultInstance) { result.bb_ = global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.CreateBuilder(result.bb_).MergeFrom(value).BuildPartial(); @@ -10485,6 +11326,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearBb() { + PrepareBuilder(); result.hasBb = false; result.bb_ = global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.DefaultInstance; return this; @@ -10613,7 +11455,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMutualRecursionB prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -10623,21 +11465,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMutualRecursionB(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMutualRecursionB cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestMutualRecursionB result = new TestMutualRecursionB(); + bool builderIsReadOnly; + TestMutualRecursionB result; + + private TestMutualRecursionB PrepareBuilder() { + if (builderIsReadOnly) { + TestMutualRecursionB original = result; + result = new TestMutualRecursionB(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMutualRecursionB MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMutualRecursionB(); + result = DefaultInstance ?? new TestMutualRecursionB(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -10649,12 +11518,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMutualRecursionB BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMutualRecursionB returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -10668,6 +11536,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMutualRecursionB other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { MergeA(other.A); } @@ -10683,6 +11552,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -10748,18 +11618,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetA(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder SetA(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasA = true; result.a_ = builderForValue.Build(); return this; } public Builder MergeA(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasA && result.a_ != global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.DefaultInstance) { result.a_ = global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.CreateBuilder(result.a_).MergeFrom(value).BuildPartial(); @@ -10770,6 +11643,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.DefaultInstance; return this; @@ -10783,11 +11657,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalInt32(value); } } public Builder SetOptionalInt32(int value) { + PrepareBuilder(); result.hasOptionalInt32 = true; result.optionalInt32_ = value; return this; } public Builder ClearOptionalInt32() { + PrepareBuilder(); result.hasOptionalInt32 = false; result.optionalInt32_ = 0; return this; @@ -10932,7 +11808,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Foo prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -10942,21 +11818,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Foo(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Foo cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + Foo result; - Foo result = new Foo(); + private Foo PrepareBuilder() { + if (builderIsReadOnly) { + Foo original = result; + result = new Foo(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Foo MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Foo(); + result = DefaultInstance ?? new Foo(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -10968,12 +11871,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Foo BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - Foo returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -10987,6 +11889,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(Foo other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -10999,6 +11902,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -11054,11 +11958,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -11171,7 +12077,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Bar prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -11181,21 +12087,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Bar(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Bar cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - Bar result = new Bar(); + bool builderIsReadOnly; + Bar result; + + private Bar PrepareBuilder() { + if (builderIsReadOnly) { + Bar original = result; + result = new Bar(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Bar MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Bar(); + result = DefaultInstance ?? new Bar(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -11207,12 +12140,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Bar BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - Bar returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -11226,6 +12158,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(Bar other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -11238,6 +12171,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -11293,11 +12227,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -11418,7 +12354,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestDupFieldNumber prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -11428,21 +12364,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestDupFieldNumber(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestDupFieldNumber cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestDupFieldNumber result = new TestDupFieldNumber(); + bool builderIsReadOnly; + TestDupFieldNumber result; + + private TestDupFieldNumber PrepareBuilder() { + if (builderIsReadOnly) { + TestDupFieldNumber original = result; + result = new TestDupFieldNumber(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestDupFieldNumber MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestDupFieldNumber(); + result = DefaultInstance ?? new TestDupFieldNumber(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -11454,12 +12417,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestDupFieldNumber BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestDupFieldNumber returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -11473,6 +12435,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestDupFieldNumber other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -11491,6 +12454,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -11564,11 +12528,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -11583,18 +12549,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetFoo(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasFoo = true; result.foo_ = value; return this; } public Builder SetFoo(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasFoo = true; result.foo_ = builderForValue.Build(); return this; } public Builder MergeFoo(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasFoo && result.foo_ != global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.DefaultInstance) { result.foo_ = global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.CreateBuilder(result.foo_).MergeFrom(value).BuildPartial(); @@ -11605,6 +12574,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearFoo() { + PrepareBuilder(); result.hasFoo = false; result.foo_ = global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.DefaultInstance; return this; @@ -11619,18 +12589,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetBar(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasBar = true; result.bar_ = value; return this; } public Builder SetBar(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasBar = true; result.bar_ = builderForValue.Build(); return this; } public Builder MergeBar(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasBar && result.bar_ != global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.DefaultInstance) { result.bar_ = global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.CreateBuilder(result.bar_).MergeFrom(value).BuildPartial(); @@ -11641,6 +12614,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearBar() { + PrepareBuilder(); result.hasBar = false; result.bar_ = global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.DefaultInstance; return this; @@ -11810,7 +12784,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(NestedMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -11820,21 +12794,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(NestedMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + NestedMessage result; + + private NestedMessage PrepareBuilder() { + if (builderIsReadOnly) { + NestedMessage original = result; + result = new NestedMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - NestedMessage result = new NestedMessage(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override NestedMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new NestedMessage(); + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -11846,14 +12847,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public override NestedMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.nestedmessageRepeatedInt32_.MakeReadOnly(); result.nestedmessageRepeatedForeignmessage_.MakeReadOnly(); - NestedMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -11867,6 +12867,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(NestedMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.nestedmessageRepeatedInt32_.Count != 0) { base.AddRange(other.nestedmessageRepeatedInt32_, result.nestedmessageRepeatedInt32_); } @@ -11882,6 +12883,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -11935,7 +12937,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList NestedmessageRepeatedInt32List { - get { return result.nestedmessageRepeatedInt32_; } + get { return PrepareBuilder().nestedmessageRepeatedInt32_; } } public int NestedmessageRepeatedInt32Count { get { return result.NestedmessageRepeatedInt32Count; } @@ -11944,24 +12946,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetNestedmessageRepeatedInt32(index); } public Builder SetNestedmessageRepeatedInt32(int index, int value) { + PrepareBuilder(); result.nestedmessageRepeatedInt32_[index] = value; return this; } public Builder AddNestedmessageRepeatedInt32(int value) { + PrepareBuilder(); result.nestedmessageRepeatedInt32_.Add(value); return this; } public Builder AddRangeNestedmessageRepeatedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.nestedmessageRepeatedInt32_); return this; } public Builder ClearNestedmessageRepeatedInt32() { + PrepareBuilder(); result.nestedmessageRepeatedInt32_.Clear(); return this; } public pbc::IPopsicleList NestedmessageRepeatedForeignmessageList { - get { return result.nestedmessageRepeatedForeignmessage_; } + get { return PrepareBuilder().nestedmessageRepeatedForeignmessage_; } } public int NestedmessageRepeatedForeignmessageCount { get { return result.NestedmessageRepeatedForeignmessageCount; } @@ -11971,29 +12977,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetNestedmessageRepeatedForeignmessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_[index] = value; return this; } public Builder SetNestedmessageRepeatedForeignmessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_[index] = builderForValue.Build(); return this; } public Builder AddNestedmessageRepeatedForeignmessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_.Add(value); return this; } public Builder AddNestedmessageRepeatedForeignmessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeNestedmessageRepeatedForeignmessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.nestedmessageRepeatedForeignmessage_); return this; } public Builder ClearNestedmessageRepeatedForeignmessage() { + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_.Clear(); return this; } @@ -12081,7 +13093,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestNestedMessageHasBits prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -12091,21 +13103,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestNestedMessageHasBits(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestNestedMessageHasBits cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestNestedMessageHasBits result = new TestNestedMessageHasBits(); + bool builderIsReadOnly; + TestNestedMessageHasBits result; + + private TestNestedMessageHasBits PrepareBuilder() { + if (builderIsReadOnly) { + TestNestedMessageHasBits original = result; + result = new TestNestedMessageHasBits(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestNestedMessageHasBits MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestNestedMessageHasBits(); + result = DefaultInstance ?? new TestNestedMessageHasBits(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -12117,12 +13156,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestNestedMessageHasBits BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestNestedMessageHasBits returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -12136,6 +13174,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestNestedMessageHasBits other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.DefaultInstance) return this; + PrepareBuilder(); if (other.HasOptionalNestedMessage) { MergeOptionalNestedMessage(other.OptionalNestedMessage); } @@ -12148,6 +13187,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -12209,18 +13249,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = value; return this; } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalNestedMessage && result.optionalNestedMessage_ != global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.DefaultInstance) { result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.CreateBuilder(result.optionalNestedMessage_).MergeFrom(value).BuildPartial(); @@ -12231,6 +13274,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalNestedMessage() { + PrepareBuilder(); result.hasOptionalNestedMessage = false; result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.DefaultInstance; return this; @@ -12558,7 +13602,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestCamelCaseFieldNames prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -12568,21 +13612,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestCamelCaseFieldNames(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestCamelCaseFieldNames cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestCamelCaseFieldNames result; + + private TestCamelCaseFieldNames PrepareBuilder() { + if (builderIsReadOnly) { + TestCamelCaseFieldNames original = result; + result = new TestCamelCaseFieldNames(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestCamelCaseFieldNames result = new TestCamelCaseFieldNames(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestCamelCaseFieldNames MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestCamelCaseFieldNames(); + result = DefaultInstance ?? new TestCamelCaseFieldNames(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -12594,8 +13665,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestCamelCaseFieldNames BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedPrimitiveField_.MakeReadOnly(); result.repeatedStringField_.MakeReadOnly(); @@ -12603,9 +13674,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.repeatedMessageField_.MakeReadOnly(); result.repeatedStringPieceField_.MakeReadOnly(); result.repeatedCordField_.MakeReadOnly(); - TestCamelCaseFieldNames returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -12619,6 +13689,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestCamelCaseFieldNames other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestCamelCaseFieldNames.DefaultInstance) return this; + PrepareBuilder(); if (other.HasPrimitiveField) { PrimitiveField = other.PrimitiveField; } @@ -12664,6 +13735,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -12787,11 +13859,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetPrimitiveField(value); } } public Builder SetPrimitiveField(int value) { + PrepareBuilder(); result.hasPrimitiveField = true; result.primitiveField_ = value; return this; } public Builder ClearPrimitiveField() { + PrepareBuilder(); result.hasPrimitiveField = false; result.primitiveField_ = 0; return this; @@ -12806,11 +13880,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetStringField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasStringField = true; result.stringField_ = value; return this; } public Builder ClearStringField() { + PrepareBuilder(); result.hasStringField = false; result.stringField_ = ""; return this; @@ -12824,11 +13900,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetEnumField(value); } } public Builder SetEnumField(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.hasEnumField = true; result.enumField_ = value; return this; } public Builder ClearEnumField() { + PrepareBuilder(); result.hasEnumField = false; result.enumField_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnum.FOREIGN_FOO; return this; @@ -12843,18 +13921,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMessageField = true; result.messageField_ = value; return this; } public Builder SetMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasMessageField = true; result.messageField_ = builderForValue.Build(); return this; } public Builder MergeMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasMessageField && result.messageField_ != global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) { result.messageField_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.CreateBuilder(result.messageField_).MergeFrom(value).BuildPartial(); @@ -12865,6 +13946,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearMessageField() { + PrepareBuilder(); result.hasMessageField = false; result.messageField_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance; return this; @@ -12879,11 +13961,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetStringPieceField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasStringPieceField = true; result.stringPieceField_ = value; return this; } public Builder ClearStringPieceField() { + PrepareBuilder(); result.hasStringPieceField = false; result.stringPieceField_ = ""; return this; @@ -12898,18 +13982,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetCordField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasCordField = true; result.cordField_ = value; return this; } public Builder ClearCordField() { + PrepareBuilder(); result.hasCordField = false; result.cordField_ = ""; return this; } public pbc::IPopsicleList RepeatedPrimitiveFieldList { - get { return result.repeatedPrimitiveField_; } + get { return PrepareBuilder().repeatedPrimitiveField_; } } public int RepeatedPrimitiveFieldCount { get { return result.RepeatedPrimitiveFieldCount; } @@ -12918,24 +14004,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedPrimitiveField(index); } public Builder SetRepeatedPrimitiveField(int index, int value) { + PrepareBuilder(); result.repeatedPrimitiveField_[index] = value; return this; } public Builder AddRepeatedPrimitiveField(int value) { + PrepareBuilder(); result.repeatedPrimitiveField_.Add(value); return this; } public Builder AddRangeRepeatedPrimitiveField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedPrimitiveField_); return this; } public Builder ClearRepeatedPrimitiveField() { + PrepareBuilder(); result.repeatedPrimitiveField_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringFieldList { - get { return result.repeatedStringField_; } + get { return PrepareBuilder().repeatedStringField_; } } public int RepeatedStringFieldCount { get { return result.RepeatedStringFieldCount; } @@ -12945,25 +14035,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedStringField(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringField_[index] = value; return this; } public Builder AddRepeatedStringField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringField_.Add(value); return this; } public Builder AddRangeRepeatedStringField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedStringField_); return this; } public Builder ClearRepeatedStringField() { + PrepareBuilder(); result.repeatedStringField_.Clear(); return this; } public pbc::IPopsicleList RepeatedEnumFieldList { - get { return result.repeatedEnumField_; } + get { return PrepareBuilder().repeatedEnumField_; } } public int RepeatedEnumFieldCount { get { return result.RepeatedEnumFieldCount; } @@ -12972,24 +14066,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedEnumField(index); } public Builder SetRepeatedEnumField(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.repeatedEnumField_[index] = value; return this; } public Builder AddRepeatedEnumField(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.repeatedEnumField_.Add(value); return this; } public Builder AddRangeRepeatedEnumField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedEnumField_); return this; } public Builder ClearRepeatedEnumField() { + PrepareBuilder(); result.repeatedEnumField_.Clear(); return this; } public pbc::IPopsicleList RepeatedMessageFieldList { - get { return result.repeatedMessageField_; } + get { return PrepareBuilder().repeatedMessageField_; } } public int RepeatedMessageFieldCount { get { return result.RepeatedMessageFieldCount; } @@ -12999,35 +14097,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedMessageField(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessageField_[index] = value; return this; } public Builder SetRepeatedMessageField(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessageField_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessageField_.Add(value); return this; } public Builder AddRepeatedMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessageField_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedMessageField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedMessageField_); return this; } public Builder ClearRepeatedMessageField() { + PrepareBuilder(); result.repeatedMessageField_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringPieceFieldList { - get { return result.repeatedStringPieceField_; } + get { return PrepareBuilder().repeatedStringPieceField_; } } public int RepeatedStringPieceFieldCount { get { return result.RepeatedStringPieceFieldCount; } @@ -13037,25 +14141,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedStringPieceField(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPieceField_[index] = value; return this; } public Builder AddRepeatedStringPieceField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPieceField_.Add(value); return this; } public Builder AddRangeRepeatedStringPieceField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedStringPieceField_); return this; } public Builder ClearRepeatedStringPieceField() { + PrepareBuilder(); result.repeatedStringPieceField_.Clear(); return this; } public pbc::IPopsicleList RepeatedCordFieldList { - get { return result.repeatedCordField_; } + get { return PrepareBuilder().repeatedCordField_; } } public int RepeatedCordFieldCount { get { return result.RepeatedCordFieldCount; } @@ -13065,19 +14173,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedCordField(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCordField_[index] = value; return this; } public Builder AddRepeatedCordField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCordField_.Add(value); return this; } public Builder AddRangeRepeatedCordField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedCordField_); return this; } public Builder ClearRepeatedCordField() { + PrepareBuilder(); result.repeatedCordField_.Clear(); return this; } @@ -13226,7 +14338,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestFieldOrderings prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -13236,21 +14348,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestFieldOrderings(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestFieldOrderings cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestFieldOrderings result; + + private TestFieldOrderings PrepareBuilder() { + if (builderIsReadOnly) { + TestFieldOrderings original = result; + result = new TestFieldOrderings(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestFieldOrderings result = new TestFieldOrderings(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestFieldOrderings MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestFieldOrderings(); + result = DefaultInstance ?? new TestFieldOrderings(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -13262,12 +14401,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestFieldOrderings BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestFieldOrderings returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -13281,6 +14419,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestFieldOrderings other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestFieldOrderings.DefaultInstance) return this; + PrepareBuilder(); if (other.HasMyString) { MyString = other.MyString; } @@ -13300,6 +14439,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -13364,11 +14504,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMyString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMyString = true; result.myString_ = value; return this; } public Builder ClearMyString() { + PrepareBuilder(); result.hasMyString = false; result.myString_ = ""; return this; @@ -13382,11 +14524,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetMyInt(value); } } public Builder SetMyInt(long value) { + PrepareBuilder(); result.hasMyInt = true; result.myInt_ = value; return this; } public Builder ClearMyInt() { + PrepareBuilder(); result.hasMyInt = false; result.myInt_ = 0L; return this; @@ -13400,11 +14544,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetMyFloat(value); } } public Builder SetMyFloat(float value) { + PrepareBuilder(); result.hasMyFloat = true; result.myFloat_ = value; return this; } public Builder ClearMyFloat() { + PrepareBuilder(); result.hasMyFloat = false; result.myFloat_ = 0F; return this; @@ -13807,7 +14953,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestExtremeDefaultValues prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -13817,21 +14963,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestExtremeDefaultValues(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestExtremeDefaultValues cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestExtremeDefaultValues result; - TestExtremeDefaultValues result = new TestExtremeDefaultValues(); + private TestExtremeDefaultValues PrepareBuilder() { + if (builderIsReadOnly) { + TestExtremeDefaultValues original = result; + result = new TestExtremeDefaultValues(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestExtremeDefaultValues MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestExtremeDefaultValues(); + result = DefaultInstance ?? new TestExtremeDefaultValues(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -13843,12 +15016,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestExtremeDefaultValues BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestExtremeDefaultValues returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -13862,6 +15034,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestExtremeDefaultValues other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestExtremeDefaultValues.DefaultInstance) return this; + PrepareBuilder(); if (other.HasEscapedBytes) { EscapedBytes = other.EscapedBytes; } @@ -13928,6 +15101,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -14056,11 +15230,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetEscapedBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasEscapedBytes = true; result.escapedBytes_ = value; return this; } public Builder ClearEscapedBytes() { + PrepareBuilder(); result.hasEscapedBytes = false; result.escapedBytes_ = (pb::ByteString) global::Google.ProtocolBuffers.TestProtos.TestExtremeDefaultValues.Descriptor.Fields[0].DefaultValue; return this; @@ -14076,11 +15252,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetLargeUint32(uint value) { + PrepareBuilder(); result.hasLargeUint32 = true; result.largeUint32_ = value; return this; } public Builder ClearLargeUint32() { + PrepareBuilder(); result.hasLargeUint32 = false; result.largeUint32_ = 4294967295; return this; @@ -14096,11 +15274,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetLargeUint64(ulong value) { + PrepareBuilder(); result.hasLargeUint64 = true; result.largeUint64_ = value; return this; } public Builder ClearLargeUint64() { + PrepareBuilder(); result.hasLargeUint64 = false; result.largeUint64_ = 18446744073709551615UL; return this; @@ -14114,11 +15294,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetSmallInt32(value); } } public Builder SetSmallInt32(int value) { + PrepareBuilder(); result.hasSmallInt32 = true; result.smallInt32_ = value; return this; } public Builder ClearSmallInt32() { + PrepareBuilder(); result.hasSmallInt32 = false; result.smallInt32_ = -2147483647; return this; @@ -14132,11 +15314,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetSmallInt64(value); } } public Builder SetSmallInt64(long value) { + PrepareBuilder(); result.hasSmallInt64 = true; result.smallInt64_ = value; return this; } public Builder ClearSmallInt64() { + PrepareBuilder(); result.hasSmallInt64 = false; result.smallInt64_ = -9223372036854775807L; return this; @@ -14151,11 +15335,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetUtf8String(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasUtf8String = true; result.utf8String_ = value; return this; } public Builder ClearUtf8String() { + PrepareBuilder(); result.hasUtf8String = false; result.utf8String_ = (string) global::Google.ProtocolBuffers.TestProtos.TestExtremeDefaultValues.Descriptor.Fields[5].DefaultValue; return this; @@ -14169,11 +15355,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetZeroFloat(value); } } public Builder SetZeroFloat(float value) { + PrepareBuilder(); result.hasZeroFloat = true; result.zeroFloat_ = value; return this; } public Builder ClearZeroFloat() { + PrepareBuilder(); result.hasZeroFloat = false; result.zeroFloat_ = 0F; return this; @@ -14187,11 +15375,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOneFloat(value); } } public Builder SetOneFloat(float value) { + PrepareBuilder(); result.hasOneFloat = true; result.oneFloat_ = value; return this; } public Builder ClearOneFloat() { + PrepareBuilder(); result.hasOneFloat = false; result.oneFloat_ = 1F; return this; @@ -14205,11 +15395,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetSmallFloat(value); } } public Builder SetSmallFloat(float value) { + PrepareBuilder(); result.hasSmallFloat = true; result.smallFloat_ = value; return this; } public Builder ClearSmallFloat() { + PrepareBuilder(); result.hasSmallFloat = false; result.smallFloat_ = 1.5F; return this; @@ -14223,11 +15415,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNegativeOneFloat(value); } } public Builder SetNegativeOneFloat(float value) { + PrepareBuilder(); result.hasNegativeOneFloat = true; result.negativeOneFloat_ = value; return this; } public Builder ClearNegativeOneFloat() { + PrepareBuilder(); result.hasNegativeOneFloat = false; result.negativeOneFloat_ = -1F; return this; @@ -14241,11 +15435,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNegativeFloat(value); } } public Builder SetNegativeFloat(float value) { + PrepareBuilder(); result.hasNegativeFloat = true; result.negativeFloat_ = value; return this; } public Builder ClearNegativeFloat() { + PrepareBuilder(); result.hasNegativeFloat = false; result.negativeFloat_ = -1.5F; return this; @@ -14259,11 +15455,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetLargeFloat(value); } } public Builder SetLargeFloat(float value) { + PrepareBuilder(); result.hasLargeFloat = true; result.largeFloat_ = value; return this; } public Builder ClearLargeFloat() { + PrepareBuilder(); result.hasLargeFloat = false; result.largeFloat_ = 2E+08F; return this; @@ -14277,11 +15475,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetSmallNegativeFloat(value); } } public Builder SetSmallNegativeFloat(float value) { + PrepareBuilder(); result.hasSmallNegativeFloat = true; result.smallNegativeFloat_ = value; return this; } public Builder ClearSmallNegativeFloat() { + PrepareBuilder(); result.hasSmallNegativeFloat = false; result.smallNegativeFloat_ = -8E-28F; return this; @@ -14295,11 +15495,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetInfDouble(value); } } public Builder SetInfDouble(double value) { + PrepareBuilder(); result.hasInfDouble = true; result.infDouble_ = value; return this; } public Builder ClearInfDouble() { + PrepareBuilder(); result.hasInfDouble = false; result.infDouble_ = double.PositiveInfinity; return this; @@ -14313,11 +15515,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNegInfDouble(value); } } public Builder SetNegInfDouble(double value) { + PrepareBuilder(); result.hasNegInfDouble = true; result.negInfDouble_ = value; return this; } public Builder ClearNegInfDouble() { + PrepareBuilder(); result.hasNegInfDouble = false; result.negInfDouble_ = double.NegativeInfinity; return this; @@ -14331,11 +15535,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNanDouble(value); } } public Builder SetNanDouble(double value) { + PrepareBuilder(); result.hasNanDouble = true; result.nanDouble_ = value; return this; } public Builder ClearNanDouble() { + PrepareBuilder(); result.hasNanDouble = false; result.nanDouble_ = double.NaN; return this; @@ -14349,11 +15555,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetInfFloat(value); } } public Builder SetInfFloat(float value) { + PrepareBuilder(); result.hasInfFloat = true; result.infFloat_ = value; return this; } public Builder ClearInfFloat() { + PrepareBuilder(); result.hasInfFloat = false; result.infFloat_ = float.PositiveInfinity; return this; @@ -14367,11 +15575,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNegInfFloat(value); } } public Builder SetNegInfFloat(float value) { + PrepareBuilder(); result.hasNegInfFloat = true; result.negInfFloat_ = value; return this; } public Builder ClearNegInfFloat() { + PrepareBuilder(); result.hasNegInfFloat = false; result.negInfFloat_ = float.NegativeInfinity; return this; @@ -14385,11 +15595,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNanFloat(value); } } public Builder SetNanFloat(float value) { + PrepareBuilder(); result.hasNanFloat = true; result.nanFloat_ = value; return this; } public Builder ClearNanFloat() { + PrepareBuilder(); result.hasNanFloat = false; result.nanFloat_ = float.NaN; return this; @@ -14502,7 +15714,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OneString prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -14512,21 +15724,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OneString(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OneString cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - OneString result = new OneString(); + bool builderIsReadOnly; + OneString result; + + private OneString PrepareBuilder() { + if (builderIsReadOnly) { + OneString original = result; + result = new OneString(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OneString MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OneString(); + result = DefaultInstance ?? new OneString(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -14538,12 +15777,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OneString BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OneString returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -14557,6 +15795,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OneString other) { if (other == global::Google.ProtocolBuffers.TestProtos.OneString.DefaultInstance) return this; + PrepareBuilder(); if (other.HasData) { Data = other.Data; } @@ -14569,6 +15808,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -14625,11 +15865,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetData(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasData = true; result.data_ = value; return this; } public Builder ClearData() { + PrepareBuilder(); result.hasData = false; result.data_ = ""; return this; @@ -14742,7 +15984,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OneBytes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -14752,21 +15994,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OneBytes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OneBytes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - OneBytes result = new OneBytes(); + bool builderIsReadOnly; + OneBytes result; + + private OneBytes PrepareBuilder() { + if (builderIsReadOnly) { + OneBytes original = result; + result = new OneBytes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OneBytes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OneBytes(); + result = DefaultInstance ?? new OneBytes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -14778,12 +16047,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OneBytes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OneBytes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -14797,6 +16065,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OneBytes other) { if (other == global::Google.ProtocolBuffers.TestProtos.OneBytes.DefaultInstance) return this; + PrepareBuilder(); if (other.HasData) { Data = other.Data; } @@ -14809,6 +16078,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -14865,11 +16135,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetData(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasData = true; result.data_ = value; return this; } public Builder ClearData() { + PrepareBuilder(); result.hasData = false; result.data_ = pb::ByteString.Empty; return this; @@ -15339,7 +16611,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestPackedTypes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -15349,21 +16621,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestPackedTypes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestPackedTypes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestPackedTypes result = new TestPackedTypes(); + bool builderIsReadOnly; + TestPackedTypes result; + + private TestPackedTypes PrepareBuilder() { + if (builderIsReadOnly) { + TestPackedTypes original = result; + result = new TestPackedTypes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestPackedTypes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestPackedTypes(); + result = DefaultInstance ?? new TestPackedTypes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -15375,8 +16674,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestPackedTypes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.packedInt32_.MakeReadOnly(); result.packedInt64_.MakeReadOnly(); @@ -15392,9 +16691,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.packedDouble_.MakeReadOnly(); result.packedBool_.MakeReadOnly(); result.packedEnum_.MakeReadOnly(); - TestPackedTypes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -15408,6 +16706,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestPackedTypes other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestPackedTypes.DefaultInstance) return this; + PrepareBuilder(); if (other.packedInt32_.Count != 0) { base.AddRange(other.packedInt32_, result.packedInt32_); } @@ -15459,6 +16758,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -15582,7 +16882,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList PackedInt32List { - get { return result.packedInt32_; } + get { return PrepareBuilder().packedInt32_; } } public int PackedInt32Count { get { return result.PackedInt32Count; } @@ -15591,24 +16891,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedInt32(index); } public Builder SetPackedInt32(int index, int value) { + PrepareBuilder(); result.packedInt32_[index] = value; return this; } public Builder AddPackedInt32(int value) { + PrepareBuilder(); result.packedInt32_.Add(value); return this; } public Builder AddRangePackedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedInt32_); return this; } public Builder ClearPackedInt32() { + PrepareBuilder(); result.packedInt32_.Clear(); return this; } public pbc::IPopsicleList PackedInt64List { - get { return result.packedInt64_; } + get { return PrepareBuilder().packedInt64_; } } public int PackedInt64Count { get { return result.PackedInt64Count; } @@ -15617,25 +16921,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedInt64(index); } public Builder SetPackedInt64(int index, long value) { + PrepareBuilder(); result.packedInt64_[index] = value; return this; } public Builder AddPackedInt64(long value) { + PrepareBuilder(); result.packedInt64_.Add(value); return this; } public Builder AddRangePackedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedInt64_); return this; } public Builder ClearPackedInt64() { + PrepareBuilder(); result.packedInt64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedUint32List { - get { return result.packedUint32_; } + get { return PrepareBuilder().packedUint32_; } } public int PackedUint32Count { get { return result.PackedUint32Count; } @@ -15646,27 +16954,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedUint32(int index, uint value) { + PrepareBuilder(); result.packedUint32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedUint32(uint value) { + PrepareBuilder(); result.packedUint32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedUint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedUint32_); return this; } public Builder ClearPackedUint32() { + PrepareBuilder(); result.packedUint32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedUint64List { - get { return result.packedUint64_; } + get { return PrepareBuilder().packedUint64_; } } public int PackedUint64Count { get { return result.PackedUint64Count; } @@ -15677,26 +16989,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedUint64(int index, ulong value) { + PrepareBuilder(); result.packedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedUint64(ulong value) { + PrepareBuilder(); result.packedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedUint64_); return this; } public Builder ClearPackedUint64() { + PrepareBuilder(); result.packedUint64_.Clear(); return this; } public pbc::IPopsicleList PackedSint32List { - get { return result.packedSint32_; } + get { return PrepareBuilder().packedSint32_; } } public int PackedSint32Count { get { return result.PackedSint32Count; } @@ -15705,24 +17021,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSint32(index); } public Builder SetPackedSint32(int index, int value) { + PrepareBuilder(); result.packedSint32_[index] = value; return this; } public Builder AddPackedSint32(int value) { + PrepareBuilder(); result.packedSint32_.Add(value); return this; } public Builder AddRangePackedSint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSint32_); return this; } public Builder ClearPackedSint32() { + PrepareBuilder(); result.packedSint32_.Clear(); return this; } public pbc::IPopsicleList PackedSint64List { - get { return result.packedSint64_; } + get { return PrepareBuilder().packedSint64_; } } public int PackedSint64Count { get { return result.PackedSint64Count; } @@ -15731,25 +17051,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSint64(index); } public Builder SetPackedSint64(int index, long value) { + PrepareBuilder(); result.packedSint64_[index] = value; return this; } public Builder AddPackedSint64(long value) { + PrepareBuilder(); result.packedSint64_.Add(value); return this; } public Builder AddRangePackedSint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSint64_); return this; } public Builder ClearPackedSint64() { + PrepareBuilder(); result.packedSint64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedFixed32List { - get { return result.packedFixed32_; } + get { return PrepareBuilder().packedFixed32_; } } public int PackedFixed32Count { get { return result.PackedFixed32Count; } @@ -15760,27 +17084,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedFixed32(int index, uint value) { + PrepareBuilder(); result.packedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedFixed32(uint value) { + PrepareBuilder(); result.packedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedFixed32_); return this; } public Builder ClearPackedFixed32() { + PrepareBuilder(); result.packedFixed32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedFixed64List { - get { return result.packedFixed64_; } + get { return PrepareBuilder().packedFixed64_; } } public int PackedFixed64Count { get { return result.PackedFixed64Count; } @@ -15791,26 +17119,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedFixed64(int index, ulong value) { + PrepareBuilder(); result.packedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedFixed64(ulong value) { + PrepareBuilder(); result.packedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedFixed64_); return this; } public Builder ClearPackedFixed64() { + PrepareBuilder(); result.packedFixed64_.Clear(); return this; } public pbc::IPopsicleList PackedSfixed32List { - get { return result.packedSfixed32_; } + get { return PrepareBuilder().packedSfixed32_; } } public int PackedSfixed32Count { get { return result.PackedSfixed32Count; } @@ -15819,24 +17151,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSfixed32(index); } public Builder SetPackedSfixed32(int index, int value) { + PrepareBuilder(); result.packedSfixed32_[index] = value; return this; } public Builder AddPackedSfixed32(int value) { + PrepareBuilder(); result.packedSfixed32_.Add(value); return this; } public Builder AddRangePackedSfixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSfixed32_); return this; } public Builder ClearPackedSfixed32() { + PrepareBuilder(); result.packedSfixed32_.Clear(); return this; } public pbc::IPopsicleList PackedSfixed64List { - get { return result.packedSfixed64_; } + get { return PrepareBuilder().packedSfixed64_; } } public int PackedSfixed64Count { get { return result.PackedSfixed64Count; } @@ -15845,24 +17181,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSfixed64(index); } public Builder SetPackedSfixed64(int index, long value) { + PrepareBuilder(); result.packedSfixed64_[index] = value; return this; } public Builder AddPackedSfixed64(long value) { + PrepareBuilder(); result.packedSfixed64_.Add(value); return this; } public Builder AddRangePackedSfixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSfixed64_); return this; } public Builder ClearPackedSfixed64() { + PrepareBuilder(); result.packedSfixed64_.Clear(); return this; } public pbc::IPopsicleList PackedFloatList { - get { return result.packedFloat_; } + get { return PrepareBuilder().packedFloat_; } } public int PackedFloatCount { get { return result.PackedFloatCount; } @@ -15871,24 +17211,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedFloat(index); } public Builder SetPackedFloat(int index, float value) { + PrepareBuilder(); result.packedFloat_[index] = value; return this; } public Builder AddPackedFloat(float value) { + PrepareBuilder(); result.packedFloat_.Add(value); return this; } public Builder AddRangePackedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedFloat_); return this; } public Builder ClearPackedFloat() { + PrepareBuilder(); result.packedFloat_.Clear(); return this; } public pbc::IPopsicleList PackedDoubleList { - get { return result.packedDouble_; } + get { return PrepareBuilder().packedDouble_; } } public int PackedDoubleCount { get { return result.PackedDoubleCount; } @@ -15897,24 +17241,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedDouble(index); } public Builder SetPackedDouble(int index, double value) { + PrepareBuilder(); result.packedDouble_[index] = value; return this; } public Builder AddPackedDouble(double value) { + PrepareBuilder(); result.packedDouble_.Add(value); return this; } public Builder AddRangePackedDouble(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedDouble_); return this; } public Builder ClearPackedDouble() { + PrepareBuilder(); result.packedDouble_.Clear(); return this; } public pbc::IPopsicleList PackedBoolList { - get { return result.packedBool_; } + get { return PrepareBuilder().packedBool_; } } public int PackedBoolCount { get { return result.PackedBoolCount; } @@ -15923,24 +17271,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedBool(index); } public Builder SetPackedBool(int index, bool value) { + PrepareBuilder(); result.packedBool_[index] = value; return this; } public Builder AddPackedBool(bool value) { + PrepareBuilder(); result.packedBool_.Add(value); return this; } public Builder AddRangePackedBool(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedBool_); return this; } public Builder ClearPackedBool() { + PrepareBuilder(); result.packedBool_.Clear(); return this; } public pbc::IPopsicleList PackedEnumList { - get { return result.packedEnum_; } + get { return PrepareBuilder().packedEnum_; } } public int PackedEnumCount { get { return result.PackedEnumCount; } @@ -15949,18 +17301,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedEnum(index); } public Builder SetPackedEnum(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.packedEnum_[index] = value; return this; } public Builder AddPackedEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.packedEnum_.Add(value); return this; } public Builder AddRangePackedEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedEnum_); return this; } public Builder ClearPackedEnum() { + PrepareBuilder(); result.packedEnum_.Clear(); return this; } @@ -16374,7 +17730,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestUnpackedTypes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -16384,21 +17740,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestUnpackedTypes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestUnpackedTypes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestUnpackedTypes result; + + private TestUnpackedTypes PrepareBuilder() { + if (builderIsReadOnly) { + TestUnpackedTypes original = result; + result = new TestUnpackedTypes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestUnpackedTypes result = new TestUnpackedTypes(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestUnpackedTypes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestUnpackedTypes(); + result = DefaultInstance ?? new TestUnpackedTypes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -16410,8 +17793,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestUnpackedTypes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.unpackedInt32_.MakeReadOnly(); result.unpackedInt64_.MakeReadOnly(); @@ -16427,9 +17810,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.unpackedDouble_.MakeReadOnly(); result.unpackedBool_.MakeReadOnly(); result.unpackedEnum_.MakeReadOnly(); - TestUnpackedTypes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -16443,6 +17825,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestUnpackedTypes other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestUnpackedTypes.DefaultInstance) return this; + PrepareBuilder(); if (other.unpackedInt32_.Count != 0) { base.AddRange(other.unpackedInt32_, result.unpackedInt32_); } @@ -16494,6 +17877,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -16617,7 +18001,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList UnpackedInt32List { - get { return result.unpackedInt32_; } + get { return PrepareBuilder().unpackedInt32_; } } public int UnpackedInt32Count { get { return result.UnpackedInt32Count; } @@ -16626,24 +18010,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedInt32(index); } public Builder SetUnpackedInt32(int index, int value) { + PrepareBuilder(); result.unpackedInt32_[index] = value; return this; } public Builder AddUnpackedInt32(int value) { + PrepareBuilder(); result.unpackedInt32_.Add(value); return this; } public Builder AddRangeUnpackedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedInt32_); return this; } public Builder ClearUnpackedInt32() { + PrepareBuilder(); result.unpackedInt32_.Clear(); return this; } public pbc::IPopsicleList UnpackedInt64List { - get { return result.unpackedInt64_; } + get { return PrepareBuilder().unpackedInt64_; } } public int UnpackedInt64Count { get { return result.UnpackedInt64Count; } @@ -16652,25 +18040,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedInt64(index); } public Builder SetUnpackedInt64(int index, long value) { + PrepareBuilder(); result.unpackedInt64_[index] = value; return this; } public Builder AddUnpackedInt64(long value) { + PrepareBuilder(); result.unpackedInt64_.Add(value); return this; } public Builder AddRangeUnpackedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedInt64_); return this; } public Builder ClearUnpackedInt64() { + PrepareBuilder(); result.unpackedInt64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedUint32List { - get { return result.unpackedUint32_; } + get { return PrepareBuilder().unpackedUint32_; } } public int UnpackedUint32Count { get { return result.UnpackedUint32Count; } @@ -16681,27 +18073,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedUint32(int index, uint value) { + PrepareBuilder(); result.unpackedUint32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedUint32(uint value) { + PrepareBuilder(); result.unpackedUint32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedUint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedUint32_); return this; } public Builder ClearUnpackedUint32() { + PrepareBuilder(); result.unpackedUint32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedUint64List { - get { return result.unpackedUint64_; } + get { return PrepareBuilder().unpackedUint64_; } } public int UnpackedUint64Count { get { return result.UnpackedUint64Count; } @@ -16712,26 +18108,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedUint64(int index, ulong value) { + PrepareBuilder(); result.unpackedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedUint64(ulong value) { + PrepareBuilder(); result.unpackedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedUint64_); return this; } public Builder ClearUnpackedUint64() { + PrepareBuilder(); result.unpackedUint64_.Clear(); return this; } public pbc::IPopsicleList UnpackedSint32List { - get { return result.unpackedSint32_; } + get { return PrepareBuilder().unpackedSint32_; } } public int UnpackedSint32Count { get { return result.UnpackedSint32Count; } @@ -16740,24 +18140,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSint32(index); } public Builder SetUnpackedSint32(int index, int value) { + PrepareBuilder(); result.unpackedSint32_[index] = value; return this; } public Builder AddUnpackedSint32(int value) { + PrepareBuilder(); result.unpackedSint32_.Add(value); return this; } public Builder AddRangeUnpackedSint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSint32_); return this; } public Builder ClearUnpackedSint32() { + PrepareBuilder(); result.unpackedSint32_.Clear(); return this; } public pbc::IPopsicleList UnpackedSint64List { - get { return result.unpackedSint64_; } + get { return PrepareBuilder().unpackedSint64_; } } public int UnpackedSint64Count { get { return result.UnpackedSint64Count; } @@ -16766,25 +18170,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSint64(index); } public Builder SetUnpackedSint64(int index, long value) { + PrepareBuilder(); result.unpackedSint64_[index] = value; return this; } public Builder AddUnpackedSint64(long value) { + PrepareBuilder(); result.unpackedSint64_.Add(value); return this; } public Builder AddRangeUnpackedSint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSint64_); return this; } public Builder ClearUnpackedSint64() { + PrepareBuilder(); result.unpackedSint64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedFixed32List { - get { return result.unpackedFixed32_; } + get { return PrepareBuilder().unpackedFixed32_; } } public int UnpackedFixed32Count { get { return result.UnpackedFixed32Count; } @@ -16795,27 +18203,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedFixed32(int index, uint value) { + PrepareBuilder(); result.unpackedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedFixed32(uint value) { + PrepareBuilder(); result.unpackedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedFixed32_); return this; } public Builder ClearUnpackedFixed32() { + PrepareBuilder(); result.unpackedFixed32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedFixed64List { - get { return result.unpackedFixed64_; } + get { return PrepareBuilder().unpackedFixed64_; } } public int UnpackedFixed64Count { get { return result.UnpackedFixed64Count; } @@ -16826,26 +18238,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedFixed64(int index, ulong value) { + PrepareBuilder(); result.unpackedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedFixed64(ulong value) { + PrepareBuilder(); result.unpackedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedFixed64_); return this; } public Builder ClearUnpackedFixed64() { + PrepareBuilder(); result.unpackedFixed64_.Clear(); return this; } public pbc::IPopsicleList UnpackedSfixed32List { - get { return result.unpackedSfixed32_; } + get { return PrepareBuilder().unpackedSfixed32_; } } public int UnpackedSfixed32Count { get { return result.UnpackedSfixed32Count; } @@ -16854,24 +18270,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSfixed32(index); } public Builder SetUnpackedSfixed32(int index, int value) { + PrepareBuilder(); result.unpackedSfixed32_[index] = value; return this; } public Builder AddUnpackedSfixed32(int value) { + PrepareBuilder(); result.unpackedSfixed32_.Add(value); return this; } public Builder AddRangeUnpackedSfixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSfixed32_); return this; } public Builder ClearUnpackedSfixed32() { + PrepareBuilder(); result.unpackedSfixed32_.Clear(); return this; } public pbc::IPopsicleList UnpackedSfixed64List { - get { return result.unpackedSfixed64_; } + get { return PrepareBuilder().unpackedSfixed64_; } } public int UnpackedSfixed64Count { get { return result.UnpackedSfixed64Count; } @@ -16880,24 +18300,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSfixed64(index); } public Builder SetUnpackedSfixed64(int index, long value) { + PrepareBuilder(); result.unpackedSfixed64_[index] = value; return this; } public Builder AddUnpackedSfixed64(long value) { + PrepareBuilder(); result.unpackedSfixed64_.Add(value); return this; } public Builder AddRangeUnpackedSfixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSfixed64_); return this; } public Builder ClearUnpackedSfixed64() { + PrepareBuilder(); result.unpackedSfixed64_.Clear(); return this; } public pbc::IPopsicleList UnpackedFloatList { - get { return result.unpackedFloat_; } + get { return PrepareBuilder().unpackedFloat_; } } public int UnpackedFloatCount { get { return result.UnpackedFloatCount; } @@ -16906,24 +18330,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedFloat(index); } public Builder SetUnpackedFloat(int index, float value) { + PrepareBuilder(); result.unpackedFloat_[index] = value; return this; } public Builder AddUnpackedFloat(float value) { + PrepareBuilder(); result.unpackedFloat_.Add(value); return this; } public Builder AddRangeUnpackedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedFloat_); return this; } public Builder ClearUnpackedFloat() { + PrepareBuilder(); result.unpackedFloat_.Clear(); return this; } public pbc::IPopsicleList UnpackedDoubleList { - get { return result.unpackedDouble_; } + get { return PrepareBuilder().unpackedDouble_; } } public int UnpackedDoubleCount { get { return result.UnpackedDoubleCount; } @@ -16932,24 +18360,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedDouble(index); } public Builder SetUnpackedDouble(int index, double value) { + PrepareBuilder(); result.unpackedDouble_[index] = value; return this; } public Builder AddUnpackedDouble(double value) { + PrepareBuilder(); result.unpackedDouble_.Add(value); return this; } public Builder AddRangeUnpackedDouble(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedDouble_); return this; } public Builder ClearUnpackedDouble() { + PrepareBuilder(); result.unpackedDouble_.Clear(); return this; } public pbc::IPopsicleList UnpackedBoolList { - get { return result.unpackedBool_; } + get { return PrepareBuilder().unpackedBool_; } } public int UnpackedBoolCount { get { return result.UnpackedBoolCount; } @@ -16958,24 +18390,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedBool(index); } public Builder SetUnpackedBool(int index, bool value) { + PrepareBuilder(); result.unpackedBool_[index] = value; return this; } public Builder AddUnpackedBool(bool value) { + PrepareBuilder(); result.unpackedBool_.Add(value); return this; } public Builder AddRangeUnpackedBool(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedBool_); return this; } public Builder ClearUnpackedBool() { + PrepareBuilder(); result.unpackedBool_.Clear(); return this; } public pbc::IPopsicleList UnpackedEnumList { - get { return result.unpackedEnum_; } + get { return PrepareBuilder().unpackedEnum_; } } public int UnpackedEnumCount { get { return result.UnpackedEnumCount; } @@ -16984,18 +18420,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedEnum(index); } public Builder SetUnpackedEnum(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.unpackedEnum_[index] = value; return this; } public Builder AddUnpackedEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.unpackedEnum_.Add(value); return this; } public Builder AddRangeUnpackedEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedEnum_); return this; } public Builder ClearUnpackedEnum() { + PrepareBuilder(); result.unpackedEnum_.Clear(); return this; } @@ -17095,7 +18535,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestPackedExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -17105,21 +18545,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestPackedExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestPackedExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestPackedExtensions result; + + private TestPackedExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestPackedExtensions original = result; + result = new TestPackedExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestPackedExtensions result = new TestPackedExtensions(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestPackedExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestPackedExtensions(); + result = DefaultInstance ?? new TestPackedExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -17131,12 +18598,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestPackedExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestPackedExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -17150,6 +18616,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestPackedExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestPackedExtensions.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -17160,6 +18627,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -17298,7 +18766,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestUnpackedExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -17308,21 +18776,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestUnpackedExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestUnpackedExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestUnpackedExtensions result; + + private TestUnpackedExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestUnpackedExtensions original = result; + result = new TestUnpackedExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestUnpackedExtensions result = new TestUnpackedExtensions(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestUnpackedExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestUnpackedExtensions(); + result = DefaultInstance ?? new TestUnpackedExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -17334,12 +18829,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestUnpackedExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestUnpackedExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -17353,6 +18847,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestUnpackedExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensions.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -17363,6 +18858,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -17553,7 +19049,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(DynamicMessageType prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -17563,21 +19059,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new DynamicMessageType(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(DynamicMessageType cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + DynamicMessageType result; - DynamicMessageType result = new DynamicMessageType(); + private DynamicMessageType PrepareBuilder() { + if (builderIsReadOnly) { + DynamicMessageType original = result; + result = new DynamicMessageType(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override DynamicMessageType MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new DynamicMessageType(); + result = DefaultInstance ?? new DynamicMessageType(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -17589,12 +19112,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override DynamicMessageType BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - DynamicMessageType returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -17608,6 +19130,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(DynamicMessageType other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.DefaultInstance) return this; + PrepareBuilder(); if (other.HasDynamicField) { DynamicField = other.DynamicField; } @@ -17620,6 +19143,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -17675,11 +19199,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDynamicField(value); } } public Builder SetDynamicField(int value) { + PrepareBuilder(); result.hasDynamicField = true; result.dynamicField_ = value; return this; } public Builder ClearDynamicField() { + PrepareBuilder(); result.hasDynamicField = false; result.dynamicField_ = 0; return this; @@ -17883,7 +19409,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestDynamicExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -17893,21 +19419,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestDynamicExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestDynamicExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestDynamicExtensions result = new TestDynamicExtensions(); + bool builderIsReadOnly; + TestDynamicExtensions result; + + private TestDynamicExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestDynamicExtensions original = result; + result = new TestDynamicExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestDynamicExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestDynamicExtensions(); + result = DefaultInstance ?? new TestDynamicExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -17919,14 +19472,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestDynamicExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedExtension_.MakeReadOnly(); result.packedExtension_.MakeReadOnly(); - TestDynamicExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -17940,6 +19492,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestDynamicExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasScalarExtension) { ScalarExtension = other.ScalarExtension; } @@ -17970,6 +19523,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -18078,11 +19632,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetScalarExtension(uint value) { + PrepareBuilder(); result.hasScalarExtension = true; result.scalarExtension_ = value; return this; } public Builder ClearScalarExtension() { + PrepareBuilder(); result.hasScalarExtension = false; result.scalarExtension_ = 0; return this; @@ -18096,11 +19652,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetEnumExtension(value); } } public Builder SetEnumExtension(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.hasEnumExtension = true; result.enumExtension_ = value; return this; } public Builder ClearEnumExtension() { + PrepareBuilder(); result.hasEnumExtension = false; result.enumExtension_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnum.FOREIGN_FOO; return this; @@ -18114,11 +19672,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDynamicEnumExtension(value); } } public Builder SetDynamicEnumExtension(global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicEnumType value) { + PrepareBuilder(); result.hasDynamicEnumExtension = true; result.dynamicEnumExtension_ = value; return this; } public Builder ClearDynamicEnumExtension() { + PrepareBuilder(); result.hasDynamicEnumExtension = false; result.dynamicEnumExtension_ = global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicEnumType.DYNAMIC_FOO; return this; @@ -18133,18 +19693,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMessageExtension(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMessageExtension = true; result.messageExtension_ = value; return this; } public Builder SetMessageExtension(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasMessageExtension = true; result.messageExtension_ = builderForValue.Build(); return this; } public Builder MergeMessageExtension(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasMessageExtension && result.messageExtension_ != global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) { result.messageExtension_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.CreateBuilder(result.messageExtension_).MergeFrom(value).BuildPartial(); @@ -18155,6 +19718,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearMessageExtension() { + PrepareBuilder(); result.hasMessageExtension = false; result.messageExtension_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance; return this; @@ -18169,18 +19733,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDynamicMessageExtension(global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDynamicMessageExtension = true; result.dynamicMessageExtension_ = value; return this; } public Builder SetDynamicMessageExtension(global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasDynamicMessageExtension = true; result.dynamicMessageExtension_ = builderForValue.Build(); return this; } public Builder MergeDynamicMessageExtension(global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasDynamicMessageExtension && result.dynamicMessageExtension_ != global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.DefaultInstance) { result.dynamicMessageExtension_ = global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.CreateBuilder(result.dynamicMessageExtension_).MergeFrom(value).BuildPartial(); @@ -18191,13 +19758,14 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearDynamicMessageExtension() { + PrepareBuilder(); result.hasDynamicMessageExtension = false; result.dynamicMessageExtension_ = global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.DefaultInstance; return this; } public pbc::IPopsicleList RepeatedExtensionList { - get { return result.repeatedExtension_; } + get { return PrepareBuilder().repeatedExtension_; } } public int RepeatedExtensionCount { get { return result.RepeatedExtensionCount; } @@ -18207,25 +19775,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedExtension(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedExtension_[index] = value; return this; } public Builder AddRepeatedExtension(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedExtension_.Add(value); return this; } public Builder AddRangeRepeatedExtension(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedExtension_); return this; } public Builder ClearRepeatedExtension() { + PrepareBuilder(); result.repeatedExtension_.Clear(); return this; } public pbc::IPopsicleList PackedExtensionList { - get { return result.packedExtension_; } + get { return PrepareBuilder().packedExtension_; } } public int PackedExtensionCount { get { return result.PackedExtensionCount; } @@ -18234,18 +19806,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedExtension(index); } public Builder SetPackedExtension(int index, int value) { + PrepareBuilder(); result.packedExtension_[index] = value; return this; } public Builder AddPackedExtension(int value) { + PrepareBuilder(); result.packedExtension_.Add(value); return this; } public Builder AddRangePackedExtension(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedExtension_); return this; } public Builder ClearPackedExtension() { + PrepareBuilder(); result.packedExtension_.Clear(); return this; } @@ -18479,7 +20055,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRepeatedScalarDifferentTagSizes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -18489,21 +20065,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRepeatedScalarDifferentTagSizes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRepeatedScalarDifferentTagSizes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestRepeatedScalarDifferentTagSizes result; + + private TestRepeatedScalarDifferentTagSizes PrepareBuilder() { + if (builderIsReadOnly) { + TestRepeatedScalarDifferentTagSizes original = result; + result = new TestRepeatedScalarDifferentTagSizes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestRepeatedScalarDifferentTagSizes result = new TestRepeatedScalarDifferentTagSizes(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRepeatedScalarDifferentTagSizes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRepeatedScalarDifferentTagSizes(); + result = DefaultInstance ?? new TestRepeatedScalarDifferentTagSizes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -18515,8 +20118,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRepeatedScalarDifferentTagSizes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedFixed32_.MakeReadOnly(); result.repeatedInt32_.MakeReadOnly(); @@ -18524,9 +20127,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.repeatedInt64_.MakeReadOnly(); result.repeatedFloat_.MakeReadOnly(); result.repeatedUint64_.MakeReadOnly(); - TestRepeatedScalarDifferentTagSizes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -18540,6 +20142,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestRepeatedScalarDifferentTagSizes other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestRepeatedScalarDifferentTagSizes.DefaultInstance) return this; + PrepareBuilder(); if (other.repeatedFixed32_.Count != 0) { base.AddRange(other.repeatedFixed32_, result.repeatedFixed32_); } @@ -18567,6 +20170,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -18642,7 +20246,7 @@ namespace Google.ProtocolBuffers.TestProtos { [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed32List { - get { return result.repeatedFixed32_; } + get { return PrepareBuilder().repeatedFixed32_; } } public int RepeatedFixed32Count { get { return result.RepeatedFixed32Count; } @@ -18653,26 +20257,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed32(int index, uint value) { + PrepareBuilder(); result.repeatedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed32(uint value) { + PrepareBuilder(); result.repeatedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed32_); return this; } public Builder ClearRepeatedFixed32() { + PrepareBuilder(); result.repeatedFixed32_.Clear(); return this; } public pbc::IPopsicleList RepeatedInt32List { - get { return result.repeatedInt32_; } + get { return PrepareBuilder().repeatedInt32_; } } public int RepeatedInt32Count { get { return result.RepeatedInt32Count; } @@ -18681,25 +20289,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt32(index); } public Builder SetRepeatedInt32(int index, int value) { + PrepareBuilder(); result.repeatedInt32_[index] = value; return this; } public Builder AddRepeatedInt32(int value) { + PrepareBuilder(); result.repeatedInt32_.Add(value); return this; } public Builder AddRangeRepeatedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt32_); return this; } public Builder ClearRepeatedInt32() { + PrepareBuilder(); result.repeatedInt32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed64List { - get { return result.repeatedFixed64_; } + get { return PrepareBuilder().repeatedFixed64_; } } public int RepeatedFixed64Count { get { return result.RepeatedFixed64Count; } @@ -18710,26 +20322,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed64(int index, ulong value) { + PrepareBuilder(); result.repeatedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed64(ulong value) { + PrepareBuilder(); result.repeatedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed64_); return this; } public Builder ClearRepeatedFixed64() { + PrepareBuilder(); result.repeatedFixed64_.Clear(); return this; } public pbc::IPopsicleList RepeatedInt64List { - get { return result.repeatedInt64_; } + get { return PrepareBuilder().repeatedInt64_; } } public int RepeatedInt64Count { get { return result.RepeatedInt64Count; } @@ -18738,24 +20354,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt64(index); } public Builder SetRepeatedInt64(int index, long value) { + PrepareBuilder(); result.repeatedInt64_[index] = value; return this; } public Builder AddRepeatedInt64(long value) { + PrepareBuilder(); result.repeatedInt64_.Add(value); return this; } public Builder AddRangeRepeatedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt64_); return this; } public Builder ClearRepeatedInt64() { + PrepareBuilder(); result.repeatedInt64_.Clear(); return this; } public pbc::IPopsicleList RepeatedFloatList { - get { return result.repeatedFloat_; } + get { return PrepareBuilder().repeatedFloat_; } } public int RepeatedFloatCount { get { return result.RepeatedFloatCount; } @@ -18764,25 +20384,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedFloat(index); } public Builder SetRepeatedFloat(int index, float value) { + PrepareBuilder(); result.repeatedFloat_[index] = value; return this; } public Builder AddRepeatedFloat(float value) { + PrepareBuilder(); result.repeatedFloat_.Add(value); return this; } public Builder AddRangeRepeatedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFloat_); return this; } public Builder ClearRepeatedFloat() { + PrepareBuilder(); result.repeatedFloat_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedUint64List { - get { return result.repeatedUint64_; } + get { return PrepareBuilder().repeatedUint64_; } } public int RepeatedUint64Count { get { return result.RepeatedUint64Count; } @@ -18793,20 +20417,24 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedUint64(int index, ulong value) { + PrepareBuilder(); result.repeatedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedUint64(ulong value) { + PrepareBuilder(); result.repeatedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedUint64_); return this; } public Builder ClearRepeatedUint64() { + PrepareBuilder(); result.repeatedUint64_.Clear(); return this; } @@ -18902,7 +20530,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(FooRequest prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -18912,21 +20540,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new FooRequest(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(FooRequest cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - FooRequest result = new FooRequest(); + bool builderIsReadOnly; + FooRequest result; + + private FooRequest PrepareBuilder() { + if (builderIsReadOnly) { + FooRequest original = result; + result = new FooRequest(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override FooRequest MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new FooRequest(); + result = DefaultInstance ?? new FooRequest(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -18938,12 +20593,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override FooRequest BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - FooRequest returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -18957,6 +20611,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(FooRequest other) { if (other == global::Google.ProtocolBuffers.TestProtos.FooRequest.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -18966,6 +20621,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -19100,7 +20756,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(FooResponse prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -19110,21 +20766,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new FooResponse(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(FooResponse cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + FooResponse result; + + private FooResponse PrepareBuilder() { + if (builderIsReadOnly) { + FooResponse original = result; + result = new FooResponse(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - FooResponse result = new FooResponse(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override FooResponse MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new FooResponse(); + result = DefaultInstance ?? new FooResponse(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -19136,12 +20819,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override FooResponse BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - FooResponse returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -19155,6 +20837,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(FooResponse other) { if (other == global::Google.ProtocolBuffers.TestProtos.FooResponse.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -19164,6 +20847,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -19298,7 +20982,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(BarRequest prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -19308,21 +20992,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new BarRequest(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(BarRequest cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + BarRequest result; + + private BarRequest PrepareBuilder() { + if (builderIsReadOnly) { + BarRequest original = result; + result = new BarRequest(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - BarRequest result = new BarRequest(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override BarRequest MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new BarRequest(); + result = DefaultInstance ?? new BarRequest(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -19334,12 +21045,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override BarRequest BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - BarRequest returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -19353,6 +21063,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(BarRequest other) { if (other == global::Google.ProtocolBuffers.TestProtos.BarRequest.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -19362,6 +21073,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -19496,7 +21208,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(BarResponse prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -19506,21 +21218,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new BarResponse(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(BarResponse cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - BarResponse result = new BarResponse(); + bool builderIsReadOnly; + BarResponse result; + + private BarResponse PrepareBuilder() { + if (builderIsReadOnly) { + BarResponse original = result; + result = new BarResponse(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override BarResponse MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new BarResponse(); + result = DefaultInstance ?? new BarResponse(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -19532,12 +21271,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override BarResponse BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - BarResponse returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -19551,6 +21289,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(BarResponse other) { if (other == global::Google.ProtocolBuffers.TestProtos.BarResponse.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -19560,6 +21299,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestRpcInterop.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestRpcInterop.cs index ae309fa706..3c5e9307d1 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestRpcInterop.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestRpcInterop.cs @@ -188,7 +188,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SearchRequest prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -198,21 +198,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SearchRequest(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SearchRequest cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + SearchRequest result; - SearchRequest result = new SearchRequest(); + private SearchRequest PrepareBuilder() { + if (builderIsReadOnly) { + SearchRequest original = result; + result = new SearchRequest(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SearchRequest MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SearchRequest(); + result = DefaultInstance ?? new SearchRequest(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -224,13 +251,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SearchRequest BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.criteria_.MakeReadOnly(); - SearchRequest returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -244,6 +270,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(SearchRequest other) { if (other == global::Google.ProtocolBuffers.TestProtos.SearchRequest.DefaultInstance) return this; + PrepareBuilder(); if (other.criteria_.Count != 0) { base.AddRange(other.criteria_, result.criteria_); } @@ -256,6 +283,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -304,7 +332,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList CriteriaList { - get { return result.criteria_; } + get { return PrepareBuilder().criteria_; } } public int CriteriaCount { get { return result.CriteriaCount; } @@ -314,19 +342,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetCriteria(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.criteria_[index] = value; return this; } public Builder AddCriteria(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.criteria_.Add(value); return this; } public Builder AddRangeCriteria(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.criteria_); return this; } public Builder ClearCriteria() { + PrepareBuilder(); result.criteria_.Clear(); return this; } @@ -487,7 +519,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ResultItem prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -497,21 +529,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ResultItem(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ResultItem cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ResultItem result; - ResultItem result = new ResultItem(); + private ResultItem PrepareBuilder() { + if (builderIsReadOnly) { + ResultItem original = result; + result = new ResultItem(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ResultItem MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ResultItem(); + result = DefaultInstance ?? new ResultItem(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -523,12 +582,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ResultItem BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ResultItem returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -542,6 +600,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ResultItem other) { if (other == global::Google.ProtocolBuffers.TestProtos.SearchResponse.Types.ResultItem.DefaultInstance) return this; + PrepareBuilder(); if (other.HasUrl) { Url = other.Url; } @@ -557,6 +616,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -617,11 +677,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetUrl(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasUrl = true; result.url_ = value; return this; } public Builder ClearUrl() { + PrepareBuilder(); result.hasUrl = false; result.url_ = ""; return this; @@ -636,11 +698,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -734,7 +798,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SearchResponse prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -744,21 +808,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SearchResponse(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SearchResponse cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + SearchResponse result; - SearchResponse result = new SearchResponse(); + private SearchResponse PrepareBuilder() { + if (builderIsReadOnly) { + SearchResponse original = result; + result = new SearchResponse(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SearchResponse MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SearchResponse(); + result = DefaultInstance ?? new SearchResponse(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -770,13 +861,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SearchResponse BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.results_.MakeReadOnly(); - SearchResponse returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -790,6 +880,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(SearchResponse other) { if (other == global::Google.ProtocolBuffers.TestProtos.SearchResponse.DefaultInstance) return this; + PrepareBuilder(); if (other.results_.Count != 0) { base.AddRange(other.results_, result.results_); } @@ -802,6 +893,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -850,7 +942,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList ResultsList { - get { return result.results_; } + get { return PrepareBuilder().results_; } } public int ResultsCount { get { return result.ResultsCount; } @@ -860,29 +952,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetResults(int index, global::Google.ProtocolBuffers.TestProtos.SearchResponse.Types.ResultItem value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.results_[index] = value; return this; } public Builder SetResults(int index, global::Google.ProtocolBuffers.TestProtos.SearchResponse.Types.ResultItem.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.results_[index] = builderForValue.Build(); return this; } public Builder AddResults(global::Google.ProtocolBuffers.TestProtos.SearchResponse.Types.ResultItem value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.results_.Add(value); return this; } public Builder AddResults(global::Google.ProtocolBuffers.TestProtos.SearchResponse.Types.ResultItem.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.results_.Add(builderForValue.Build()); return this; } public Builder AddRangeResults(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.results_); return this; } public Builder ClearResults() { + PrepareBuilder(); result.results_.Clear(); return this; } @@ -1019,7 +1117,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(RefineSearchRequest prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1029,21 +1127,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new RefineSearchRequest(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(RefineSearchRequest cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + RefineSearchRequest result; - RefineSearchRequest result = new RefineSearchRequest(); + private RefineSearchRequest PrepareBuilder() { + if (builderIsReadOnly) { + RefineSearchRequest original = result; + result = new RefineSearchRequest(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override RefineSearchRequest MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new RefineSearchRequest(); + result = DefaultInstance ?? new RefineSearchRequest(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1055,13 +1180,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override RefineSearchRequest BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.criteria_.MakeReadOnly(); - RefineSearchRequest returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1075,6 +1199,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(RefineSearchRequest other) { if (other == global::Google.ProtocolBuffers.TestProtos.RefineSearchRequest.DefaultInstance) return this; + PrepareBuilder(); if (other.criteria_.Count != 0) { base.AddRange(other.criteria_, result.criteria_); } @@ -1090,6 +1215,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1147,7 +1273,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList CriteriaList { - get { return result.criteria_; } + get { return PrepareBuilder().criteria_; } } public int CriteriaCount { get { return result.CriteriaCount; } @@ -1157,19 +1283,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetCriteria(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.criteria_[index] = value; return this; } public Builder AddCriteria(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.criteria_.Add(value); return this; } public Builder AddRangeCriteria(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.criteria_); return this; } public Builder ClearCriteria() { + PrepareBuilder(); result.criteria_.Clear(); return this; } @@ -1183,18 +1313,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetPreviousResults(global::Google.ProtocolBuffers.TestProtos.SearchResponse value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasPreviousResults = true; result.previousResults_ = value; return this; } public Builder SetPreviousResults(global::Google.ProtocolBuffers.TestProtos.SearchResponse.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasPreviousResults = true; result.previousResults_ = builderForValue.Build(); return this; } public Builder MergePreviousResults(global::Google.ProtocolBuffers.TestProtos.SearchResponse value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasPreviousResults && result.previousResults_ != global::Google.ProtocolBuffers.TestProtos.SearchResponse.DefaultInstance) { result.previousResults_ = global::Google.ProtocolBuffers.TestProtos.SearchResponse.CreateBuilder(result.previousResults_).MergeFrom(value).BuildPartial(); @@ -1205,6 +1338,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearPreviousResults() { + PrepareBuilder(); result.hasPreviousResults = false; result.previousResults_ = global::Google.ProtocolBuffers.TestProtos.SearchResponse.DefaultInstance; return this; diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestXmlSerializerTestProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestXmlSerializerTestProtoFile.cs index 3d818a6082..c0e53348c2 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestXmlSerializerTestProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestXmlSerializerTestProtoFile.cs @@ -261,7 +261,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestXmlChild prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -271,21 +271,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestXmlChild(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestXmlChild cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestXmlChild result = new TestXmlChild(); + bool builderIsReadOnly; + TestXmlChild result; + + private TestXmlChild PrepareBuilder() { + if (builderIsReadOnly) { + TestXmlChild original = result; + result = new TestXmlChild(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestXmlChild MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestXmlChild(); + result = DefaultInstance ?? new TestXmlChild(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -297,13 +324,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestXmlChild BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.options_.MakeReadOnly(); - TestXmlChild returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -317,6 +343,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestXmlChild other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestXmlChild.DefaultInstance) return this; + PrepareBuilder(); if (other.options_.Count != 0) { base.AddRange(other.options_, result.options_); } @@ -332,6 +359,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -394,7 +422,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList OptionsList { - get { return result.options_; } + get { return PrepareBuilder().options_; } } public int OptionsCount { get { return result.OptionsCount; } @@ -403,18 +431,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetOptions(index); } public Builder SetOptions(int index, global::Google.ProtocolBuffers.TestProtos.EnumOptions value) { + PrepareBuilder(); result.options_[index] = value; return this; } public Builder AddOptions(global::Google.ProtocolBuffers.TestProtos.EnumOptions value) { + PrepareBuilder(); result.options_.Add(value); return this; } public Builder AddRangeOptions(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.options_); return this; } public Builder ClearOptions() { + PrepareBuilder(); result.options_.Clear(); return this; } @@ -428,11 +460,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetBinary(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasBinary = true; result.binary_ = value; return this; } public Builder ClearBinary() { + PrepareBuilder(); result.hasBinary = false; result.binary_ = pb::ByteString.Empty; return this; @@ -529,7 +563,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestXmlNoFields prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -539,21 +573,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestXmlNoFields(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestXmlNoFields cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestXmlNoFields result = new TestXmlNoFields(); + bool builderIsReadOnly; + TestXmlNoFields result; + + private TestXmlNoFields PrepareBuilder() { + if (builderIsReadOnly) { + TestXmlNoFields original = result; + result = new TestXmlNoFields(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestXmlNoFields MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestXmlNoFields(); + result = DefaultInstance ?? new TestXmlNoFields(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -565,12 +626,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestXmlNoFields BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestXmlNoFields returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -584,6 +644,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestXmlNoFields other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestXmlNoFields.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -593,6 +654,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -743,7 +805,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestXmlRescursive prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -753,21 +815,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestXmlRescursive(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestXmlRescursive cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestXmlRescursive result = new TestXmlRescursive(); + bool builderIsReadOnly; + TestXmlRescursive result; + + private TestXmlRescursive PrepareBuilder() { + if (builderIsReadOnly) { + TestXmlRescursive original = result; + result = new TestXmlRescursive(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestXmlRescursive MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestXmlRescursive(); + result = DefaultInstance ?? new TestXmlRescursive(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -779,12 +868,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestXmlRescursive BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestXmlRescursive returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -798,6 +886,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestXmlRescursive other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestXmlRescursive.DefaultInstance) return this; + PrepareBuilder(); if (other.HasChild) { MergeChild(other.Child); } @@ -810,6 +899,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -871,18 +961,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetChild(global::Google.ProtocolBuffers.TestProtos.TestXmlRescursive value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasChild = true; result.child_ = value; return this; } public Builder SetChild(global::Google.ProtocolBuffers.TestProtos.TestXmlRescursive.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasChild = true; result.child_ = builderForValue.Build(); return this; } public Builder MergeChild(global::Google.ProtocolBuffers.TestProtos.TestXmlRescursive value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasChild && result.child_ != global::Google.ProtocolBuffers.TestProtos.TestXmlRescursive.DefaultInstance) { result.child_ = global::Google.ProtocolBuffers.TestProtos.TestXmlRescursive.CreateBuilder(result.child_).MergeFrom(value).BuildPartial(); @@ -893,6 +986,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearChild() { + PrepareBuilder(); result.hasChild = false; result.child_ = global::Google.ProtocolBuffers.TestProtos.TestXmlRescursive.DefaultInstance; return this; @@ -1062,7 +1156,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Children prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1072,21 +1166,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Children(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Children cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - Children result = new Children(); + bool builderIsReadOnly; + Children result; + + private Children PrepareBuilder() { + if (builderIsReadOnly) { + Children original = result; + result = new Children(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Children MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Children(); + result = DefaultInstance ?? new Children(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1098,13 +1219,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Children BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.options_.MakeReadOnly(); - Children returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1118,6 +1238,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(Children other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestXmlMessage.Types.Children.DefaultInstance) return this; + PrepareBuilder(); if (other.options_.Count != 0) { base.AddRange(other.options_, result.options_); } @@ -1133,6 +1254,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1195,7 +1317,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList OptionsList { - get { return result.options_; } + get { return PrepareBuilder().options_; } } public int OptionsCount { get { return result.OptionsCount; } @@ -1204,18 +1326,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetOptions(index); } public Builder SetOptions(int index, global::Google.ProtocolBuffers.TestProtos.EnumOptions value) { + PrepareBuilder(); result.options_[index] = value; return this; } public Builder AddOptions(global::Google.ProtocolBuffers.TestProtos.EnumOptions value) { + PrepareBuilder(); result.options_.Add(value); return this; } public Builder AddRangeOptions(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.options_); return this; } public Builder ClearOptions() { + PrepareBuilder(); result.options_.Clear(); return this; } @@ -1229,11 +1355,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetBinary(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasBinary = true; result.binary_ = value; return this; } public Builder ClearBinary() { + PrepareBuilder(); result.hasBinary = false; result.binary_ = pb::ByteString.Empty; return this; @@ -1438,7 +1566,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestXmlMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1448,21 +1576,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestXmlMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestXmlMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestXmlMessage result = new TestXmlMessage(); + bool builderIsReadOnly; + TestXmlMessage result; + + private TestXmlMessage PrepareBuilder() { + if (builderIsReadOnly) { + TestXmlMessage original = result; + result = new TestXmlMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestXmlMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestXmlMessage(); + result = DefaultInstance ?? new TestXmlMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1474,15 +1629,14 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestXmlMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.numbers_.MakeReadOnly(); result.textlines_.MakeReadOnly(); result.children_.MakeReadOnly(); - TestXmlMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1496,6 +1650,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestXmlMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestXmlMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasNumber) { Number = other.Number; } @@ -1527,6 +1682,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1612,18 +1768,20 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNumber(value); } } public Builder SetNumber(long value) { + PrepareBuilder(); result.hasNumber = true; result.number_ = value; return this; } public Builder ClearNumber() { + PrepareBuilder(); result.hasNumber = false; result.number_ = 0L; return this; } public pbc::IPopsicleList NumbersList { - get { return result.numbers_; } + get { return PrepareBuilder().numbers_; } } public int NumbersCount { get { return result.NumbersCount; } @@ -1632,18 +1790,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetNumbers(index); } public Builder SetNumbers(int index, int value) { + PrepareBuilder(); result.numbers_[index] = value; return this; } public Builder AddNumbers(int value) { + PrepareBuilder(); result.numbers_.Add(value); return this; } public Builder AddRangeNumbers(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.numbers_); return this; } public Builder ClearNumbers() { + PrepareBuilder(); result.numbers_.Clear(); return this; } @@ -1657,18 +1819,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetText(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasText = true; result.text_ = value; return this; } public Builder ClearText() { + PrepareBuilder(); result.hasText = false; result.text_ = ""; return this; } public pbc::IPopsicleList TextlinesList { - get { return result.textlines_; } + get { return PrepareBuilder().textlines_; } } public int TextlinesCount { get { return result.TextlinesCount; } @@ -1678,19 +1842,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetTextlines(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.textlines_[index] = value; return this; } public Builder AddTextlines(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.textlines_.Add(value); return this; } public Builder AddRangeTextlines(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.textlines_); return this; } public Builder ClearTextlines() { + PrepareBuilder(); result.textlines_.Clear(); return this; } @@ -1703,11 +1871,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetValid(value); } } public Builder SetValid(bool value) { + PrepareBuilder(); result.hasValid = true; result.valid_ = value; return this; } public Builder ClearValid() { + PrepareBuilder(); result.hasValid = false; result.valid_ = false; return this; @@ -1722,18 +1892,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetChild(global::Google.ProtocolBuffers.TestProtos.TestXmlChild value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasChild = true; result.child_ = value; return this; } public Builder SetChild(global::Google.ProtocolBuffers.TestProtos.TestXmlChild.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasChild = true; result.child_ = builderForValue.Build(); return this; } public Builder MergeChild(global::Google.ProtocolBuffers.TestProtos.TestXmlChild value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasChild && result.child_ != global::Google.ProtocolBuffers.TestProtos.TestXmlChild.DefaultInstance) { result.child_ = global::Google.ProtocolBuffers.TestProtos.TestXmlChild.CreateBuilder(result.child_).MergeFrom(value).BuildPartial(); @@ -1744,13 +1917,14 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearChild() { + PrepareBuilder(); result.hasChild = false; result.child_ = global::Google.ProtocolBuffers.TestProtos.TestXmlChild.DefaultInstance; return this; } public pbc::IPopsicleList ChildrenList { - get { return result.children_; } + get { return PrepareBuilder().children_; } } public int ChildrenCount { get { return result.ChildrenCount; } @@ -1760,29 +1934,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetChildren(int index, global::Google.ProtocolBuffers.TestProtos.TestXmlMessage.Types.Children value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.children_[index] = value; return this; } public Builder SetChildren(int index, global::Google.ProtocolBuffers.TestProtos.TestXmlMessage.Types.Children.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.children_[index] = builderForValue.Build(); return this; } public Builder AddChildren(global::Google.ProtocolBuffers.TestProtos.TestXmlMessage.Types.Children value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.children_.Add(value); return this; } public Builder AddChildren(global::Google.ProtocolBuffers.TestProtos.TestXmlMessage.Types.Children.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.children_.Add(builderForValue.Build()); return this; } public Builder AddRangeChildren(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.children_); return this; } public Builder ClearChildren() { + PrepareBuilder(); result.children_.Clear(); return this; } @@ -1895,7 +2075,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestXmlExtension prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1905,21 +2085,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestXmlExtension(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestXmlExtension cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestXmlExtension result = new TestXmlExtension(); + bool builderIsReadOnly; + TestXmlExtension result; + + private TestXmlExtension PrepareBuilder() { + if (builderIsReadOnly) { + TestXmlExtension original = result; + result = new TestXmlExtension(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestXmlExtension MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestXmlExtension(); + result = DefaultInstance ?? new TestXmlExtension(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1931,12 +2138,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestXmlExtension BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestXmlExtension returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1950,6 +2156,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestXmlExtension other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestXmlExtension.DefaultInstance) return this; + PrepareBuilder(); if (other.HasNumber) { Number = other.Number; } @@ -1962,6 +2169,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -2017,11 +2225,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNumber(value); } } public Builder SetNumber(int value) { + PrepareBuilder(); result.hasNumber = true; result.number_ = value; return this; } public Builder ClearNumber() { + PrepareBuilder(); result.hasNumber = false; result.number_ = 0; return this; diff --git a/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs b/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs index 853b0e7d09..0d9109a265 100644 --- a/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs +++ b/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs @@ -415,7 +415,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(CSharpFileOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -425,21 +425,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new CSharpFileOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(CSharpFileOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + CSharpFileOptions result; - CSharpFileOptions result = new CSharpFileOptions(); + private CSharpFileOptions PrepareBuilder() { + if (builderIsReadOnly) { + CSharpFileOptions original = result; + result = new CSharpFileOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override CSharpFileOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new CSharpFileOptions(); + result = DefaultInstance ?? new CSharpFileOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -451,12 +478,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override CSharpFileOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - CSharpFileOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -470,6 +496,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(CSharpFileOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.CSharpFileOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasNamespace) { Namespace = other.Namespace; } @@ -518,6 +545,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -630,11 +658,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetNamespace(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasNamespace = true; result.namespace_ = value; return this; } public Builder ClearNamespace() { + PrepareBuilder(); result.hasNamespace = false; result.namespace_ = ""; return this; @@ -649,11 +679,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetUmbrellaClassname(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasUmbrellaClassname = true; result.umbrellaClassname_ = value; return this; } public Builder ClearUmbrellaClassname() { + PrepareBuilder(); result.hasUmbrellaClassname = false; result.umbrellaClassname_ = ""; return this; @@ -667,11 +699,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetPublicClasses(value); } } public Builder SetPublicClasses(bool value) { + PrepareBuilder(); result.hasPublicClasses = true; result.publicClasses_ = value; return this; } public Builder ClearPublicClasses() { + PrepareBuilder(); result.hasPublicClasses = false; result.publicClasses_ = true; return this; @@ -685,11 +719,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetMultipleFiles(value); } } public Builder SetMultipleFiles(bool value) { + PrepareBuilder(); result.hasMultipleFiles = true; result.multipleFiles_ = value; return this; } public Builder ClearMultipleFiles() { + PrepareBuilder(); result.hasMultipleFiles = false; result.multipleFiles_ = false; return this; @@ -703,11 +739,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetNestClasses(value); } } public Builder SetNestClasses(bool value) { + PrepareBuilder(); result.hasNestClasses = true; result.nestClasses_ = value; return this; } public Builder ClearNestClasses() { + PrepareBuilder(); result.hasNestClasses = false; result.nestClasses_ = false; return this; @@ -721,11 +759,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetCodeContracts(value); } } public Builder SetCodeContracts(bool value) { + PrepareBuilder(); result.hasCodeContracts = true; result.codeContracts_ = value; return this; } public Builder ClearCodeContracts() { + PrepareBuilder(); result.hasCodeContracts = false; result.codeContracts_ = false; return this; @@ -739,11 +779,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetExpandNamespaceDirectories(value); } } public Builder SetExpandNamespaceDirectories(bool value) { + PrepareBuilder(); result.hasExpandNamespaceDirectories = true; result.expandNamespaceDirectories_ = value; return this; } public Builder ClearExpandNamespaceDirectories() { + PrepareBuilder(); result.hasExpandNamespaceDirectories = false; result.expandNamespaceDirectories_ = false; return this; @@ -757,11 +799,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetClsCompliance(value); } } public Builder SetClsCompliance(bool value) { + PrepareBuilder(); result.hasClsCompliance = true; result.clsCompliance_ = value; return this; } public Builder ClearClsCompliance() { + PrepareBuilder(); result.hasClsCompliance = false; result.clsCompliance_ = true; return this; @@ -776,11 +820,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetFileExtension(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasFileExtension = true; result.fileExtension_ = value; return this; } public Builder ClearFileExtension() { + PrepareBuilder(); result.hasFileExtension = false; result.fileExtension_ = ".cs"; return this; @@ -795,11 +841,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetUmbrellaNamespace(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasUmbrellaNamespace = true; result.umbrellaNamespace_ = value; return this; } public Builder ClearUmbrellaNamespace() { + PrepareBuilder(); result.hasUmbrellaNamespace = false; result.umbrellaNamespace_ = ""; return this; @@ -814,11 +862,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetOutputDirectory(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOutputDirectory = true; result.outputDirectory_ = value; return this; } public Builder ClearOutputDirectory() { + PrepareBuilder(); result.hasOutputDirectory = false; result.outputDirectory_ = "."; return this; @@ -832,11 +882,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetIgnoreGoogleProtobuf(value); } } public Builder SetIgnoreGoogleProtobuf(bool value) { + PrepareBuilder(); result.hasIgnoreGoogleProtobuf = true; result.ignoreGoogleProtobuf_ = value; return this; } public Builder ClearIgnoreGoogleProtobuf() { + PrepareBuilder(); result.hasIgnoreGoogleProtobuf = false; result.ignoreGoogleProtobuf_ = false; return this; @@ -850,11 +902,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetServiceGeneratorType(value); } } public Builder SetServiceGeneratorType(global::Google.ProtocolBuffers.DescriptorProtos.CSharpServiceType value) { + PrepareBuilder(); result.hasServiceGeneratorType = true; result.serviceGeneratorType_ = value; return this; } public Builder ClearServiceGeneratorType() { + PrepareBuilder(); result.hasServiceGeneratorType = false; result.serviceGeneratorType_ = global::Google.ProtocolBuffers.DescriptorProtos.CSharpServiceType.NONE; return this; @@ -967,7 +1021,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(CSharpFieldOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -977,21 +1031,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new CSharpFieldOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(CSharpFieldOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + CSharpFieldOptions result; - CSharpFieldOptions result = new CSharpFieldOptions(); + private CSharpFieldOptions PrepareBuilder() { + if (builderIsReadOnly) { + CSharpFieldOptions original = result; + result = new CSharpFieldOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override CSharpFieldOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new CSharpFieldOptions(); + result = DefaultInstance ?? new CSharpFieldOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1003,12 +1084,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override CSharpFieldOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - CSharpFieldOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1022,6 +1102,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(CSharpFieldOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.CSharpFieldOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasPropertyName) { PropertyName = other.PropertyName; } @@ -1034,6 +1115,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1090,11 +1172,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetPropertyName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasPropertyName = true; result.propertyName_ = value; return this; } public Builder ClearPropertyName() { + PrepareBuilder(); result.hasPropertyName = false; result.propertyName_ = ""; return this; @@ -1207,7 +1291,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(CSharpServiceOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1217,21 +1301,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new CSharpServiceOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(CSharpServiceOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + CSharpServiceOptions result; - CSharpServiceOptions result = new CSharpServiceOptions(); + private CSharpServiceOptions PrepareBuilder() { + if (builderIsReadOnly) { + CSharpServiceOptions original = result; + result = new CSharpServiceOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override CSharpServiceOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new CSharpServiceOptions(); + result = DefaultInstance ?? new CSharpServiceOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1243,12 +1354,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override CSharpServiceOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - CSharpServiceOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1262,6 +1372,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(CSharpServiceOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.CSharpServiceOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasInterfaceId) { InterfaceId = other.InterfaceId; } @@ -1274,6 +1385,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1330,11 +1442,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetInterfaceId(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasInterfaceId = true; result.interfaceId_ = value; return this; } public Builder ClearInterfaceId() { + PrepareBuilder(); result.hasInterfaceId = false; result.interfaceId_ = ""; return this; @@ -1447,7 +1561,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(CSharpMethodOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1457,21 +1571,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new CSharpMethodOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(CSharpMethodOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + CSharpMethodOptions result; - CSharpMethodOptions result = new CSharpMethodOptions(); + private CSharpMethodOptions PrepareBuilder() { + if (builderIsReadOnly) { + CSharpMethodOptions original = result; + result = new CSharpMethodOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override CSharpMethodOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new CSharpMethodOptions(); + result = DefaultInstance ?? new CSharpMethodOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1483,12 +1624,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override CSharpMethodOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - CSharpMethodOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1502,6 +1642,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(CSharpMethodOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.CSharpMethodOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasDispatchId) { DispatchId = other.DispatchId; } @@ -1514,6 +1655,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1569,11 +1711,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetDispatchId(value); } } public Builder SetDispatchId(int value) { + PrepareBuilder(); result.hasDispatchId = true; result.dispatchId_ = value; return this; } public Builder ClearDispatchId() { + PrepareBuilder(); result.hasDispatchId = false; result.dispatchId_ = 0; return this; diff --git a/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs b/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs index 5b48cde198..631ec21fb7 100644 --- a/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs +++ b/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs @@ -336,7 +336,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(FileDescriptorSet prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -346,21 +346,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new FileDescriptorSet(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(FileDescriptorSet cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + FileDescriptorSet result; - FileDescriptorSet result = new FileDescriptorSet(); + private FileDescriptorSet PrepareBuilder() { + if (builderIsReadOnly) { + FileDescriptorSet original = result; + result = new FileDescriptorSet(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override FileDescriptorSet MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new FileDescriptorSet(); + result = DefaultInstance ?? new FileDescriptorSet(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -372,13 +399,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override FileDescriptorSet BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.file_.MakeReadOnly(); - FileDescriptorSet returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -392,6 +418,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(FileDescriptorSet other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorSet.DefaultInstance) return this; + PrepareBuilder(); if (other.file_.Count != 0) { base.AddRange(other.file_, result.file_); } @@ -404,6 +431,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -452,7 +480,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public pbc::IPopsicleList FileList { - get { return result.file_; } + get { return PrepareBuilder().file_; } } public int FileCount { get { return result.FileCount; } @@ -462,29 +490,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetFile(int index, global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.file_[index] = value; return this; } public Builder SetFile(int index, global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.file_[index] = builderForValue.Build(); return this; } public Builder AddFile(global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.file_.Add(value); return this; } public Builder AddFile(global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.file_.Add(builderForValue.Build()); return this; } public Builder AddRangeFile(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.file_); return this; } public Builder ClearFile() { + PrepareBuilder(); result.file_.Clear(); return this; } @@ -738,7 +772,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(FileDescriptorProto prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -748,21 +782,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new FileDescriptorProto(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(FileDescriptorProto cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - FileDescriptorProto result = new FileDescriptorProto(); + bool builderIsReadOnly; + FileDescriptorProto result; + + private FileDescriptorProto PrepareBuilder() { + if (builderIsReadOnly) { + FileDescriptorProto original = result; + result = new FileDescriptorProto(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override FileDescriptorProto MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new FileDescriptorProto(); + result = DefaultInstance ?? new FileDescriptorProto(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -774,17 +835,16 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override FileDescriptorProto BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.dependency_.MakeReadOnly(); result.messageType_.MakeReadOnly(); result.enumType_.MakeReadOnly(); result.service_.MakeReadOnly(); result.extension_.MakeReadOnly(); - FileDescriptorProto returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -798,6 +858,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(FileDescriptorProto other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto.DefaultInstance) return this; + PrepareBuilder(); if (other.HasName) { Name = other.Name; } @@ -831,6 +892,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -920,11 +982,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -939,18 +1003,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetPackage(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasPackage = true; result.package_ = value; return this; } public Builder ClearPackage() { + PrepareBuilder(); result.hasPackage = false; result.package_ = ""; return this; } public pbc::IPopsicleList DependencyList { - get { return result.dependency_; } + get { return PrepareBuilder().dependency_; } } public int DependencyCount { get { return result.DependencyCount; } @@ -960,25 +1026,29 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetDependency(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.dependency_[index] = value; return this; } public Builder AddDependency(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.dependency_.Add(value); return this; } public Builder AddRangeDependency(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.dependency_); return this; } public Builder ClearDependency() { + PrepareBuilder(); result.dependency_.Clear(); return this; } public pbc::IPopsicleList MessageTypeList { - get { return result.messageType_; } + get { return PrepareBuilder().messageType_; } } public int MessageTypeCount { get { return result.MessageTypeCount; } @@ -988,35 +1058,41 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetMessageType(int index, global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.messageType_[index] = value; return this; } public Builder SetMessageType(int index, global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.messageType_[index] = builderForValue.Build(); return this; } public Builder AddMessageType(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.messageType_.Add(value); return this; } public Builder AddMessageType(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.messageType_.Add(builderForValue.Build()); return this; } public Builder AddRangeMessageType(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.messageType_); return this; } public Builder ClearMessageType() { + PrepareBuilder(); result.messageType_.Clear(); return this; } public pbc::IPopsicleList EnumTypeList { - get { return result.enumType_; } + get { return PrepareBuilder().enumType_; } } public int EnumTypeCount { get { return result.EnumTypeCount; } @@ -1026,35 +1102,41 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetEnumType(int index, global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.enumType_[index] = value; return this; } public Builder SetEnumType(int index, global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.enumType_[index] = builderForValue.Build(); return this; } public Builder AddEnumType(global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.enumType_.Add(value); return this; } public Builder AddEnumType(global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.enumType_.Add(builderForValue.Build()); return this; } public Builder AddRangeEnumType(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.enumType_); return this; } public Builder ClearEnumType() { + PrepareBuilder(); result.enumType_.Clear(); return this; } public pbc::IPopsicleList ServiceList { - get { return result.service_; } + get { return PrepareBuilder().service_; } } public int ServiceCount { get { return result.ServiceCount; } @@ -1064,35 +1146,41 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetService(int index, global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.service_[index] = value; return this; } public Builder SetService(int index, global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.service_[index] = builderForValue.Build(); return this; } public Builder AddService(global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.service_.Add(value); return this; } public Builder AddService(global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.service_.Add(builderForValue.Build()); return this; } public Builder AddRangeService(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.service_); return this; } public Builder ClearService() { + PrepareBuilder(); result.service_.Clear(); return this; } public pbc::IPopsicleList ExtensionList { - get { return result.extension_; } + get { return PrepareBuilder().extension_; } } public int ExtensionCount { get { return result.ExtensionCount; } @@ -1102,29 +1190,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetExtension(int index, global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.extension_[index] = value; return this; } public Builder SetExtension(int index, global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.extension_[index] = builderForValue.Build(); return this; } public Builder AddExtension(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.extension_.Add(value); return this; } public Builder AddExtension(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.extension_.Add(builderForValue.Build()); return this; } public Builder AddRangeExtension(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.extension_); return this; } public Builder ClearExtension() { + PrepareBuilder(); result.extension_.Clear(); return this; } @@ -1138,18 +1232,21 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.FileOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptions = true; result.options_ = value; return this; } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.FileOptions.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptions = true; result.options_ = builderForValue.Build(); return this; } public Builder MergeOptions(global::Google.ProtocolBuffers.DescriptorProtos.FileOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptions && result.options_ != global::Google.ProtocolBuffers.DescriptorProtos.FileOptions.DefaultInstance) { result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.FileOptions.CreateBuilder(result.options_).MergeFrom(value).BuildPartial(); @@ -1160,6 +1257,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder ClearOptions() { + PrepareBuilder(); result.hasOptions = false; result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.FileOptions.DefaultInstance; return this; @@ -1320,7 +1418,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ExtensionRange prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1330,21 +1428,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ExtensionRange(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ExtensionRange cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - ExtensionRange result = new ExtensionRange(); + bool builderIsReadOnly; + ExtensionRange result; + + private ExtensionRange PrepareBuilder() { + if (builderIsReadOnly) { + ExtensionRange original = result; + result = new ExtensionRange(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ExtensionRange MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ExtensionRange(); + result = DefaultInstance ?? new ExtensionRange(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1356,12 +1481,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override ExtensionRange BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ExtensionRange returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1375,6 +1499,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(ExtensionRange other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange.DefaultInstance) return this; + PrepareBuilder(); if (other.HasStart) { Start = other.Start; } @@ -1390,6 +1515,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1449,11 +1575,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetStart(value); } } public Builder SetStart(int value) { + PrepareBuilder(); result.hasStart = true; result.start_ = value; return this; } public Builder ClearStart() { + PrepareBuilder(); result.hasStart = false; result.start_ = 0; return this; @@ -1467,11 +1595,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetEnd(value); } } public Builder SetEnd(int value) { + PrepareBuilder(); result.hasEnd = true; result.end_ = value; return this; } public Builder ClearEnd() { + PrepareBuilder(); result.hasEnd = false; result.end_ = 0; return this; @@ -1681,7 +1811,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(DescriptorProto prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1691,21 +1821,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new DescriptorProto(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(DescriptorProto cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + DescriptorProto result; + + private DescriptorProto PrepareBuilder() { + if (builderIsReadOnly) { + DescriptorProto original = result; + result = new DescriptorProto(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - DescriptorProto result = new DescriptorProto(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override DescriptorProto MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new DescriptorProto(); + result = DefaultInstance ?? new DescriptorProto(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1717,17 +1874,16 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override DescriptorProto BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.field_.MakeReadOnly(); result.extension_.MakeReadOnly(); result.nestedType_.MakeReadOnly(); result.enumType_.MakeReadOnly(); result.extensionRange_.MakeReadOnly(); - DescriptorProto returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1741,6 +1897,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(DescriptorProto other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.DefaultInstance) return this; + PrepareBuilder(); if (other.HasName) { Name = other.Name; } @@ -1771,6 +1928,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1856,18 +2014,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; } public pbc::IPopsicleList FieldList { - get { return result.field_; } + get { return PrepareBuilder().field_; } } public int FieldCount { get { return result.FieldCount; } @@ -1877,35 +2037,41 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetField(int index, global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field_[index] = value; return this; } public Builder SetField(int index, global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.field_[index] = builderForValue.Build(); return this; } public Builder AddField(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.field_.Add(value); return this; } public Builder AddField(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.field_.Add(builderForValue.Build()); return this; } public Builder AddRangeField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.field_); return this; } public Builder ClearField() { + PrepareBuilder(); result.field_.Clear(); return this; } public pbc::IPopsicleList ExtensionList { - get { return result.extension_; } + get { return PrepareBuilder().extension_; } } public int ExtensionCount { get { return result.ExtensionCount; } @@ -1915,35 +2081,41 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetExtension(int index, global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.extension_[index] = value; return this; } public Builder SetExtension(int index, global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.extension_[index] = builderForValue.Build(); return this; } public Builder AddExtension(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.extension_.Add(value); return this; } public Builder AddExtension(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.extension_.Add(builderForValue.Build()); return this; } public Builder AddRangeExtension(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.extension_); return this; } public Builder ClearExtension() { + PrepareBuilder(); result.extension_.Clear(); return this; } public pbc::IPopsicleList NestedTypeList { - get { return result.nestedType_; } + get { return PrepareBuilder().nestedType_; } } public int NestedTypeCount { get { return result.NestedTypeCount; } @@ -1953,35 +2125,41 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetNestedType(int index, global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.nestedType_[index] = value; return this; } public Builder SetNestedType(int index, global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.nestedType_[index] = builderForValue.Build(); return this; } public Builder AddNestedType(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.nestedType_.Add(value); return this; } public Builder AddNestedType(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.nestedType_.Add(builderForValue.Build()); return this; } public Builder AddRangeNestedType(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.nestedType_); return this; } public Builder ClearNestedType() { + PrepareBuilder(); result.nestedType_.Clear(); return this; } public pbc::IPopsicleList EnumTypeList { - get { return result.enumType_; } + get { return PrepareBuilder().enumType_; } } public int EnumTypeCount { get { return result.EnumTypeCount; } @@ -1991,35 +2169,41 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetEnumType(int index, global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.enumType_[index] = value; return this; } public Builder SetEnumType(int index, global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.enumType_[index] = builderForValue.Build(); return this; } public Builder AddEnumType(global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.enumType_.Add(value); return this; } public Builder AddEnumType(global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.enumType_.Add(builderForValue.Build()); return this; } public Builder AddRangeEnumType(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.enumType_); return this; } public Builder ClearEnumType() { + PrepareBuilder(); result.enumType_.Clear(); return this; } public pbc::IPopsicleList ExtensionRangeList { - get { return result.extensionRange_; } + get { return PrepareBuilder().extensionRange_; } } public int ExtensionRangeCount { get { return result.ExtensionRangeCount; } @@ -2029,29 +2213,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetExtensionRange(int index, global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.extensionRange_[index] = value; return this; } public Builder SetExtensionRange(int index, global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.extensionRange_[index] = builderForValue.Build(); return this; } public Builder AddExtensionRange(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.extensionRange_.Add(value); return this; } public Builder AddExtensionRange(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.extensionRange_.Add(builderForValue.Build()); return this; } public Builder AddRangeExtensionRange(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.extensionRange_); return this; } public Builder ClearExtensionRange() { + PrepareBuilder(); result.extensionRange_.Clear(); return this; } @@ -2065,18 +2255,21 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.MessageOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptions = true; result.options_ = value; return this; } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.MessageOptions.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptions = true; result.options_ = builderForValue.Build(); return this; } public Builder MergeOptions(global::Google.ProtocolBuffers.DescriptorProtos.MessageOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptions && result.options_ != global::Google.ProtocolBuffers.DescriptorProtos.MessageOptions.DefaultInstance) { result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.MessageOptions.CreateBuilder(result.options_).MergeFrom(value).BuildPartial(); @@ -2087,6 +2280,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder ClearOptions() { + PrepareBuilder(); result.hasOptions = false; result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.MessageOptions.DefaultInstance; return this; @@ -2353,7 +2547,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(FieldDescriptorProto prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -2363,21 +2557,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new FieldDescriptorProto(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(FieldDescriptorProto cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + FieldDescriptorProto result; - FieldDescriptorProto result = new FieldDescriptorProto(); + private FieldDescriptorProto PrepareBuilder() { + if (builderIsReadOnly) { + FieldDescriptorProto original = result; + result = new FieldDescriptorProto(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override FieldDescriptorProto MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new FieldDescriptorProto(); + result = DefaultInstance ?? new FieldDescriptorProto(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -2389,12 +2610,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override FieldDescriptorProto BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - FieldDescriptorProto returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -2408,6 +2628,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(FieldDescriptorProto other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.DefaultInstance) return this; + PrepareBuilder(); if (other.HasName) { Name = other.Name; } @@ -2441,6 +2662,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -2546,11 +2768,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -2564,11 +2788,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetNumber(value); } } public Builder SetNumber(int value) { + PrepareBuilder(); result.hasNumber = true; result.number_ = value; return this; } public Builder ClearNumber() { + PrepareBuilder(); result.hasNumber = false; result.number_ = 0; return this; @@ -2582,11 +2808,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetLabel(value); } } public Builder SetLabel(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Types.Label value) { + PrepareBuilder(); result.hasLabel = true; result.label_ = value; return this; } public Builder ClearLabel() { + PrepareBuilder(); result.hasLabel = false; result.label_ = global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Types.Label.LABEL_OPTIONAL; return this; @@ -2600,11 +2828,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetType(value); } } public Builder SetType(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Types.Type value) { + PrepareBuilder(); result.hasType = true; result.type_ = value; return this; } public Builder ClearType() { + PrepareBuilder(); result.hasType = false; result.type_ = global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Types.Type.TYPE_DOUBLE; return this; @@ -2619,11 +2849,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetTypeName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasTypeName = true; result.typeName_ = value; return this; } public Builder ClearTypeName() { + PrepareBuilder(); result.hasTypeName = false; result.typeName_ = ""; return this; @@ -2638,11 +2870,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetExtendee(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasExtendee = true; result.extendee_ = value; return this; } public Builder ClearExtendee() { + PrepareBuilder(); result.hasExtendee = false; result.extendee_ = ""; return this; @@ -2657,11 +2891,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetDefaultValue(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultValue = true; result.defaultValue_ = value; return this; } public Builder ClearDefaultValue() { + PrepareBuilder(); result.hasDefaultValue = false; result.defaultValue_ = ""; return this; @@ -2676,18 +2912,21 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptions = true; result.options_ = value; return this; } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptions = true; result.options_ = builderForValue.Build(); return this; } public Builder MergeOptions(global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptions && result.options_ != global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions.DefaultInstance) { result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions.CreateBuilder(result.options_).MergeFrom(value).BuildPartial(); @@ -2698,6 +2937,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder ClearOptions() { + PrepareBuilder(); result.hasOptions = false; result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions.DefaultInstance; return this; @@ -2850,7 +3090,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(EnumDescriptorProto prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -2860,21 +3100,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new EnumDescriptorProto(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(EnumDescriptorProto cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + EnumDescriptorProto result; + + private EnumDescriptorProto PrepareBuilder() { + if (builderIsReadOnly) { + EnumDescriptorProto original = result; + result = new EnumDescriptorProto(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - EnumDescriptorProto result = new EnumDescriptorProto(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override EnumDescriptorProto MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new EnumDescriptorProto(); + result = DefaultInstance ?? new EnumDescriptorProto(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -2886,13 +3153,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override EnumDescriptorProto BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.value_.MakeReadOnly(); - EnumDescriptorProto returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -2906,6 +3172,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(EnumDescriptorProto other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.DefaultInstance) return this; + PrepareBuilder(); if (other.HasName) { Name = other.Name; } @@ -2924,6 +3191,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -2993,18 +3261,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; } public pbc::IPopsicleList ValueList { - get { return result.value_; } + get { return PrepareBuilder().value_; } } public int ValueCount { get { return result.ValueCount; } @@ -3014,29 +3284,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetValue(int index, global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.value_[index] = value; return this; } public Builder SetValue(int index, global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.value_[index] = builderForValue.Build(); return this; } public Builder AddValue(global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.value_.Add(value); return this; } public Builder AddValue(global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.value_.Add(builderForValue.Build()); return this; } public Builder AddRangeValue(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.value_); return this; } public Builder ClearValue() { + PrepareBuilder(); result.value_.Clear(); return this; } @@ -3050,18 +3326,21 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.EnumOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptions = true; result.options_ = value; return this; } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.EnumOptions.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptions = true; result.options_ = builderForValue.Build(); return this; } public Builder MergeOptions(global::Google.ProtocolBuffers.DescriptorProtos.EnumOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptions && result.options_ != global::Google.ProtocolBuffers.DescriptorProtos.EnumOptions.DefaultInstance) { result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.EnumOptions.CreateBuilder(result.options_).MergeFrom(value).BuildPartial(); @@ -3072,6 +3351,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder ClearOptions() { + PrepareBuilder(); result.hasOptions = false; result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.EnumOptions.DefaultInstance; return this; @@ -3219,7 +3499,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(EnumValueDescriptorProto prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3229,21 +3509,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new EnumValueDescriptorProto(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(EnumValueDescriptorProto cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - EnumValueDescriptorProto result = new EnumValueDescriptorProto(); + bool builderIsReadOnly; + EnumValueDescriptorProto result; + + private EnumValueDescriptorProto PrepareBuilder() { + if (builderIsReadOnly) { + EnumValueDescriptorProto original = result; + result = new EnumValueDescriptorProto(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override EnumValueDescriptorProto MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new EnumValueDescriptorProto(); + result = DefaultInstance ?? new EnumValueDescriptorProto(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3255,12 +3562,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override EnumValueDescriptorProto BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - EnumValueDescriptorProto returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -3274,6 +3580,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(EnumValueDescriptorProto other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto.DefaultInstance) return this; + PrepareBuilder(); if (other.HasName) { Name = other.Name; } @@ -3292,6 +3599,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -3361,11 +3669,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -3379,11 +3689,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetNumber(value); } } public Builder SetNumber(int value) { + PrepareBuilder(); result.hasNumber = true; result.number_ = value; return this; } public Builder ClearNumber() { + PrepareBuilder(); result.hasNumber = false; result.number_ = 0; return this; @@ -3398,18 +3710,21 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.EnumValueOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptions = true; result.options_ = value; return this; } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.EnumValueOptions.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptions = true; result.options_ = builderForValue.Build(); return this; } public Builder MergeOptions(global::Google.ProtocolBuffers.DescriptorProtos.EnumValueOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptions && result.options_ != global::Google.ProtocolBuffers.DescriptorProtos.EnumValueOptions.DefaultInstance) { result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.EnumValueOptions.CreateBuilder(result.options_).MergeFrom(value).BuildPartial(); @@ -3420,6 +3735,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder ClearOptions() { + PrepareBuilder(); result.hasOptions = false; result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.EnumValueOptions.DefaultInstance; return this; @@ -3572,7 +3888,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ServiceDescriptorProto prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3582,21 +3898,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ServiceDescriptorProto(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ServiceDescriptorProto cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ServiceDescriptorProto result; + + private ServiceDescriptorProto PrepareBuilder() { + if (builderIsReadOnly) { + ServiceDescriptorProto original = result; + result = new ServiceDescriptorProto(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - ServiceDescriptorProto result = new ServiceDescriptorProto(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ServiceDescriptorProto MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ServiceDescriptorProto(); + result = DefaultInstance ?? new ServiceDescriptorProto(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3608,13 +3951,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override ServiceDescriptorProto BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.method_.MakeReadOnly(); - ServiceDescriptorProto returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -3628,6 +3970,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(ServiceDescriptorProto other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto.DefaultInstance) return this; + PrepareBuilder(); if (other.HasName) { Name = other.Name; } @@ -3646,6 +3989,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -3715,18 +4059,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; } public pbc::IPopsicleList MethodList { - get { return result.method_; } + get { return PrepareBuilder().method_; } } public int MethodCount { get { return result.MethodCount; } @@ -3736,29 +4082,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetMethod(int index, global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.method_[index] = value; return this; } public Builder SetMethod(int index, global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.method_[index] = builderForValue.Build(); return this; } public Builder AddMethod(global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.method_.Add(value); return this; } public Builder AddMethod(global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.method_.Add(builderForValue.Build()); return this; } public Builder AddRangeMethod(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.method_); return this; } public Builder ClearMethod() { + PrepareBuilder(); result.method_.Clear(); return this; } @@ -3772,18 +4124,21 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.ServiceOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptions = true; result.options_ = value; return this; } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.ServiceOptions.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptions = true; result.options_ = builderForValue.Build(); return this; } public Builder MergeOptions(global::Google.ProtocolBuffers.DescriptorProtos.ServiceOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptions && result.options_ != global::Google.ProtocolBuffers.DescriptorProtos.ServiceOptions.DefaultInstance) { result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.ServiceOptions.CreateBuilder(result.options_).MergeFrom(value).BuildPartial(); @@ -3794,6 +4149,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder ClearOptions() { + PrepareBuilder(); result.hasOptions = false; result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.ServiceOptions.DefaultInstance; return this; @@ -3957,7 +4313,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(MethodDescriptorProto prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3967,21 +4323,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new MethodDescriptorProto(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(MethodDescriptorProto cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + MethodDescriptorProto result; + + private MethodDescriptorProto PrepareBuilder() { + if (builderIsReadOnly) { + MethodDescriptorProto original = result; + result = new MethodDescriptorProto(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - MethodDescriptorProto result = new MethodDescriptorProto(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override MethodDescriptorProto MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new MethodDescriptorProto(); + result = DefaultInstance ?? new MethodDescriptorProto(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3993,12 +4376,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override MethodDescriptorProto BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - MethodDescriptorProto returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -4012,6 +4394,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(MethodDescriptorProto other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto.DefaultInstance) return this; + PrepareBuilder(); if (other.HasName) { Name = other.Name; } @@ -4033,6 +4416,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -4106,11 +4490,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -4125,11 +4511,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetInputType(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasInputType = true; result.inputType_ = value; return this; } public Builder ClearInputType() { + PrepareBuilder(); result.hasInputType = false; result.inputType_ = ""; return this; @@ -4144,11 +4532,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetOutputType(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOutputType = true; result.outputType_ = value; return this; } public Builder ClearOutputType() { + PrepareBuilder(); result.hasOutputType = false; result.outputType_ = ""; return this; @@ -4163,18 +4553,21 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.MethodOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptions = true; result.options_ = value; return this; } public Builder SetOptions(global::Google.ProtocolBuffers.DescriptorProtos.MethodOptions.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptions = true; result.options_ = builderForValue.Build(); return this; } public Builder MergeOptions(global::Google.ProtocolBuffers.DescriptorProtos.MethodOptions value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptions && result.options_ != global::Google.ProtocolBuffers.DescriptorProtos.MethodOptions.DefaultInstance) { result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.MethodOptions.CreateBuilder(result.options_).MergeFrom(value).BuildPartial(); @@ -4185,6 +4578,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder ClearOptions() { + PrepareBuilder(); result.hasOptions = false; result.options_ = global::Google.ProtocolBuffers.DescriptorProtos.MethodOptions.DefaultInstance; return this; @@ -4434,7 +4828,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(FileOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -4444,21 +4838,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new FileOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(FileOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + FileOptions result; - FileOptions result = new FileOptions(); + private FileOptions PrepareBuilder() { + if (builderIsReadOnly) { + FileOptions original = result; + result = new FileOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override FileOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new FileOptions(); + result = DefaultInstance ?? new FileOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -4470,13 +4891,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override FileOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.uninterpretedOption_.MakeReadOnly(); - FileOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -4490,6 +4910,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(FileOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.FileOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasJavaPackage) { JavaPackage = other.JavaPackage; } @@ -4524,6 +4945,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -4616,11 +5038,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetJavaPackage(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasJavaPackage = true; result.javaPackage_ = value; return this; } public Builder ClearJavaPackage() { + PrepareBuilder(); result.hasJavaPackage = false; result.javaPackage_ = ""; return this; @@ -4635,11 +5059,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetJavaOuterClassname(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasJavaOuterClassname = true; result.javaOuterClassname_ = value; return this; } public Builder ClearJavaOuterClassname() { + PrepareBuilder(); result.hasJavaOuterClassname = false; result.javaOuterClassname_ = ""; return this; @@ -4653,11 +5079,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetJavaMultipleFiles(value); } } public Builder SetJavaMultipleFiles(bool value) { + PrepareBuilder(); result.hasJavaMultipleFiles = true; result.javaMultipleFiles_ = value; return this; } public Builder ClearJavaMultipleFiles() { + PrepareBuilder(); result.hasJavaMultipleFiles = false; result.javaMultipleFiles_ = false; return this; @@ -4671,11 +5099,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetOptimizeFor(value); } } public Builder SetOptimizeFor(global::Google.ProtocolBuffers.DescriptorProtos.FileOptions.Types.OptimizeMode value) { + PrepareBuilder(); result.hasOptimizeFor = true; result.optimizeFor_ = value; return this; } public Builder ClearOptimizeFor() { + PrepareBuilder(); result.hasOptimizeFor = false; result.optimizeFor_ = global::Google.ProtocolBuffers.DescriptorProtos.FileOptions.Types.OptimizeMode.SPEED; return this; @@ -4689,11 +5119,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetCcGenericServices(value); } } public Builder SetCcGenericServices(bool value) { + PrepareBuilder(); result.hasCcGenericServices = true; result.ccGenericServices_ = value; return this; } public Builder ClearCcGenericServices() { + PrepareBuilder(); result.hasCcGenericServices = false; result.ccGenericServices_ = true; return this; @@ -4707,11 +5139,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetJavaGenericServices(value); } } public Builder SetJavaGenericServices(bool value) { + PrepareBuilder(); result.hasJavaGenericServices = true; result.javaGenericServices_ = value; return this; } public Builder ClearJavaGenericServices() { + PrepareBuilder(); result.hasJavaGenericServices = false; result.javaGenericServices_ = true; return this; @@ -4725,18 +5159,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetPyGenericServices(value); } } public Builder SetPyGenericServices(bool value) { + PrepareBuilder(); result.hasPyGenericServices = true; result.pyGenericServices_ = value; return this; } public Builder ClearPyGenericServices() { + PrepareBuilder(); result.hasPyGenericServices = false; result.pyGenericServices_ = true; return this; } public pbc::IPopsicleList UninterpretedOptionList { - get { return result.uninterpretedOption_; } + get { return PrepareBuilder().uninterpretedOption_; } } public int UninterpretedOptionCount { get { return result.UninterpretedOptionCount; } @@ -4746,29 +5182,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_[index] = value; return this; } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_[index] = builderForValue.Build(); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_.Add(value); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_.Add(builderForValue.Build()); return this; } public Builder AddRangeUninterpretedOption(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.uninterpretedOption_); return this; } public Builder ClearUninterpretedOption() { + PrepareBuilder(); result.uninterpretedOption_.Clear(); return this; } @@ -4921,7 +5363,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(MessageOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -4931,21 +5373,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new MessageOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(MessageOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - MessageOptions result = new MessageOptions(); + bool builderIsReadOnly; + MessageOptions result; + + private MessageOptions PrepareBuilder() { + if (builderIsReadOnly) { + MessageOptions original = result; + result = new MessageOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override MessageOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new MessageOptions(); + result = DefaultInstance ?? new MessageOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -4957,13 +5426,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override MessageOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.uninterpretedOption_.MakeReadOnly(); - MessageOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -4977,6 +5445,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(MessageOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.MessageOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasMessageSetWireFormat) { MessageSetWireFormat = other.MessageSetWireFormat; } @@ -4996,6 +5465,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -5059,11 +5529,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetMessageSetWireFormat(value); } } public Builder SetMessageSetWireFormat(bool value) { + PrepareBuilder(); result.hasMessageSetWireFormat = true; result.messageSetWireFormat_ = value; return this; } public Builder ClearMessageSetWireFormat() { + PrepareBuilder(); result.hasMessageSetWireFormat = false; result.messageSetWireFormat_ = false; return this; @@ -5077,18 +5549,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetNoStandardDescriptorAccessor(value); } } public Builder SetNoStandardDescriptorAccessor(bool value) { + PrepareBuilder(); result.hasNoStandardDescriptorAccessor = true; result.noStandardDescriptorAccessor_ = value; return this; } public Builder ClearNoStandardDescriptorAccessor() { + PrepareBuilder(); result.hasNoStandardDescriptorAccessor = false; result.noStandardDescriptorAccessor_ = false; return this; } public pbc::IPopsicleList UninterpretedOptionList { - get { return result.uninterpretedOption_; } + get { return PrepareBuilder().uninterpretedOption_; } } public int UninterpretedOptionCount { get { return result.UninterpretedOptionCount; } @@ -5098,29 +5572,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_[index] = value; return this; } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_[index] = builderForValue.Build(); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_.Add(value); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_.Add(builderForValue.Build()); return this; } public Builder AddRangeUninterpretedOption(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.uninterpretedOption_); return this; } public Builder ClearUninterpretedOption() { + PrepareBuilder(); result.uninterpretedOption_.Clear(); return this; } @@ -5321,7 +5801,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(FieldOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -5331,21 +5811,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new FieldOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(FieldOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - FieldOptions result = new FieldOptions(); + bool builderIsReadOnly; + FieldOptions result; + + private FieldOptions PrepareBuilder() { + if (builderIsReadOnly) { + FieldOptions original = result; + result = new FieldOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override FieldOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new FieldOptions(); + result = DefaultInstance ?? new FieldOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -5357,13 +5864,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override FieldOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.uninterpretedOption_.MakeReadOnly(); - FieldOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -5377,6 +5883,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(FieldOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasCtype) { Ctype = other.Ctype; } @@ -5402,6 +5909,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -5481,11 +5989,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetCtype(value); } } public Builder SetCtype(global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions.Types.CType value) { + PrepareBuilder(); result.hasCtype = true; result.ctype_ = value; return this; } public Builder ClearCtype() { + PrepareBuilder(); result.hasCtype = false; result.ctype_ = global::Google.ProtocolBuffers.DescriptorProtos.FieldOptions.Types.CType.STRING; return this; @@ -5499,11 +6009,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetPacked(value); } } public Builder SetPacked(bool value) { + PrepareBuilder(); result.hasPacked = true; result.packed_ = value; return this; } public Builder ClearPacked() { + PrepareBuilder(); result.hasPacked = false; result.packed_ = false; return this; @@ -5517,11 +6029,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetDeprecated(value); } } public Builder SetDeprecated(bool value) { + PrepareBuilder(); result.hasDeprecated = true; result.deprecated_ = value; return this; } public Builder ClearDeprecated() { + PrepareBuilder(); result.hasDeprecated = false; result.deprecated_ = false; return this; @@ -5536,18 +6050,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetExperimentalMapKey(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasExperimentalMapKey = true; result.experimentalMapKey_ = value; return this; } public Builder ClearExperimentalMapKey() { + PrepareBuilder(); result.hasExperimentalMapKey = false; result.experimentalMapKey_ = ""; return this; } public pbc::IPopsicleList UninterpretedOptionList { - get { return result.uninterpretedOption_; } + get { return PrepareBuilder().uninterpretedOption_; } } public int UninterpretedOptionCount { get { return result.UninterpretedOptionCount; } @@ -5557,29 +6073,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_[index] = value; return this; } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_[index] = builderForValue.Build(); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_.Add(value); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_.Add(builderForValue.Build()); return this; } public Builder AddRangeUninterpretedOption(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.uninterpretedOption_); return this; } public Builder ClearUninterpretedOption() { + PrepareBuilder(); result.uninterpretedOption_.Clear(); return this; } @@ -5700,7 +6222,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(EnumOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -5710,21 +6232,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new EnumOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(EnumOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + EnumOptions result; + + private EnumOptions PrepareBuilder() { + if (builderIsReadOnly) { + EnumOptions original = result; + result = new EnumOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - EnumOptions result = new EnumOptions(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override EnumOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new EnumOptions(); + result = DefaultInstance ?? new EnumOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -5736,13 +6285,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override EnumOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.uninterpretedOption_.MakeReadOnly(); - EnumOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -5756,6 +6304,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(EnumOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.EnumOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.uninterpretedOption_.Count != 0) { base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_); } @@ -5769,6 +6318,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -5817,7 +6367,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public pbc::IPopsicleList UninterpretedOptionList { - get { return result.uninterpretedOption_; } + get { return PrepareBuilder().uninterpretedOption_; } } public int UninterpretedOptionCount { get { return result.UninterpretedOptionCount; } @@ -5827,29 +6377,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_[index] = value; return this; } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_[index] = builderForValue.Build(); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_.Add(value); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_.Add(builderForValue.Build()); return this; } public Builder AddRangeUninterpretedOption(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.uninterpretedOption_); return this; } public Builder ClearUninterpretedOption() { + PrepareBuilder(); result.uninterpretedOption_.Clear(); return this; } @@ -5970,7 +6526,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(EnumValueOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -5980,21 +6536,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new EnumValueOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(EnumValueOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + EnumValueOptions result; - EnumValueOptions result = new EnumValueOptions(); + private EnumValueOptions PrepareBuilder() { + if (builderIsReadOnly) { + EnumValueOptions original = result; + result = new EnumValueOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override EnumValueOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new EnumValueOptions(); + result = DefaultInstance ?? new EnumValueOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6006,13 +6589,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override EnumValueOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.uninterpretedOption_.MakeReadOnly(); - EnumValueOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6026,6 +6608,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(EnumValueOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.EnumValueOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.uninterpretedOption_.Count != 0) { base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_); } @@ -6039,6 +6622,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6087,7 +6671,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public pbc::IPopsicleList UninterpretedOptionList { - get { return result.uninterpretedOption_; } + get { return PrepareBuilder().uninterpretedOption_; } } public int UninterpretedOptionCount { get { return result.UninterpretedOptionCount; } @@ -6097,29 +6681,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_[index] = value; return this; } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_[index] = builderForValue.Build(); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_.Add(value); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_.Add(builderForValue.Build()); return this; } public Builder AddRangeUninterpretedOption(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.uninterpretedOption_); return this; } public Builder ClearUninterpretedOption() { + PrepareBuilder(); result.uninterpretedOption_.Clear(); return this; } @@ -6240,7 +6830,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ServiceOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6250,21 +6840,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ServiceOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ServiceOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ServiceOptions result; + + private ServiceOptions PrepareBuilder() { + if (builderIsReadOnly) { + ServiceOptions original = result; + result = new ServiceOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - ServiceOptions result = new ServiceOptions(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ServiceOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ServiceOptions(); + result = DefaultInstance ?? new ServiceOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6276,13 +6893,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override ServiceOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.uninterpretedOption_.MakeReadOnly(); - ServiceOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6296,6 +6912,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(ServiceOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.ServiceOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.uninterpretedOption_.Count != 0) { base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_); } @@ -6309,6 +6926,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6357,7 +6975,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public pbc::IPopsicleList UninterpretedOptionList { - get { return result.uninterpretedOption_; } + get { return PrepareBuilder().uninterpretedOption_; } } public int UninterpretedOptionCount { get { return result.UninterpretedOptionCount; } @@ -6367,29 +6985,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_[index] = value; return this; } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_[index] = builderForValue.Build(); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_.Add(value); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_.Add(builderForValue.Build()); return this; } public Builder AddRangeUninterpretedOption(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.uninterpretedOption_); return this; } public Builder ClearUninterpretedOption() { + PrepareBuilder(); result.uninterpretedOption_.Clear(); return this; } @@ -6510,7 +7134,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(MethodOptions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6520,21 +7144,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new MethodOptions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(MethodOptions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - MethodOptions result = new MethodOptions(); + bool builderIsReadOnly; + MethodOptions result; + + private MethodOptions PrepareBuilder() { + if (builderIsReadOnly) { + MethodOptions original = result; + result = new MethodOptions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override MethodOptions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new MethodOptions(); + result = DefaultInstance ?? new MethodOptions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6546,13 +7197,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override MethodOptions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.uninterpretedOption_.MakeReadOnly(); - MethodOptions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6566,6 +7216,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(MethodOptions other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.MethodOptions.DefaultInstance) return this; + PrepareBuilder(); if (other.uninterpretedOption_.Count != 0) { base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_); } @@ -6579,6 +7230,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6627,7 +7279,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public pbc::IPopsicleList UninterpretedOptionList { - get { return result.uninterpretedOption_; } + get { return PrepareBuilder().uninterpretedOption_; } } public int UninterpretedOptionCount { get { return result.UninterpretedOptionCount; } @@ -6637,29 +7289,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_[index] = value; return this; } public Builder SetUninterpretedOption(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_[index] = builderForValue.Build(); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.uninterpretedOption_.Add(value); return this; } public Builder AddUninterpretedOption(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.uninterpretedOption_.Add(builderForValue.Build()); return this; } public Builder AddRangeUninterpretedOption(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.uninterpretedOption_); return this; } public Builder ClearUninterpretedOption() { + PrepareBuilder(); result.uninterpretedOption_.Clear(); return this; } @@ -6821,7 +7479,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(NamePart prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6831,21 +7489,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new NamePart(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(NamePart cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + NamePart result; + + private NamePart PrepareBuilder() { + if (builderIsReadOnly) { + NamePart original = result; + result = new NamePart(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - NamePart result = new NamePart(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override NamePart MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new NamePart(); + result = DefaultInstance ?? new NamePart(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6857,12 +7542,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override NamePart BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - NamePart returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6876,6 +7560,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(NamePart other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart.DefaultInstance) return this; + PrepareBuilder(); if (other.HasNamePart_) { NamePart_ = other.NamePart_; } @@ -6891,6 +7576,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6951,11 +7637,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetNamePart_(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasNamePart_ = true; result.namePart_ = value; return this; } public Builder ClearNamePart_() { + PrepareBuilder(); result.hasNamePart_ = false; result.namePart_ = ""; return this; @@ -6969,11 +7657,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetIsExtension(value); } } public Builder SetIsExtension(bool value) { + PrepareBuilder(); result.hasIsExtension = true; result.isExtension_ = value; return this; } public Builder ClearIsExtension() { + PrepareBuilder(); result.hasIsExtension = false; result.isExtension_ = false; return this; @@ -7148,7 +7838,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(UninterpretedOption prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -7158,21 +7848,48 @@ namespace Google.ProtocolBuffers.DescriptorProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new UninterpretedOption(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(UninterpretedOption cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + UninterpretedOption result; + + private UninterpretedOption PrepareBuilder() { + if (builderIsReadOnly) { + UninterpretedOption original = result; + result = new UninterpretedOption(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - UninterpretedOption result = new UninterpretedOption(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override UninterpretedOption MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new UninterpretedOption(); + result = DefaultInstance ?? new UninterpretedOption(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -7184,13 +7901,12 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override UninterpretedOption BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.name_.MakeReadOnly(); - UninterpretedOption returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -7204,6 +7920,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(UninterpretedOption other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.DefaultInstance) return this; + PrepareBuilder(); if (other.name_.Count != 0) { base.AddRange(other.name_, result.name_); } @@ -7231,6 +7948,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -7299,7 +8017,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public pbc::IPopsicleList NameList { - get { return result.name_; } + get { return PrepareBuilder().name_; } } public int NameCount { get { return result.NameCount; } @@ -7309,29 +8027,35 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetName(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.name_[index] = value; return this; } public Builder SetName(int index, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.name_[index] = builderForValue.Build(); return this; } public Builder AddName(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.name_.Add(value); return this; } public Builder AddName(global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.name_.Add(builderForValue.Build()); return this; } public Builder AddRangeName(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.name_); return this; } public Builder ClearName() { + PrepareBuilder(); result.name_.Clear(); return this; } @@ -7345,11 +8069,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetIdentifierValue(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasIdentifierValue = true; result.identifierValue_ = value; return this; } public Builder ClearIdentifierValue() { + PrepareBuilder(); result.hasIdentifierValue = false; result.identifierValue_ = ""; return this; @@ -7365,11 +8091,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } [global::System.CLSCompliant(false)] public Builder SetPositiveIntValue(ulong value) { + PrepareBuilder(); result.hasPositiveIntValue = true; result.positiveIntValue_ = value; return this; } public Builder ClearPositiveIntValue() { + PrepareBuilder(); result.hasPositiveIntValue = false; result.positiveIntValue_ = 0UL; return this; @@ -7383,11 +8111,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetNegativeIntValue(value); } } public Builder SetNegativeIntValue(long value) { + PrepareBuilder(); result.hasNegativeIntValue = true; result.negativeIntValue_ = value; return this; } public Builder ClearNegativeIntValue() { + PrepareBuilder(); result.hasNegativeIntValue = false; result.negativeIntValue_ = 0L; return this; @@ -7401,11 +8131,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { set { SetDoubleValue(value); } } public Builder SetDoubleValue(double value) { + PrepareBuilder(); result.hasDoubleValue = true; result.doubleValue_ = value; return this; } public Builder ClearDoubleValue() { + PrepareBuilder(); result.hasDoubleValue = false; result.doubleValue_ = 0D; return this; @@ -7420,11 +8152,13 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public Builder SetStringValue(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasStringValue = true; result.stringValue_ = value; return this; } public Builder ClearStringValue() { + PrepareBuilder(); result.hasStringValue = false; result.stringValue_ = pb::ByteString.Empty; return this; diff --git a/src/ProtocolBuffers/GeneratedBuilder.cs b/src/ProtocolBuffers/GeneratedBuilder.cs index 94948e495c..2472d2b0ae 100644 --- a/src/ProtocolBuffers/GeneratedBuilder.cs +++ b/src/ProtocolBuffers/GeneratedBuilder.cs @@ -58,12 +58,7 @@ namespace Google.ProtocolBuffers protected internal FieldAccessorTable InternalFieldAccessors { - get { return MessageBeingBuilt.FieldAccessorsFromBuilder; } - } - - public override bool IsInitialized - { - get { return MessageBeingBuilt.IsInitialized; } + get { return DefaultInstanceForType.FieldAccessorsFromBuilder; } } public override IDictionary AllFields @@ -123,7 +118,7 @@ namespace Google.ProtocolBuffers public override MessageDescriptor DescriptorForType { - get { return MessageBeingBuilt.DescriptorForType; } + get { return DefaultInstanceForType.DescriptorForType; } } public override int GetRepeatedFieldCount(FieldDescriptor field) @@ -230,7 +225,7 @@ namespace Google.ProtocolBuffers public override TMessage Build() { // If the message is null, we'll throw a more appropriate exception in BuildPartial. - if (MessageBeingBuilt != null && !IsInitialized) + if (!IsInitialized) { throw new UninitializedMessageException(MessageBeingBuilt); } diff --git a/src/ProtocolBuffers/GeneratedBuilderLite.cs b/src/ProtocolBuffers/GeneratedBuilderLite.cs index cd2b8395c0..165edc10a1 100644 --- a/src/ProtocolBuffers/GeneratedBuilderLite.cs +++ b/src/ProtocolBuffers/GeneratedBuilderLite.cs @@ -61,11 +61,6 @@ namespace Google.ProtocolBuffers public abstract TBuilder MergeFrom(TMessage other); - public override bool IsInitialized - { - get { return MessageBeingBuilt.IsInitialized; } - } - /// /// Adds all of the specified values to the given collection. /// @@ -122,7 +117,7 @@ namespace Google.ProtocolBuffers public override TMessage Build() { // If the message is null, we'll throw a more appropriate exception in BuildPartial. - if (MessageBeingBuilt != null && !IsInitialized) + if (!IsInitialized) { throw new UninitializedMessageException(MessageBeingBuilt); } diff --git a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasFullProtoFile.cs b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasFullProtoFile.cs index a9ee77724b..563cea5ed2 100644 --- a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasFullProtoFile.cs +++ b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasFullProtoFile.cs @@ -241,7 +241,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(PhoneNumber prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -251,21 +251,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new PhoneNumber(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(PhoneNumber cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + PhoneNumber result; - PhoneNumber result = new PhoneNumber(); + private PhoneNumber PrepareBuilder() { + if (builderIsReadOnly) { + PhoneNumber original = result; + result = new PhoneNumber(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override PhoneNumber MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new PhoneNumber(); + result = DefaultInstance ?? new PhoneNumber(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -277,12 +304,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override PhoneNumber BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - PhoneNumber returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -295,11 +321,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetNumber(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasNumber = true; result.number_ = value; return this; } public Builder ClearNumber() { + PrepareBuilder(); result.hasNumber = false; result.number_ = ""; return this; @@ -313,11 +341,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetType(value); } } public Builder SetType(global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.PhoneType value) { + PrepareBuilder(); result.hasType = true; result.type_ = value; return this; } public Builder ClearType() { + PrepareBuilder(); result.hasType = false; result.type_ = global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.PhoneType.HOME; return this; @@ -438,7 +468,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Addresses prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -448,21 +478,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Addresses(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Addresses cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + Addresses result; + + private Addresses PrepareBuilder() { + if (builderIsReadOnly) { + Addresses original = result; + result = new Addresses(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - Addresses result = new Addresses(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Addresses MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Addresses(); + result = DefaultInstance ?? new Addresses(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -474,12 +531,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Addresses BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - Addresses returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -492,11 +548,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetAddress(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasAddress = true; result.address_ = value; return this; } public Builder ClearAddress() { + PrepareBuilder(); result.hasAddress = false; result.address_ = ""; return this; @@ -511,11 +569,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetAddress2(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasAddress2 = true; result.address2_ = value; return this; } public Builder ClearAddress2() { + PrepareBuilder(); result.hasAddress2 = false; result.address2_ = ""; return this; @@ -530,11 +590,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetCity(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasCity = true; result.city_ = value; return this; } public Builder ClearCity() { + PrepareBuilder(); result.hasCity = false; result.city_ = ""; return this; @@ -549,11 +611,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetState(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasState = true; result.state_ = value; return this; } public Builder ClearState() { + PrepareBuilder(); result.hasState = false; result.state_ = ""; return this; @@ -569,11 +633,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetZip(uint value) { + PrepareBuilder(); result.hasZip = true; result.zip_ = value; return this; } public Builder ClearZip() { + PrepareBuilder(); result.hasZip = false; result.zip_ = 0; return this; @@ -687,7 +753,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestInteropPerson prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -697,21 +763,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestInteropPerson(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestInteropPerson cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestInteropPerson result = new TestInteropPerson(); + bool builderIsReadOnly; + TestInteropPerson result; + + private TestInteropPerson PrepareBuilder() { + if (builderIsReadOnly) { + TestInteropPerson original = result; + result = new TestInteropPerson(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestInteropPerson MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestInteropPerson(); + result = DefaultInstance ?? new TestInteropPerson(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -723,15 +816,14 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestInteropPerson BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.codes_.MakeReadOnly(); result.phone_.MakeReadOnly(); result.addresses_.MakeReadOnly(); - TestInteropPerson returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -744,11 +836,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -762,11 +856,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetId(value); } } public Builder SetId(int value) { + PrepareBuilder(); result.hasId = true; result.id_ = value; return this; } public Builder ClearId() { + PrepareBuilder(); result.hasId = false; result.id_ = 0; return this; @@ -781,18 +877,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetEmail(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasEmail = true; result.email_ = value; return this; } public Builder ClearEmail() { + PrepareBuilder(); result.hasEmail = false; result.email_ = ""; return this; } public pbc::IPopsicleList CodesList { - get { return result.codes_; } + get { return PrepareBuilder().codes_; } } public int CodesCount { get { return result.CodesCount; } @@ -801,24 +899,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetCodes(index); } public Builder SetCodes(int index, int value) { + PrepareBuilder(); result.codes_[index] = value; return this; } public Builder AddCodes(int value) { + PrepareBuilder(); result.codes_.Add(value); return this; } public Builder AddRangeCodes(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.codes_); return this; } public Builder ClearCodes() { + PrepareBuilder(); result.codes_.Clear(); return this; } public pbc::IPopsicleList PhoneList { - get { return result.phone_; } + get { return PrepareBuilder().phone_; } } public int PhoneCount { get { return result.PhoneCount; } @@ -828,35 +930,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetPhone(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.PhoneNumber value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.phone_[index] = value; return this; } public Builder SetPhone(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.PhoneNumber.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.phone_[index] = builderForValue.Build(); return this; } public Builder AddPhone(global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.PhoneNumber value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.phone_.Add(value); return this; } public Builder AddPhone(global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.PhoneNumber.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.phone_.Add(builderForValue.Build()); return this; } public Builder AddRangePhone(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.phone_); return this; } public Builder ClearPhone() { + PrepareBuilder(); result.phone_.Clear(); return this; } public pbc::IPopsicleList AddressesList { - get { return result.addresses_; } + get { return PrepareBuilder().addresses_; } } public int AddressesCount { get { return result.AddressesCount; } @@ -866,29 +974,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetAddresses(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.Addresses value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.addresses_[index] = value; return this; } public Builder SetAddresses(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.Addresses.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.addresses_[index] = builderForValue.Build(); return this; } public Builder AddAddresses(global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.Addresses value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.addresses_.Add(value); return this; } public Builder AddAddresses(global::Google.ProtocolBuffers.TestProtos.TestInteropPerson.Types.Addresses.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.addresses_.Add(builderForValue.Build()); return this; } public Builder AddRangeAddresses(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.addresses_); return this; } public Builder ClearAddresses() { + PrepareBuilder(); result.addresses_.Clear(); return this; } @@ -967,7 +1081,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestInteropEmployeeId prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -977,21 +1091,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestInteropEmployeeId(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestInteropEmployeeId cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestInteropEmployeeId result; + + private TestInteropEmployeeId PrepareBuilder() { + if (builderIsReadOnly) { + TestInteropEmployeeId original = result; + result = new TestInteropEmployeeId(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestInteropEmployeeId result = new TestInteropEmployeeId(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestInteropEmployeeId MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestInteropEmployeeId(); + result = DefaultInstance ?? new TestInteropEmployeeId(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1003,12 +1144,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestInteropEmployeeId BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestInteropEmployeeId returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -1021,11 +1161,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetNumber(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasNumber = true; result.number_ = value; return this; } public Builder ClearNumber() { + PrepareBuilder(); result.hasNumber = false; result.number_ = ""; return this; @@ -1147,7 +1289,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SubA prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1157,21 +1299,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SubA(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SubA cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + SubA result; - SubA result = new SubA(); + private SubA PrepareBuilder() { + if (builderIsReadOnly) { + SubA original = result; + result = new SubA(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SubA MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SubA(); + result = DefaultInstance ?? new SubA(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1183,13 +1352,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SubA BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.values_.MakeReadOnly(); - SubA returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -1201,18 +1369,20 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetCount(value); } } public Builder SetCount(int value) { + PrepareBuilder(); result.hasCount = true; result.count_ = value; return this; } public Builder ClearCount() { + PrepareBuilder(); result.hasCount = false; result.count_ = 0; return this; } public pbc::IPopsicleList ValuesList { - get { return result.values_; } + get { return PrepareBuilder().values_; } } public int ValuesCount { get { return result.ValuesCount; } @@ -1222,19 +1392,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetValues(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.values_[index] = value; return this; } public Builder AddValues(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.values_.Add(value); return this; } public Builder AddRangeValues(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.values_); return this; } public Builder ClearValues() { + PrepareBuilder(); result.values_.Clear(); return this; } @@ -1321,7 +1495,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMissingFieldsA prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1331,21 +1505,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMissingFieldsA(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMissingFieldsA cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestMissingFieldsA result; + + private TestMissingFieldsA PrepareBuilder() { + if (builderIsReadOnly) { + TestMissingFieldsA original = result; + result = new TestMissingFieldsA(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestMissingFieldsA result = new TestMissingFieldsA(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMissingFieldsA MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMissingFieldsA(); + result = DefaultInstance ?? new TestMissingFieldsA(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1357,12 +1558,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMissingFieldsA BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMissingFieldsA returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -1375,11 +1575,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -1393,11 +1595,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetId(value); } } public Builder SetId(int value) { + PrepareBuilder(); result.hasId = true; result.id_ = value; return this; } public Builder ClearId() { + PrepareBuilder(); result.hasId = false; result.id_ = 0; return this; @@ -1412,11 +1616,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetEmail(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasEmail = true; result.email_ = value; return this; } public Builder ClearEmail() { + PrepareBuilder(); result.hasEmail = false; result.email_ = ""; return this; @@ -1431,18 +1637,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetTestA(global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsA.Types.SubA value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasTestA = true; result.testA_ = value; return this; } public Builder SetTestA(global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsA.Types.SubA.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasTestA = true; result.testA_ = builderForValue.Build(); return this; } public Builder MergeTestA(global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsA.Types.SubA value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasTestA && result.testA_ != global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsA.Types.SubA.DefaultInstance) { result.testA_ = global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsA.Types.SubA.CreateBuilder(result.testA_).MergeFrom(value).BuildPartial(); @@ -1453,6 +1662,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearTestA() { + PrepareBuilder(); result.hasTestA = false; result.testA_ = global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsA.Types.SubA.DefaultInstance; return this; @@ -1564,7 +1774,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(SubB prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1574,21 +1784,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new SubB(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(SubB cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + SubB result; - SubB result = new SubB(); + private SubB PrepareBuilder() { + if (builderIsReadOnly) { + SubB original = result; + result = new SubB(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override SubB MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new SubB(); + result = DefaultInstance ?? new SubB(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1600,18 +1837,17 @@ namespace Google.ProtocolBuffers.TestProtos { } public override SubB BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.values_.MakeReadOnly(); - SubB returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public pbc::IPopsicleList ValuesList { - get { return result.values_; } + get { return PrepareBuilder().values_; } } public int ValuesCount { get { return result.ValuesCount; } @@ -1621,19 +1857,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetValues(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.values_[index] = value; return this; } public Builder AddValues(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.values_.Add(value); return this; } public Builder AddRangeValues(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.values_); return this; } public Builder ClearValues() { + PrepareBuilder(); result.values_.Clear(); return this; } @@ -1720,7 +1960,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMissingFieldsB prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1730,21 +1970,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMissingFieldsB(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMissingFieldsB cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestMissingFieldsB result; + + private TestMissingFieldsB PrepareBuilder() { + if (builderIsReadOnly) { + TestMissingFieldsB original = result; + result = new TestMissingFieldsB(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestMissingFieldsB result = new TestMissingFieldsB(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMissingFieldsB MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMissingFieldsB(); + result = DefaultInstance ?? new TestMissingFieldsB(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1756,12 +2023,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMissingFieldsB BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMissingFieldsB returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } @@ -1774,11 +2040,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -1792,11 +2060,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetId(value); } } public Builder SetId(int value) { + PrepareBuilder(); result.hasId = true; result.id_ = value; return this; } public Builder ClearId() { + PrepareBuilder(); result.hasId = false; result.id_ = 0; return this; @@ -1811,11 +2081,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetWebsite(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasWebsite = true; result.website_ = value; return this; } public Builder ClearWebsite() { + PrepareBuilder(); result.hasWebsite = false; result.website_ = ""; return this; @@ -1830,18 +2102,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetTestB(global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsB.Types.SubB value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasTestB = true; result.testB_ = value; return this; } public Builder SetTestB(global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsB.Types.SubB.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasTestB = true; result.testB_ = builderForValue.Build(); return this; } public Builder MergeTestB(global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsB.Types.SubB value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasTestB && result.testB_ != global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsB.Types.SubB.DefaultInstance) { result.testB_ = global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsB.Types.SubB.CreateBuilder(result.testB_).MergeFrom(value).BuildPartial(); @@ -1852,6 +2127,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearTestB() { + PrepareBuilder(); result.hasTestB = false; result.testB_ = global::Google.ProtocolBuffers.TestProtos.TestMissingFieldsB.Types.SubB.DefaultInstance; return this; diff --git a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs index bc214e2565..cbbc50db22 100644 --- a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs +++ b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs @@ -187,7 +187,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRequiredLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -197,21 +197,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRequiredLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRequiredLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestRequiredLite result; + + private TestRequiredLite PrepareBuilder() { + if (builderIsReadOnly) { + TestRequiredLite original = result; + result = new TestRequiredLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestRequiredLite result = new TestRequiredLite(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRequiredLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRequiredLite(); + result = DefaultInstance ?? new TestRequiredLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestRequiredLite DefaultInstanceForType { @@ -219,12 +246,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRequiredLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestRequiredLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -238,6 +264,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestRequiredLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestRequiredLite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasD) { D = other.D; } @@ -252,6 +279,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -302,11 +330,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetD(value); } } public Builder SetD(int value) { + PrepareBuilder(); result.hasD = true; result.d_ = value; return this; } public Builder ClearD() { + PrepareBuilder(); result.hasD = false; result.d_ = 0; return this; @@ -320,11 +350,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetEn(value); } } public Builder SetEn(global::Google.ProtocolBuffers.TestProtos.ExtraEnum value) { + PrepareBuilder(); result.hasEn = true; result.en_ = value; return this; } public Builder ClearEn() { + PrepareBuilder(); result.hasEn = false; result.en_ = global::Google.ProtocolBuffers.TestProtos.ExtraEnum.DEFAULT; return this; @@ -498,7 +530,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(PhoneNumber prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -508,21 +540,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new PhoneNumber(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(PhoneNumber cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - PhoneNumber result = new PhoneNumber(); + bool builderIsReadOnly; + PhoneNumber result; + + private PhoneNumber PrepareBuilder() { + if (builderIsReadOnly) { + PhoneNumber original = result; + result = new PhoneNumber(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override PhoneNumber MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new PhoneNumber(); + result = DefaultInstance ?? new PhoneNumber(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override PhoneNumber DefaultInstanceForType { @@ -530,12 +589,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override PhoneNumber BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - PhoneNumber returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -549,6 +607,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(PhoneNumber other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.DefaultInstance) return this; + PrepareBuilder(); if (other.HasNumber) { Number = other.Number; } @@ -563,6 +622,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -614,11 +674,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetNumber(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasNumber = true; result.number_ = value; return this; } public Builder ClearNumber() { + PrepareBuilder(); result.hasNumber = false; result.number_ = ""; return this; @@ -632,11 +694,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetType(value); } } public Builder SetType(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType value) { + PrepareBuilder(); result.hasType = true; result.type_ = value; return this; } public Builder ClearType() { + PrepareBuilder(); result.hasType = false; result.type_ = global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType.HOME; return this; @@ -839,7 +903,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Addresses prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -849,21 +913,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Addresses(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Addresses cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + Addresses result; - Addresses result = new Addresses(); + private Addresses PrepareBuilder() { + if (builderIsReadOnly) { + Addresses original = result; + result = new Addresses(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Addresses MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Addresses(); + result = DefaultInstance ?? new Addresses(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override Addresses DefaultInstanceForType { @@ -871,12 +962,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Addresses BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - Addresses returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -890,6 +980,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(Addresses other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.DefaultInstance) return this; + PrepareBuilder(); if (other.HasAddress) { Address = other.Address; } @@ -913,6 +1004,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -972,11 +1064,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetAddress(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasAddress = true; result.address_ = value; return this; } public Builder ClearAddress() { + PrepareBuilder(); result.hasAddress = false; result.address_ = ""; return this; @@ -991,11 +1085,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetAddress2(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasAddress2 = true; result.address2_ = value; return this; } public Builder ClearAddress2() { + PrepareBuilder(); result.hasAddress2 = false; result.address2_ = ""; return this; @@ -1010,11 +1106,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetCity(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasCity = true; result.city_ = value; return this; } public Builder ClearCity() { + PrepareBuilder(); result.hasCity = false; result.city_ = ""; return this; @@ -1029,11 +1127,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetState(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasState = true; result.state_ = value; return this; } public Builder ClearState() { + PrepareBuilder(); result.hasState = false; result.state_ = ""; return this; @@ -1049,11 +1149,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetZip(uint value) { + PrepareBuilder(); result.hasZip = true; result.zip_ = value; return this; } public Builder ClearZip() { + PrepareBuilder(); result.hasZip = false; result.zip_ = 0; return this; @@ -1290,7 +1392,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestInteropPersonLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1300,21 +1402,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestInteropPersonLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestInteropPersonLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestInteropPersonLite result = new TestInteropPersonLite(); + bool builderIsReadOnly; + TestInteropPersonLite result; + + private TestInteropPersonLite PrepareBuilder() { + if (builderIsReadOnly) { + TestInteropPersonLite original = result; + result = new TestInteropPersonLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestInteropPersonLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestInteropPersonLite(); + result = DefaultInstance ?? new TestInteropPersonLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestInteropPersonLite DefaultInstanceForType { @@ -1322,15 +1451,14 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestInteropPersonLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.codes_.MakeReadOnly(); result.phone_.MakeReadOnly(); result.addresses_.MakeReadOnly(); - TestInteropPersonLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -1344,6 +1472,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestInteropPersonLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasName) { Name = other.Name; } @@ -1371,6 +1500,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -1435,11 +1565,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetName(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasName = true; result.name_ = value; return this; } public Builder ClearName() { + PrepareBuilder(); result.hasName = false; result.name_ = ""; return this; @@ -1453,11 +1585,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetId(value); } } public Builder SetId(int value) { + PrepareBuilder(); result.hasId = true; result.id_ = value; return this; } public Builder ClearId() { + PrepareBuilder(); result.hasId = false; result.id_ = 0; return this; @@ -1472,18 +1606,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetEmail(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasEmail = true; result.email_ = value; return this; } public Builder ClearEmail() { + PrepareBuilder(); result.hasEmail = false; result.email_ = ""; return this; } public pbc::IPopsicleList CodesList { - get { return result.codes_; } + get { return PrepareBuilder().codes_; } } public int CodesCount { get { return result.CodesCount; } @@ -1492,24 +1628,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetCodes(index); } public Builder SetCodes(int index, int value) { + PrepareBuilder(); result.codes_[index] = value; return this; } public Builder AddCodes(int value) { + PrepareBuilder(); result.codes_.Add(value); return this; } public Builder AddRangeCodes(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.codes_); return this; } public Builder ClearCodes() { + PrepareBuilder(); result.codes_.Clear(); return this; } public pbc::IPopsicleList PhoneList { - get { return result.phone_; } + get { return PrepareBuilder().phone_; } } public int PhoneCount { get { return result.PhoneCount; } @@ -1519,35 +1659,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetPhone(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.phone_[index] = value; return this; } public Builder SetPhone(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.phone_[index] = builderForValue.Build(); return this; } public Builder AddPhone(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.phone_.Add(value); return this; } public Builder AddPhone(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.phone_.Add(builderForValue.Build()); return this; } public Builder AddRangePhone(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.phone_); return this; } public Builder ClearPhone() { + PrepareBuilder(); result.phone_.Clear(); return this; } public pbc::IPopsicleList AddressesList { - get { return result.addresses_; } + get { return PrepareBuilder().addresses_; } } public int AddressesCount { get { return result.AddressesCount; } @@ -1557,29 +1703,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetAddresses(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.addresses_[index] = value; return this; } public Builder SetAddresses(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.addresses_[index] = builderForValue.Build(); return this; } public Builder AddAddresses(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.addresses_.Add(value); return this; } public Builder AddAddresses(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.addresses_.Add(builderForValue.Build()); return this; } public Builder AddRangeAddresses(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.addresses_); return this; } public Builder ClearAddresses() { + PrepareBuilder(); result.addresses_.Clear(); return this; } @@ -1701,7 +1853,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestInteropEmployeeIdLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1711,21 +1863,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestInteropEmployeeIdLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestInteropEmployeeIdLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestInteropEmployeeIdLite result = new TestInteropEmployeeIdLite(); + bool builderIsReadOnly; + TestInteropEmployeeIdLite result; + + private TestInteropEmployeeIdLite PrepareBuilder() { + if (builderIsReadOnly) { + TestInteropEmployeeIdLite original = result; + result = new TestInteropEmployeeIdLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestInteropEmployeeIdLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestInteropEmployeeIdLite(); + result = DefaultInstance ?? new TestInteropEmployeeIdLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestInteropEmployeeIdLite DefaultInstanceForType { @@ -1733,12 +1912,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestInteropEmployeeIdLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestInteropEmployeeIdLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -1752,6 +1930,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestInteropEmployeeIdLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasNumber) { Number = other.Number; } @@ -1763,6 +1942,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -1806,11 +1986,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetNumber(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasNumber = true; result.number_ = value; return this; } public Builder ClearNumber() { + PrepareBuilder(); result.hasNumber = false; result.number_ = ""; return this; diff --git a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestImportLiteProtoFile.cs b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestImportLiteProtoFile.cs index a96833bef0..0df40f4248 100644 --- a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestImportLiteProtoFile.cs +++ b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestImportLiteProtoFile.cs @@ -150,7 +150,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ImportMessageLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -160,21 +160,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ImportMessageLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ImportMessageLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ImportMessageLite result; - ImportMessageLite result = new ImportMessageLite(); + private ImportMessageLite PrepareBuilder() { + if (builderIsReadOnly) { + ImportMessageLite original = result; + result = new ImportMessageLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ImportMessageLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ImportMessageLite(); + result = DefaultInstance ?? new ImportMessageLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override ImportMessageLite DefaultInstanceForType { @@ -182,12 +209,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ImportMessageLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ImportMessageLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -201,6 +227,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ImportMessageLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasD) { D = other.D; } @@ -212,6 +239,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -254,11 +282,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetD(value); } } public Builder SetD(int value) { + PrepareBuilder(); result.hasD = true; result.d_ = value; return this; } public Builder ClearD() { + PrepareBuilder(); result.hasD = false; result.d_ = 0; return this; diff --git a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestImportProtoFile.cs b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestImportProtoFile.cs index 5749c97f88..75e746a840 100644 --- a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestImportProtoFile.cs +++ b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestImportProtoFile.cs @@ -169,7 +169,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ImportMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -179,21 +179,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ImportMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ImportMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ImportMessage result; - ImportMessage result = new ImportMessage(); + private ImportMessage PrepareBuilder() { + if (builderIsReadOnly) { + ImportMessage original = result; + result = new ImportMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ImportMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ImportMessage(); + result = DefaultInstance ?? new ImportMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -205,12 +232,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ImportMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ImportMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -224,6 +250,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ImportMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasD) { D = other.D; } @@ -236,6 +263,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -291,11 +319,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetD(value); } } public Builder SetD(int value) { + PrepareBuilder(); result.hasD = true; result.d_ = value; return this; } public Builder ClearD() { + PrepareBuilder(); result.hasD = false; result.d_ = 0; return this; diff --git a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteImportNonLiteProtoFile.cs b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteImportNonLiteProtoFile.cs index 7c2836cdb3..5a6033a185 100644 --- a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteImportNonLiteProtoFile.cs +++ b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteImportNonLiteProtoFile.cs @@ -139,7 +139,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestLiteImportsNonlite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -149,21 +149,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestLiteImportsNonlite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestLiteImportsNonlite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestLiteImportsNonlite result; - TestLiteImportsNonlite result = new TestLiteImportsNonlite(); + private TestLiteImportsNonlite PrepareBuilder() { + if (builderIsReadOnly) { + TestLiteImportsNonlite original = result; + result = new TestLiteImportsNonlite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestLiteImportsNonlite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestLiteImportsNonlite(); + result = DefaultInstance ?? new TestLiteImportsNonlite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestLiteImportsNonlite DefaultInstanceForType { @@ -171,12 +198,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestLiteImportsNonlite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestLiteImportsNonlite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -190,6 +216,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestLiteImportsNonlite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasMessage) { MergeMessage(other.Message); } @@ -201,6 +228,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -249,18 +277,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMessage = true; result.message_ = value; return this; } public Builder SetMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasMessage = true; result.message_ = builderForValue.Build(); return this; } public Builder MergeMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasMessage && result.message_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance) { result.message_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.CreateBuilder(result.message_).MergeFrom(value).BuildPartial(); @@ -271,6 +302,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearMessage() { + PrepareBuilder(); result.hasMessage = false; result.message_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance; return this; diff --git a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteProtoFile.cs b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteProtoFile.cs index 78bed7e204..2592c83333 100644 --- a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteProtoFile.cs +++ b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteProtoFile.cs @@ -1367,7 +1367,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(NestedMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1377,21 +1377,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(NestedMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + NestedMessage result; + + private NestedMessage PrepareBuilder() { + if (builderIsReadOnly) { + NestedMessage original = result; + result = new NestedMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - NestedMessage result = new NestedMessage(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override NestedMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new NestedMessage(); + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override NestedMessage DefaultInstanceForType { @@ -1399,12 +1426,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override NestedMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - NestedMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -1418,6 +1444,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(NestedMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasBb) { Bb = other.Bb; } @@ -1429,6 +1456,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -1471,11 +1499,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetBb(value); } } public Builder SetBb(int value) { + PrepareBuilder(); result.hasBb = true; result.bb_ = value; return this; } public Builder ClearBb() { + PrepareBuilder(); result.hasBb = false; result.bb_ = 0; return this; @@ -1597,7 +1627,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OptionalGroup prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1607,21 +1637,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OptionalGroup(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OptionalGroup cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + OptionalGroup result; + + private OptionalGroup PrepareBuilder() { + if (builderIsReadOnly) { + OptionalGroup original = result; + result = new OptionalGroup(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - OptionalGroup result = new OptionalGroup(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OptionalGroup MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OptionalGroup(); + result = DefaultInstance ?? new OptionalGroup(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override OptionalGroup DefaultInstanceForType { @@ -1629,12 +1686,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OptionalGroup BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OptionalGroup returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -1648,6 +1704,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OptionalGroup other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.OptionalGroup.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -1659,6 +1716,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -1701,11 +1759,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -1827,7 +1887,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(RepeatedGroup prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1837,21 +1897,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new RepeatedGroup(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(RepeatedGroup cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + RepeatedGroup result; + + private RepeatedGroup PrepareBuilder() { + if (builderIsReadOnly) { + RepeatedGroup original = result; + result = new RepeatedGroup(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - RepeatedGroup result = new RepeatedGroup(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override RepeatedGroup MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new RepeatedGroup(); + result = DefaultInstance ?? new RepeatedGroup(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override RepeatedGroup DefaultInstanceForType { @@ -1859,12 +1946,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override RepeatedGroup BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - RepeatedGroup returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -1878,6 +1964,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(RepeatedGroup other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.RepeatedGroup.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -1889,6 +1976,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -1931,11 +2019,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -3542,7 +3632,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestAllTypesLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3552,21 +3642,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestAllTypesLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestAllTypesLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestAllTypesLite result = new TestAllTypesLite(); + bool builderIsReadOnly; + TestAllTypesLite result; + + private TestAllTypesLite PrepareBuilder() { + if (builderIsReadOnly) { + TestAllTypesLite original = result; + result = new TestAllTypesLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestAllTypesLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestAllTypesLite(); + result = DefaultInstance ?? new TestAllTypesLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestAllTypesLite DefaultInstanceForType { @@ -3574,8 +3691,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestAllTypesLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedInt32_.MakeReadOnly(); result.repeatedInt64_.MakeReadOnly(); @@ -3601,9 +3718,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.repeatedImportEnum_.MakeReadOnly(); result.repeatedStringPiece_.MakeReadOnly(); result.repeatedCord_.MakeReadOnly(); - TestAllTypesLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -3617,6 +3733,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestAllTypesLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasOptionalInt32) { OptionalInt32 = other.OptionalInt32; } @@ -3829,6 +3946,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -4202,11 +4320,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalInt32(value); } } public Builder SetOptionalInt32(int value) { + PrepareBuilder(); result.hasOptionalInt32 = true; result.optionalInt32_ = value; return this; } public Builder ClearOptionalInt32() { + PrepareBuilder(); result.hasOptionalInt32 = false; result.optionalInt32_ = 0; return this; @@ -4220,11 +4340,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalInt64(value); } } public Builder SetOptionalInt64(long value) { + PrepareBuilder(); result.hasOptionalInt64 = true; result.optionalInt64_ = value; return this; } public Builder ClearOptionalInt64() { + PrepareBuilder(); result.hasOptionalInt64 = false; result.optionalInt64_ = 0L; return this; @@ -4240,11 +4362,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalUint32(uint value) { + PrepareBuilder(); result.hasOptionalUint32 = true; result.optionalUint32_ = value; return this; } public Builder ClearOptionalUint32() { + PrepareBuilder(); result.hasOptionalUint32 = false; result.optionalUint32_ = 0; return this; @@ -4260,11 +4384,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalUint64(ulong value) { + PrepareBuilder(); result.hasOptionalUint64 = true; result.optionalUint64_ = value; return this; } public Builder ClearOptionalUint64() { + PrepareBuilder(); result.hasOptionalUint64 = false; result.optionalUint64_ = 0UL; return this; @@ -4278,11 +4404,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSint32(value); } } public Builder SetOptionalSint32(int value) { + PrepareBuilder(); result.hasOptionalSint32 = true; result.optionalSint32_ = value; return this; } public Builder ClearOptionalSint32() { + PrepareBuilder(); result.hasOptionalSint32 = false; result.optionalSint32_ = 0; return this; @@ -4296,11 +4424,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSint64(value); } } public Builder SetOptionalSint64(long value) { + PrepareBuilder(); result.hasOptionalSint64 = true; result.optionalSint64_ = value; return this; } public Builder ClearOptionalSint64() { + PrepareBuilder(); result.hasOptionalSint64 = false; result.optionalSint64_ = 0; return this; @@ -4316,11 +4446,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalFixed32(uint value) { + PrepareBuilder(); result.hasOptionalFixed32 = true; result.optionalFixed32_ = value; return this; } public Builder ClearOptionalFixed32() { + PrepareBuilder(); result.hasOptionalFixed32 = false; result.optionalFixed32_ = 0; return this; @@ -4336,11 +4468,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalFixed64(ulong value) { + PrepareBuilder(); result.hasOptionalFixed64 = true; result.optionalFixed64_ = value; return this; } public Builder ClearOptionalFixed64() { + PrepareBuilder(); result.hasOptionalFixed64 = false; result.optionalFixed64_ = 0; return this; @@ -4354,11 +4488,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSfixed32(value); } } public Builder SetOptionalSfixed32(int value) { + PrepareBuilder(); result.hasOptionalSfixed32 = true; result.optionalSfixed32_ = value; return this; } public Builder ClearOptionalSfixed32() { + PrepareBuilder(); result.hasOptionalSfixed32 = false; result.optionalSfixed32_ = 0; return this; @@ -4372,11 +4508,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSfixed64(value); } } public Builder SetOptionalSfixed64(long value) { + PrepareBuilder(); result.hasOptionalSfixed64 = true; result.optionalSfixed64_ = value; return this; } public Builder ClearOptionalSfixed64() { + PrepareBuilder(); result.hasOptionalSfixed64 = false; result.optionalSfixed64_ = 0; return this; @@ -4390,11 +4528,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalFloat(value); } } public Builder SetOptionalFloat(float value) { + PrepareBuilder(); result.hasOptionalFloat = true; result.optionalFloat_ = value; return this; } public Builder ClearOptionalFloat() { + PrepareBuilder(); result.hasOptionalFloat = false; result.optionalFloat_ = 0F; return this; @@ -4408,11 +4548,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalDouble(value); } } public Builder SetOptionalDouble(double value) { + PrepareBuilder(); result.hasOptionalDouble = true; result.optionalDouble_ = value; return this; } public Builder ClearOptionalDouble() { + PrepareBuilder(); result.hasOptionalDouble = false; result.optionalDouble_ = 0D; return this; @@ -4426,11 +4568,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalBool(value); } } public Builder SetOptionalBool(bool value) { + PrepareBuilder(); result.hasOptionalBool = true; result.optionalBool_ = value; return this; } public Builder ClearOptionalBool() { + PrepareBuilder(); result.hasOptionalBool = false; result.optionalBool_ = false; return this; @@ -4445,11 +4589,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalString = true; result.optionalString_ = value; return this; } public Builder ClearOptionalString() { + PrepareBuilder(); result.hasOptionalString = false; result.optionalString_ = ""; return this; @@ -4464,11 +4610,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalBytes = true; result.optionalBytes_ = value; return this; } public Builder ClearOptionalBytes() { + PrepareBuilder(); result.hasOptionalBytes = false; result.optionalBytes_ = pb::ByteString.Empty; return this; @@ -4483,18 +4631,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.OptionalGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalGroup = true; result.optionalGroup_ = value; return this; } public Builder SetOptionalGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.OptionalGroup.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalGroup = true; result.optionalGroup_ = builderForValue.Build(); return this; } public Builder MergeOptionalGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.OptionalGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalGroup && result.optionalGroup_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.OptionalGroup.DefaultInstance) { result.optionalGroup_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.OptionalGroup.CreateBuilder(result.optionalGroup_).MergeFrom(value).BuildPartial(); @@ -4505,6 +4656,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalGroup() { + PrepareBuilder(); result.hasOptionalGroup = false; result.optionalGroup_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.OptionalGroup.DefaultInstance; return this; @@ -4519,18 +4671,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = value; return this; } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalNestedMessage && result.optionalNestedMessage_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage.DefaultInstance) { result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage.CreateBuilder(result.optionalNestedMessage_).MergeFrom(value).BuildPartial(); @@ -4541,6 +4696,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalNestedMessage() { + PrepareBuilder(); result.hasOptionalNestedMessage = false; result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage.DefaultInstance; return this; @@ -4555,18 +4711,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalForeignMessage = true; result.optionalForeignMessage_ = value; return this; } public Builder SetOptionalForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalForeignMessage = true; result.optionalForeignMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalForeignMessage && result.optionalForeignMessage_ != global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite.DefaultInstance) { result.optionalForeignMessage_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite.CreateBuilder(result.optionalForeignMessage_).MergeFrom(value).BuildPartial(); @@ -4577,6 +4736,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalForeignMessage() { + PrepareBuilder(); result.hasOptionalForeignMessage = false; result.optionalForeignMessage_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite.DefaultInstance; return this; @@ -4591,18 +4751,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessageLite value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalImportMessage = true; result.optionalImportMessage_ = value; return this; } public Builder SetOptionalImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalImportMessage = true; result.optionalImportMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessageLite value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalImportMessage && result.optionalImportMessage_ != global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) { result.optionalImportMessage_ = global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.CreateBuilder(result.optionalImportMessage_).MergeFrom(value).BuildPartial(); @@ -4613,6 +4776,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalImportMessage() { + PrepareBuilder(); result.hasOptionalImportMessage = false; result.optionalImportMessage_ = global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance; return this; @@ -4626,11 +4790,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalNestedEnum(value); } } public Builder SetOptionalNestedEnum(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedEnum value) { + PrepareBuilder(); result.hasOptionalNestedEnum = true; result.optionalNestedEnum_ = value; return this; } public Builder ClearOptionalNestedEnum() { + PrepareBuilder(); result.hasOptionalNestedEnum = false; result.optionalNestedEnum_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedEnum.FOO; return this; @@ -4644,11 +4810,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalForeignEnum(value); } } public Builder SetOptionalForeignEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite value) { + PrepareBuilder(); result.hasOptionalForeignEnum = true; result.optionalForeignEnum_ = value; return this; } public Builder ClearOptionalForeignEnum() { + PrepareBuilder(); result.hasOptionalForeignEnum = false; result.optionalForeignEnum_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite.FOREIGN_LITE_FOO; return this; @@ -4662,11 +4830,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalImportEnum(value); } } public Builder SetOptionalImportEnum(global::Google.ProtocolBuffers.TestProtos.ImportEnumLite value) { + PrepareBuilder(); result.hasOptionalImportEnum = true; result.optionalImportEnum_ = value; return this; } public Builder ClearOptionalImportEnum() { + PrepareBuilder(); result.hasOptionalImportEnum = false; result.optionalImportEnum_ = global::Google.ProtocolBuffers.TestProtos.ImportEnumLite.IMPORT_LITE_FOO; return this; @@ -4681,11 +4851,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalStringPiece(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalStringPiece = true; result.optionalStringPiece_ = value; return this; } public Builder ClearOptionalStringPiece() { + PrepareBuilder(); result.hasOptionalStringPiece = false; result.optionalStringPiece_ = ""; return this; @@ -4700,18 +4872,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalCord(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalCord = true; result.optionalCord_ = value; return this; } public Builder ClearOptionalCord() { + PrepareBuilder(); result.hasOptionalCord = false; result.optionalCord_ = ""; return this; } public pbc::IPopsicleList RepeatedInt32List { - get { return result.repeatedInt32_; } + get { return PrepareBuilder().repeatedInt32_; } } public int RepeatedInt32Count { get { return result.RepeatedInt32Count; } @@ -4720,24 +4894,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt32(index); } public Builder SetRepeatedInt32(int index, int value) { + PrepareBuilder(); result.repeatedInt32_[index] = value; return this; } public Builder AddRepeatedInt32(int value) { + PrepareBuilder(); result.repeatedInt32_.Add(value); return this; } public Builder AddRangeRepeatedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt32_); return this; } public Builder ClearRepeatedInt32() { + PrepareBuilder(); result.repeatedInt32_.Clear(); return this; } public pbc::IPopsicleList RepeatedInt64List { - get { return result.repeatedInt64_; } + get { return PrepareBuilder().repeatedInt64_; } } public int RepeatedInt64Count { get { return result.RepeatedInt64Count; } @@ -4746,25 +4924,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt64(index); } public Builder SetRepeatedInt64(int index, long value) { + PrepareBuilder(); result.repeatedInt64_[index] = value; return this; } public Builder AddRepeatedInt64(long value) { + PrepareBuilder(); result.repeatedInt64_.Add(value); return this; } public Builder AddRangeRepeatedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt64_); return this; } public Builder ClearRepeatedInt64() { + PrepareBuilder(); result.repeatedInt64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedUint32List { - get { return result.repeatedUint32_; } + get { return PrepareBuilder().repeatedUint32_; } } public int RepeatedUint32Count { get { return result.RepeatedUint32Count; } @@ -4775,27 +4957,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedUint32(int index, uint value) { + PrepareBuilder(); result.repeatedUint32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedUint32(uint value) { + PrepareBuilder(); result.repeatedUint32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedUint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedUint32_); return this; } public Builder ClearRepeatedUint32() { + PrepareBuilder(); result.repeatedUint32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedUint64List { - get { return result.repeatedUint64_; } + get { return PrepareBuilder().repeatedUint64_; } } public int RepeatedUint64Count { get { return result.RepeatedUint64Count; } @@ -4806,26 +4992,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedUint64(int index, ulong value) { + PrepareBuilder(); result.repeatedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedUint64(ulong value) { + PrepareBuilder(); result.repeatedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedUint64_); return this; } public Builder ClearRepeatedUint64() { + PrepareBuilder(); result.repeatedUint64_.Clear(); return this; } public pbc::IPopsicleList RepeatedSint32List { - get { return result.repeatedSint32_; } + get { return PrepareBuilder().repeatedSint32_; } } public int RepeatedSint32Count { get { return result.RepeatedSint32Count; } @@ -4834,24 +5024,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSint32(index); } public Builder SetRepeatedSint32(int index, int value) { + PrepareBuilder(); result.repeatedSint32_[index] = value; return this; } public Builder AddRepeatedSint32(int value) { + PrepareBuilder(); result.repeatedSint32_.Add(value); return this; } public Builder AddRangeRepeatedSint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSint32_); return this; } public Builder ClearRepeatedSint32() { + PrepareBuilder(); result.repeatedSint32_.Clear(); return this; } public pbc::IPopsicleList RepeatedSint64List { - get { return result.repeatedSint64_; } + get { return PrepareBuilder().repeatedSint64_; } } public int RepeatedSint64Count { get { return result.RepeatedSint64Count; } @@ -4860,25 +5054,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSint64(index); } public Builder SetRepeatedSint64(int index, long value) { + PrepareBuilder(); result.repeatedSint64_[index] = value; return this; } public Builder AddRepeatedSint64(long value) { + PrepareBuilder(); result.repeatedSint64_.Add(value); return this; } public Builder AddRangeRepeatedSint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSint64_); return this; } public Builder ClearRepeatedSint64() { + PrepareBuilder(); result.repeatedSint64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed32List { - get { return result.repeatedFixed32_; } + get { return PrepareBuilder().repeatedFixed32_; } } public int RepeatedFixed32Count { get { return result.RepeatedFixed32Count; } @@ -4889,27 +5087,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed32(int index, uint value) { + PrepareBuilder(); result.repeatedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed32(uint value) { + PrepareBuilder(); result.repeatedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed32_); return this; } public Builder ClearRepeatedFixed32() { + PrepareBuilder(); result.repeatedFixed32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed64List { - get { return result.repeatedFixed64_; } + get { return PrepareBuilder().repeatedFixed64_; } } public int RepeatedFixed64Count { get { return result.RepeatedFixed64Count; } @@ -4920,26 +5122,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed64(int index, ulong value) { + PrepareBuilder(); result.repeatedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed64(ulong value) { + PrepareBuilder(); result.repeatedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed64_); return this; } public Builder ClearRepeatedFixed64() { + PrepareBuilder(); result.repeatedFixed64_.Clear(); return this; } public pbc::IPopsicleList RepeatedSfixed32List { - get { return result.repeatedSfixed32_; } + get { return PrepareBuilder().repeatedSfixed32_; } } public int RepeatedSfixed32Count { get { return result.RepeatedSfixed32Count; } @@ -4948,24 +5154,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSfixed32(index); } public Builder SetRepeatedSfixed32(int index, int value) { + PrepareBuilder(); result.repeatedSfixed32_[index] = value; return this; } public Builder AddRepeatedSfixed32(int value) { + PrepareBuilder(); result.repeatedSfixed32_.Add(value); return this; } public Builder AddRangeRepeatedSfixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSfixed32_); return this; } public Builder ClearRepeatedSfixed32() { + PrepareBuilder(); result.repeatedSfixed32_.Clear(); return this; } public pbc::IPopsicleList RepeatedSfixed64List { - get { return result.repeatedSfixed64_; } + get { return PrepareBuilder().repeatedSfixed64_; } } public int RepeatedSfixed64Count { get { return result.RepeatedSfixed64Count; } @@ -4974,24 +5184,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSfixed64(index); } public Builder SetRepeatedSfixed64(int index, long value) { + PrepareBuilder(); result.repeatedSfixed64_[index] = value; return this; } public Builder AddRepeatedSfixed64(long value) { + PrepareBuilder(); result.repeatedSfixed64_.Add(value); return this; } public Builder AddRangeRepeatedSfixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSfixed64_); return this; } public Builder ClearRepeatedSfixed64() { + PrepareBuilder(); result.repeatedSfixed64_.Clear(); return this; } public pbc::IPopsicleList RepeatedFloatList { - get { return result.repeatedFloat_; } + get { return PrepareBuilder().repeatedFloat_; } } public int RepeatedFloatCount { get { return result.RepeatedFloatCount; } @@ -5000,24 +5214,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedFloat(index); } public Builder SetRepeatedFloat(int index, float value) { + PrepareBuilder(); result.repeatedFloat_[index] = value; return this; } public Builder AddRepeatedFloat(float value) { + PrepareBuilder(); result.repeatedFloat_.Add(value); return this; } public Builder AddRangeRepeatedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFloat_); return this; } public Builder ClearRepeatedFloat() { + PrepareBuilder(); result.repeatedFloat_.Clear(); return this; } public pbc::IPopsicleList RepeatedDoubleList { - get { return result.repeatedDouble_; } + get { return PrepareBuilder().repeatedDouble_; } } public int RepeatedDoubleCount { get { return result.RepeatedDoubleCount; } @@ -5026,24 +5244,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedDouble(index); } public Builder SetRepeatedDouble(int index, double value) { + PrepareBuilder(); result.repeatedDouble_[index] = value; return this; } public Builder AddRepeatedDouble(double value) { + PrepareBuilder(); result.repeatedDouble_.Add(value); return this; } public Builder AddRangeRepeatedDouble(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedDouble_); return this; } public Builder ClearRepeatedDouble() { + PrepareBuilder(); result.repeatedDouble_.Clear(); return this; } public pbc::IPopsicleList RepeatedBoolList { - get { return result.repeatedBool_; } + get { return PrepareBuilder().repeatedBool_; } } public int RepeatedBoolCount { get { return result.RepeatedBoolCount; } @@ -5052,24 +5274,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedBool(index); } public Builder SetRepeatedBool(int index, bool value) { + PrepareBuilder(); result.repeatedBool_[index] = value; return this; } public Builder AddRepeatedBool(bool value) { + PrepareBuilder(); result.repeatedBool_.Add(value); return this; } public Builder AddRangeRepeatedBool(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedBool_); return this; } public Builder ClearRepeatedBool() { + PrepareBuilder(); result.repeatedBool_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringList { - get { return result.repeatedString_; } + get { return PrepareBuilder().repeatedString_; } } public int RepeatedStringCount { get { return result.RepeatedStringCount; } @@ -5079,25 +5305,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedString(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedString_[index] = value; return this; } public Builder AddRepeatedString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedString_.Add(value); return this; } public Builder AddRangeRepeatedString(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedString_); return this; } public Builder ClearRepeatedString() { + PrepareBuilder(); result.repeatedString_.Clear(); return this; } public pbc::IPopsicleList RepeatedBytesList { - get { return result.repeatedBytes_; } + get { return PrepareBuilder().repeatedBytes_; } } public int RepeatedBytesCount { get { return result.RepeatedBytesCount; } @@ -5107,25 +5337,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedBytes(int index, pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedBytes_[index] = value; return this; } public Builder AddRepeatedBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedBytes_.Add(value); return this; } public Builder AddRangeRepeatedBytes(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedBytes_); return this; } public Builder ClearRepeatedBytes() { + PrepareBuilder(); result.repeatedBytes_.Clear(); return this; } public pbc::IPopsicleList RepeatedGroupList { - get { return result.repeatedGroup_; } + get { return PrepareBuilder().repeatedGroup_; } } public int RepeatedGroupCount { get { return result.RepeatedGroupCount; } @@ -5135,35 +5369,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedGroup(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.RepeatedGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedGroup_[index] = value; return this; } public Builder SetRepeatedGroup(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.RepeatedGroup.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedGroup_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.RepeatedGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedGroup_.Add(value); return this; } public Builder AddRepeatedGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.RepeatedGroup.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedGroup_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedGroup(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedGroup_); return this; } public Builder ClearRepeatedGroup() { + PrepareBuilder(); result.repeatedGroup_.Clear(); return this; } public pbc::IPopsicleList RepeatedNestedMessageList { - get { return result.repeatedNestedMessage_; } + get { return PrepareBuilder().repeatedNestedMessage_; } } public int RepeatedNestedMessageCount { get { return result.RepeatedNestedMessageCount; } @@ -5173,35 +5413,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedNestedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedNestedMessage_[index] = value; return this; } public Builder SetRepeatedNestedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedNestedMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedNestedMessage_.Add(value); return this; } public Builder AddRepeatedNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedNestedMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedNestedMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedNestedMessage_); return this; } public Builder ClearRepeatedNestedMessage() { + PrepareBuilder(); result.repeatedNestedMessage_.Clear(); return this; } public pbc::IPopsicleList RepeatedForeignMessageList { - get { return result.repeatedForeignMessage_; } + get { return PrepareBuilder().repeatedForeignMessage_; } } public int RepeatedForeignMessageCount { get { return result.RepeatedForeignMessageCount; } @@ -5211,35 +5457,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedForeignMessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedForeignMessage_[index] = value; return this; } public Builder SetRepeatedForeignMessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedForeignMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedForeignMessage_.Add(value); return this; } public Builder AddRepeatedForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedForeignMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedForeignMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedForeignMessage_); return this; } public Builder ClearRepeatedForeignMessage() { + PrepareBuilder(); result.repeatedForeignMessage_.Clear(); return this; } public pbc::IPopsicleList RepeatedImportMessageList { - get { return result.repeatedImportMessage_; } + get { return PrepareBuilder().repeatedImportMessage_; } } public int RepeatedImportMessageCount { get { return result.RepeatedImportMessageCount; } @@ -5249,35 +5501,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedImportMessage(int index, global::Google.ProtocolBuffers.TestProtos.ImportMessageLite value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedImportMessage_[index] = value; return this; } public Builder SetRepeatedImportMessage(int index, global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedImportMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessageLite value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedImportMessage_.Add(value); return this; } public Builder AddRepeatedImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedImportMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedImportMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedImportMessage_); return this; } public Builder ClearRepeatedImportMessage() { + PrepareBuilder(); result.repeatedImportMessage_.Clear(); return this; } public pbc::IPopsicleList RepeatedNestedEnumList { - get { return result.repeatedNestedEnum_; } + get { return PrepareBuilder().repeatedNestedEnum_; } } public int RepeatedNestedEnumCount { get { return result.RepeatedNestedEnumCount; } @@ -5286,24 +5544,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedNestedEnum(index); } public Builder SetRepeatedNestedEnum(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedEnum value) { + PrepareBuilder(); result.repeatedNestedEnum_[index] = value; return this; } public Builder AddRepeatedNestedEnum(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedEnum value) { + PrepareBuilder(); result.repeatedNestedEnum_.Add(value); return this; } public Builder AddRangeRepeatedNestedEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedNestedEnum_); return this; } public Builder ClearRepeatedNestedEnum() { + PrepareBuilder(); result.repeatedNestedEnum_.Clear(); return this; } public pbc::IPopsicleList RepeatedForeignEnumList { - get { return result.repeatedForeignEnum_; } + get { return PrepareBuilder().repeatedForeignEnum_; } } public int RepeatedForeignEnumCount { get { return result.RepeatedForeignEnumCount; } @@ -5312,24 +5574,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedForeignEnum(index); } public Builder SetRepeatedForeignEnum(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite value) { + PrepareBuilder(); result.repeatedForeignEnum_[index] = value; return this; } public Builder AddRepeatedForeignEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite value) { + PrepareBuilder(); result.repeatedForeignEnum_.Add(value); return this; } public Builder AddRangeRepeatedForeignEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedForeignEnum_); return this; } public Builder ClearRepeatedForeignEnum() { + PrepareBuilder(); result.repeatedForeignEnum_.Clear(); return this; } public pbc::IPopsicleList RepeatedImportEnumList { - get { return result.repeatedImportEnum_; } + get { return PrepareBuilder().repeatedImportEnum_; } } public int RepeatedImportEnumCount { get { return result.RepeatedImportEnumCount; } @@ -5338,24 +5604,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedImportEnum(index); } public Builder SetRepeatedImportEnum(int index, global::Google.ProtocolBuffers.TestProtos.ImportEnumLite value) { + PrepareBuilder(); result.repeatedImportEnum_[index] = value; return this; } public Builder AddRepeatedImportEnum(global::Google.ProtocolBuffers.TestProtos.ImportEnumLite value) { + PrepareBuilder(); result.repeatedImportEnum_.Add(value); return this; } public Builder AddRangeRepeatedImportEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedImportEnum_); return this; } public Builder ClearRepeatedImportEnum() { + PrepareBuilder(); result.repeatedImportEnum_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringPieceList { - get { return result.repeatedStringPiece_; } + get { return PrepareBuilder().repeatedStringPiece_; } } public int RepeatedStringPieceCount { get { return result.RepeatedStringPieceCount; } @@ -5365,25 +5635,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedStringPiece(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPiece_[index] = value; return this; } public Builder AddRepeatedStringPiece(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPiece_.Add(value); return this; } public Builder AddRangeRepeatedStringPiece(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedStringPiece_); return this; } public Builder ClearRepeatedStringPiece() { + PrepareBuilder(); result.repeatedStringPiece_.Clear(); return this; } public pbc::IPopsicleList RepeatedCordList { - get { return result.repeatedCord_; } + get { return PrepareBuilder().repeatedCord_; } } public int RepeatedCordCount { get { return result.RepeatedCordCount; } @@ -5393,19 +5667,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedCord(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCord_[index] = value; return this; } public Builder AddRepeatedCord(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCord_.Add(value); return this; } public Builder AddRangeRepeatedCord(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedCord_); return this; } public Builder ClearRepeatedCord() { + PrepareBuilder(); result.repeatedCord_.Clear(); return this; } @@ -5418,11 +5696,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultInt32(value); } } public Builder SetDefaultInt32(int value) { + PrepareBuilder(); result.hasDefaultInt32 = true; result.defaultInt32_ = value; return this; } public Builder ClearDefaultInt32() { + PrepareBuilder(); result.hasDefaultInt32 = false; result.defaultInt32_ = 41; return this; @@ -5436,11 +5716,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultInt64(value); } } public Builder SetDefaultInt64(long value) { + PrepareBuilder(); result.hasDefaultInt64 = true; result.defaultInt64_ = value; return this; } public Builder ClearDefaultInt64() { + PrepareBuilder(); result.hasDefaultInt64 = false; result.defaultInt64_ = 42L; return this; @@ -5456,11 +5738,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultUint32(uint value) { + PrepareBuilder(); result.hasDefaultUint32 = true; result.defaultUint32_ = value; return this; } public Builder ClearDefaultUint32() { + PrepareBuilder(); result.hasDefaultUint32 = false; result.defaultUint32_ = 43; return this; @@ -5476,11 +5760,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultUint64(ulong value) { + PrepareBuilder(); result.hasDefaultUint64 = true; result.defaultUint64_ = value; return this; } public Builder ClearDefaultUint64() { + PrepareBuilder(); result.hasDefaultUint64 = false; result.defaultUint64_ = 44UL; return this; @@ -5494,11 +5780,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSint32(value); } } public Builder SetDefaultSint32(int value) { + PrepareBuilder(); result.hasDefaultSint32 = true; result.defaultSint32_ = value; return this; } public Builder ClearDefaultSint32() { + PrepareBuilder(); result.hasDefaultSint32 = false; result.defaultSint32_ = -45; return this; @@ -5512,11 +5800,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSint64(value); } } public Builder SetDefaultSint64(long value) { + PrepareBuilder(); result.hasDefaultSint64 = true; result.defaultSint64_ = value; return this; } public Builder ClearDefaultSint64() { + PrepareBuilder(); result.hasDefaultSint64 = false; result.defaultSint64_ = 46; return this; @@ -5532,11 +5822,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultFixed32(uint value) { + PrepareBuilder(); result.hasDefaultFixed32 = true; result.defaultFixed32_ = value; return this; } public Builder ClearDefaultFixed32() { + PrepareBuilder(); result.hasDefaultFixed32 = false; result.defaultFixed32_ = 47; return this; @@ -5552,11 +5844,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultFixed64(ulong value) { + PrepareBuilder(); result.hasDefaultFixed64 = true; result.defaultFixed64_ = value; return this; } public Builder ClearDefaultFixed64() { + PrepareBuilder(); result.hasDefaultFixed64 = false; result.defaultFixed64_ = 48; return this; @@ -5570,11 +5864,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSfixed32(value); } } public Builder SetDefaultSfixed32(int value) { + PrepareBuilder(); result.hasDefaultSfixed32 = true; result.defaultSfixed32_ = value; return this; } public Builder ClearDefaultSfixed32() { + PrepareBuilder(); result.hasDefaultSfixed32 = false; result.defaultSfixed32_ = 49; return this; @@ -5588,11 +5884,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSfixed64(value); } } public Builder SetDefaultSfixed64(long value) { + PrepareBuilder(); result.hasDefaultSfixed64 = true; result.defaultSfixed64_ = value; return this; } public Builder ClearDefaultSfixed64() { + PrepareBuilder(); result.hasDefaultSfixed64 = false; result.defaultSfixed64_ = -50; return this; @@ -5606,11 +5904,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultFloat(value); } } public Builder SetDefaultFloat(float value) { + PrepareBuilder(); result.hasDefaultFloat = true; result.defaultFloat_ = value; return this; } public Builder ClearDefaultFloat() { + PrepareBuilder(); result.hasDefaultFloat = false; result.defaultFloat_ = 51.5F; return this; @@ -5624,11 +5924,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultDouble(value); } } public Builder SetDefaultDouble(double value) { + PrepareBuilder(); result.hasDefaultDouble = true; result.defaultDouble_ = value; return this; } public Builder ClearDefaultDouble() { + PrepareBuilder(); result.hasDefaultDouble = false; result.defaultDouble_ = 52000D; return this; @@ -5642,11 +5944,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultBool(value); } } public Builder SetDefaultBool(bool value) { + PrepareBuilder(); result.hasDefaultBool = true; result.defaultBool_ = value; return this; } public Builder ClearDefaultBool() { + PrepareBuilder(); result.hasDefaultBool = false; result.defaultBool_ = true; return this; @@ -5661,11 +5965,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultString = true; result.defaultString_ = value; return this; } public Builder ClearDefaultString() { + PrepareBuilder(); result.hasDefaultString = false; result.defaultString_ = "hello"; return this; @@ -5680,11 +5986,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultBytes = true; result.defaultBytes_ = value; return this; } public Builder ClearDefaultBytes() { + PrepareBuilder(); result.hasDefaultBytes = false; result.defaultBytes_ = pb::ByteString.FromBase64("d29ybGQ="); return this; @@ -5698,11 +6006,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultNestedEnum(value); } } public Builder SetDefaultNestedEnum(global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedEnum value) { + PrepareBuilder(); result.hasDefaultNestedEnum = true; result.defaultNestedEnum_ = value; return this; } public Builder ClearDefaultNestedEnum() { + PrepareBuilder(); result.hasDefaultNestedEnum = false; result.defaultNestedEnum_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypesLite.Types.NestedEnum.BAR; return this; @@ -5716,11 +6026,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultForeignEnum(value); } } public Builder SetDefaultForeignEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite value) { + PrepareBuilder(); result.hasDefaultForeignEnum = true; result.defaultForeignEnum_ = value; return this; } public Builder ClearDefaultForeignEnum() { + PrepareBuilder(); result.hasDefaultForeignEnum = false; result.defaultForeignEnum_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite.FOREIGN_LITE_BAR; return this; @@ -5734,11 +6046,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultImportEnum(value); } } public Builder SetDefaultImportEnum(global::Google.ProtocolBuffers.TestProtos.ImportEnumLite value) { + PrepareBuilder(); result.hasDefaultImportEnum = true; result.defaultImportEnum_ = value; return this; } public Builder ClearDefaultImportEnum() { + PrepareBuilder(); result.hasDefaultImportEnum = false; result.defaultImportEnum_ = global::Google.ProtocolBuffers.TestProtos.ImportEnumLite.IMPORT_LITE_BAR; return this; @@ -5753,11 +6067,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultStringPiece(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultStringPiece = true; result.defaultStringPiece_ = value; return this; } public Builder ClearDefaultStringPiece() { + PrepareBuilder(); result.hasDefaultStringPiece = false; result.defaultStringPiece_ = "abc"; return this; @@ -5772,11 +6088,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultCord(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultCord = true; result.defaultCord_ = value; return this; } public Builder ClearDefaultCord() { + PrepareBuilder(); result.hasDefaultCord = false; result.defaultCord_ = "123"; return this; @@ -5898,7 +6216,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ForeignMessageLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -5908,21 +6226,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ForeignMessageLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ForeignMessageLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + ForeignMessageLite result; + + private ForeignMessageLite PrepareBuilder() { + if (builderIsReadOnly) { + ForeignMessageLite original = result; + result = new ForeignMessageLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - ForeignMessageLite result = new ForeignMessageLite(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ForeignMessageLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ForeignMessageLite(); + result = DefaultInstance ?? new ForeignMessageLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override ForeignMessageLite DefaultInstanceForType { @@ -5930,12 +6275,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ForeignMessageLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ForeignMessageLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -5949,6 +6293,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ForeignMessageLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.ForeignMessageLite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasC) { C = other.C; } @@ -5960,6 +6305,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -6002,11 +6348,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetC(value); } } public Builder SetC(int value) { + PrepareBuilder(); result.hasC = true; result.c_ = value; return this; } public Builder ClearC() { + PrepareBuilder(); result.hasC = false; result.c_ = 0; return this; @@ -6566,7 +6914,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestPackedTypesLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6576,21 +6924,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestPackedTypesLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestPackedTypesLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestPackedTypesLite result; - TestPackedTypesLite result = new TestPackedTypesLite(); + private TestPackedTypesLite PrepareBuilder() { + if (builderIsReadOnly) { + TestPackedTypesLite original = result; + result = new TestPackedTypesLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestPackedTypesLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestPackedTypesLite(); + result = DefaultInstance ?? new TestPackedTypesLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestPackedTypesLite DefaultInstanceForType { @@ -6598,8 +6973,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestPackedTypesLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.packedInt32_.MakeReadOnly(); result.packedInt64_.MakeReadOnly(); @@ -6615,9 +6990,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.packedDouble_.MakeReadOnly(); result.packedBool_.MakeReadOnly(); result.packedEnum_.MakeReadOnly(); - TestPackedTypesLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -6631,6 +7005,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestPackedTypesLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestPackedTypesLite.DefaultInstance) return this; + PrepareBuilder(); if (other.packedInt32_.Count != 0) { base.AddRange(other.packedInt32_, result.packedInt32_); } @@ -6681,6 +7056,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -6783,7 +7159,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList PackedInt32List { - get { return result.packedInt32_; } + get { return PrepareBuilder().packedInt32_; } } public int PackedInt32Count { get { return result.PackedInt32Count; } @@ -6792,24 +7168,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedInt32(index); } public Builder SetPackedInt32(int index, int value) { + PrepareBuilder(); result.packedInt32_[index] = value; return this; } public Builder AddPackedInt32(int value) { + PrepareBuilder(); result.packedInt32_.Add(value); return this; } public Builder AddRangePackedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedInt32_); return this; } public Builder ClearPackedInt32() { + PrepareBuilder(); result.packedInt32_.Clear(); return this; } public pbc::IPopsicleList PackedInt64List { - get { return result.packedInt64_; } + get { return PrepareBuilder().packedInt64_; } } public int PackedInt64Count { get { return result.PackedInt64Count; } @@ -6818,25 +7198,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedInt64(index); } public Builder SetPackedInt64(int index, long value) { + PrepareBuilder(); result.packedInt64_[index] = value; return this; } public Builder AddPackedInt64(long value) { + PrepareBuilder(); result.packedInt64_.Add(value); return this; } public Builder AddRangePackedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedInt64_); return this; } public Builder ClearPackedInt64() { + PrepareBuilder(); result.packedInt64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedUint32List { - get { return result.packedUint32_; } + get { return PrepareBuilder().packedUint32_; } } public int PackedUint32Count { get { return result.PackedUint32Count; } @@ -6847,27 +7231,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedUint32(int index, uint value) { + PrepareBuilder(); result.packedUint32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedUint32(uint value) { + PrepareBuilder(); result.packedUint32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedUint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedUint32_); return this; } public Builder ClearPackedUint32() { + PrepareBuilder(); result.packedUint32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedUint64List { - get { return result.packedUint64_; } + get { return PrepareBuilder().packedUint64_; } } public int PackedUint64Count { get { return result.PackedUint64Count; } @@ -6878,26 +7266,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedUint64(int index, ulong value) { + PrepareBuilder(); result.packedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedUint64(ulong value) { + PrepareBuilder(); result.packedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedUint64_); return this; } public Builder ClearPackedUint64() { + PrepareBuilder(); result.packedUint64_.Clear(); return this; } public pbc::IPopsicleList PackedSint32List { - get { return result.packedSint32_; } + get { return PrepareBuilder().packedSint32_; } } public int PackedSint32Count { get { return result.PackedSint32Count; } @@ -6906,24 +7298,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSint32(index); } public Builder SetPackedSint32(int index, int value) { + PrepareBuilder(); result.packedSint32_[index] = value; return this; } public Builder AddPackedSint32(int value) { + PrepareBuilder(); result.packedSint32_.Add(value); return this; } public Builder AddRangePackedSint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSint32_); return this; } public Builder ClearPackedSint32() { + PrepareBuilder(); result.packedSint32_.Clear(); return this; } public pbc::IPopsicleList PackedSint64List { - get { return result.packedSint64_; } + get { return PrepareBuilder().packedSint64_; } } public int PackedSint64Count { get { return result.PackedSint64Count; } @@ -6932,25 +7328,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSint64(index); } public Builder SetPackedSint64(int index, long value) { + PrepareBuilder(); result.packedSint64_[index] = value; return this; } public Builder AddPackedSint64(long value) { + PrepareBuilder(); result.packedSint64_.Add(value); return this; } public Builder AddRangePackedSint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSint64_); return this; } public Builder ClearPackedSint64() { + PrepareBuilder(); result.packedSint64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedFixed32List { - get { return result.packedFixed32_; } + get { return PrepareBuilder().packedFixed32_; } } public int PackedFixed32Count { get { return result.PackedFixed32Count; } @@ -6961,27 +7361,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedFixed32(int index, uint value) { + PrepareBuilder(); result.packedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedFixed32(uint value) { + PrepareBuilder(); result.packedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedFixed32_); return this; } public Builder ClearPackedFixed32() { + PrepareBuilder(); result.packedFixed32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedFixed64List { - get { return result.packedFixed64_; } + get { return PrepareBuilder().packedFixed64_; } } public int PackedFixed64Count { get { return result.PackedFixed64Count; } @@ -6992,26 +7396,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedFixed64(int index, ulong value) { + PrepareBuilder(); result.packedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedFixed64(ulong value) { + PrepareBuilder(); result.packedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedFixed64_); return this; } public Builder ClearPackedFixed64() { + PrepareBuilder(); result.packedFixed64_.Clear(); return this; } public pbc::IPopsicleList PackedSfixed32List { - get { return result.packedSfixed32_; } + get { return PrepareBuilder().packedSfixed32_; } } public int PackedSfixed32Count { get { return result.PackedSfixed32Count; } @@ -7020,24 +7428,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSfixed32(index); } public Builder SetPackedSfixed32(int index, int value) { + PrepareBuilder(); result.packedSfixed32_[index] = value; return this; } public Builder AddPackedSfixed32(int value) { + PrepareBuilder(); result.packedSfixed32_.Add(value); return this; } public Builder AddRangePackedSfixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSfixed32_); return this; } public Builder ClearPackedSfixed32() { + PrepareBuilder(); result.packedSfixed32_.Clear(); return this; } public pbc::IPopsicleList PackedSfixed64List { - get { return result.packedSfixed64_; } + get { return PrepareBuilder().packedSfixed64_; } } public int PackedSfixed64Count { get { return result.PackedSfixed64Count; } @@ -7046,24 +7458,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSfixed64(index); } public Builder SetPackedSfixed64(int index, long value) { + PrepareBuilder(); result.packedSfixed64_[index] = value; return this; } public Builder AddPackedSfixed64(long value) { + PrepareBuilder(); result.packedSfixed64_.Add(value); return this; } public Builder AddRangePackedSfixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSfixed64_); return this; } public Builder ClearPackedSfixed64() { + PrepareBuilder(); result.packedSfixed64_.Clear(); return this; } public pbc::IPopsicleList PackedFloatList { - get { return result.packedFloat_; } + get { return PrepareBuilder().packedFloat_; } } public int PackedFloatCount { get { return result.PackedFloatCount; } @@ -7072,24 +7488,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedFloat(index); } public Builder SetPackedFloat(int index, float value) { + PrepareBuilder(); result.packedFloat_[index] = value; return this; } public Builder AddPackedFloat(float value) { + PrepareBuilder(); result.packedFloat_.Add(value); return this; } public Builder AddRangePackedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedFloat_); return this; } public Builder ClearPackedFloat() { + PrepareBuilder(); result.packedFloat_.Clear(); return this; } public pbc::IPopsicleList PackedDoubleList { - get { return result.packedDouble_; } + get { return PrepareBuilder().packedDouble_; } } public int PackedDoubleCount { get { return result.PackedDoubleCount; } @@ -7098,24 +7518,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedDouble(index); } public Builder SetPackedDouble(int index, double value) { + PrepareBuilder(); result.packedDouble_[index] = value; return this; } public Builder AddPackedDouble(double value) { + PrepareBuilder(); result.packedDouble_.Add(value); return this; } public Builder AddRangePackedDouble(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedDouble_); return this; } public Builder ClearPackedDouble() { + PrepareBuilder(); result.packedDouble_.Clear(); return this; } public pbc::IPopsicleList PackedBoolList { - get { return result.packedBool_; } + get { return PrepareBuilder().packedBool_; } } public int PackedBoolCount { get { return result.PackedBoolCount; } @@ -7124,24 +7548,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedBool(index); } public Builder SetPackedBool(int index, bool value) { + PrepareBuilder(); result.packedBool_[index] = value; return this; } public Builder AddPackedBool(bool value) { + PrepareBuilder(); result.packedBool_.Add(value); return this; } public Builder AddRangePackedBool(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedBool_); return this; } public Builder ClearPackedBool() { + PrepareBuilder(); result.packedBool_.Clear(); return this; } public pbc::IPopsicleList PackedEnumList { - get { return result.packedEnum_; } + get { return PrepareBuilder().packedEnum_; } } public int PackedEnumCount { get { return result.PackedEnumCount; } @@ -7150,18 +7578,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedEnum(index); } public Builder SetPackedEnum(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite value) { + PrepareBuilder(); result.packedEnum_[index] = value; return this; } public Builder AddPackedEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite value) { + PrepareBuilder(); result.packedEnum_.Add(value); return this; } public Builder AddRangePackedEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedEnum_); return this; } public Builder ClearPackedEnum() { + PrepareBuilder(); result.packedEnum_.Clear(); return this; } @@ -7665,7 +8097,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestUnpackedTypesLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -7675,21 +8107,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestUnpackedTypesLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestUnpackedTypesLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestUnpackedTypesLite result = new TestUnpackedTypesLite(); + bool builderIsReadOnly; + TestUnpackedTypesLite result; + + private TestUnpackedTypesLite PrepareBuilder() { + if (builderIsReadOnly) { + TestUnpackedTypesLite original = result; + result = new TestUnpackedTypesLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestUnpackedTypesLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestUnpackedTypesLite(); + result = DefaultInstance ?? new TestUnpackedTypesLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestUnpackedTypesLite DefaultInstanceForType { @@ -7697,8 +8156,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestUnpackedTypesLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.unpackedInt32_.MakeReadOnly(); result.unpackedInt64_.MakeReadOnly(); @@ -7714,9 +8173,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.unpackedDouble_.MakeReadOnly(); result.unpackedBool_.MakeReadOnly(); result.unpackedEnum_.MakeReadOnly(); - TestUnpackedTypesLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -7730,6 +8188,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestUnpackedTypesLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestUnpackedTypesLite.DefaultInstance) return this; + PrepareBuilder(); if (other.unpackedInt32_.Count != 0) { base.AddRange(other.unpackedInt32_, result.unpackedInt32_); } @@ -7780,6 +8239,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -7882,7 +8342,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList UnpackedInt32List { - get { return result.unpackedInt32_; } + get { return PrepareBuilder().unpackedInt32_; } } public int UnpackedInt32Count { get { return result.UnpackedInt32Count; } @@ -7891,24 +8351,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedInt32(index); } public Builder SetUnpackedInt32(int index, int value) { + PrepareBuilder(); result.unpackedInt32_[index] = value; return this; } public Builder AddUnpackedInt32(int value) { + PrepareBuilder(); result.unpackedInt32_.Add(value); return this; } public Builder AddRangeUnpackedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedInt32_); return this; } public Builder ClearUnpackedInt32() { + PrepareBuilder(); result.unpackedInt32_.Clear(); return this; } public pbc::IPopsicleList UnpackedInt64List { - get { return result.unpackedInt64_; } + get { return PrepareBuilder().unpackedInt64_; } } public int UnpackedInt64Count { get { return result.UnpackedInt64Count; } @@ -7917,25 +8381,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedInt64(index); } public Builder SetUnpackedInt64(int index, long value) { + PrepareBuilder(); result.unpackedInt64_[index] = value; return this; } public Builder AddUnpackedInt64(long value) { + PrepareBuilder(); result.unpackedInt64_.Add(value); return this; } public Builder AddRangeUnpackedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedInt64_); return this; } public Builder ClearUnpackedInt64() { + PrepareBuilder(); result.unpackedInt64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedUint32List { - get { return result.unpackedUint32_; } + get { return PrepareBuilder().unpackedUint32_; } } public int UnpackedUint32Count { get { return result.UnpackedUint32Count; } @@ -7946,27 +8414,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedUint32(int index, uint value) { + PrepareBuilder(); result.unpackedUint32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedUint32(uint value) { + PrepareBuilder(); result.unpackedUint32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedUint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedUint32_); return this; } public Builder ClearUnpackedUint32() { + PrepareBuilder(); result.unpackedUint32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedUint64List { - get { return result.unpackedUint64_; } + get { return PrepareBuilder().unpackedUint64_; } } public int UnpackedUint64Count { get { return result.UnpackedUint64Count; } @@ -7977,26 +8449,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedUint64(int index, ulong value) { + PrepareBuilder(); result.unpackedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedUint64(ulong value) { + PrepareBuilder(); result.unpackedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedUint64_); return this; } public Builder ClearUnpackedUint64() { + PrepareBuilder(); result.unpackedUint64_.Clear(); return this; } public pbc::IPopsicleList UnpackedSint32List { - get { return result.unpackedSint32_; } + get { return PrepareBuilder().unpackedSint32_; } } public int UnpackedSint32Count { get { return result.UnpackedSint32Count; } @@ -8005,24 +8481,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSint32(index); } public Builder SetUnpackedSint32(int index, int value) { + PrepareBuilder(); result.unpackedSint32_[index] = value; return this; } public Builder AddUnpackedSint32(int value) { + PrepareBuilder(); result.unpackedSint32_.Add(value); return this; } public Builder AddRangeUnpackedSint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSint32_); return this; } public Builder ClearUnpackedSint32() { + PrepareBuilder(); result.unpackedSint32_.Clear(); return this; } public pbc::IPopsicleList UnpackedSint64List { - get { return result.unpackedSint64_; } + get { return PrepareBuilder().unpackedSint64_; } } public int UnpackedSint64Count { get { return result.UnpackedSint64Count; } @@ -8031,25 +8511,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSint64(index); } public Builder SetUnpackedSint64(int index, long value) { + PrepareBuilder(); result.unpackedSint64_[index] = value; return this; } public Builder AddUnpackedSint64(long value) { + PrepareBuilder(); result.unpackedSint64_.Add(value); return this; } public Builder AddRangeUnpackedSint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSint64_); return this; } public Builder ClearUnpackedSint64() { + PrepareBuilder(); result.unpackedSint64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedFixed32List { - get { return result.unpackedFixed32_; } + get { return PrepareBuilder().unpackedFixed32_; } } public int UnpackedFixed32Count { get { return result.UnpackedFixed32Count; } @@ -8060,27 +8544,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedFixed32(int index, uint value) { + PrepareBuilder(); result.unpackedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedFixed32(uint value) { + PrepareBuilder(); result.unpackedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedFixed32_); return this; } public Builder ClearUnpackedFixed32() { + PrepareBuilder(); result.unpackedFixed32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedFixed64List { - get { return result.unpackedFixed64_; } + get { return PrepareBuilder().unpackedFixed64_; } } public int UnpackedFixed64Count { get { return result.UnpackedFixed64Count; } @@ -8091,26 +8579,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedFixed64(int index, ulong value) { + PrepareBuilder(); result.unpackedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedFixed64(ulong value) { + PrepareBuilder(); result.unpackedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedFixed64_); return this; } public Builder ClearUnpackedFixed64() { + PrepareBuilder(); result.unpackedFixed64_.Clear(); return this; } public pbc::IPopsicleList UnpackedSfixed32List { - get { return result.unpackedSfixed32_; } + get { return PrepareBuilder().unpackedSfixed32_; } } public int UnpackedSfixed32Count { get { return result.UnpackedSfixed32Count; } @@ -8119,24 +8611,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSfixed32(index); } public Builder SetUnpackedSfixed32(int index, int value) { + PrepareBuilder(); result.unpackedSfixed32_[index] = value; return this; } public Builder AddUnpackedSfixed32(int value) { + PrepareBuilder(); result.unpackedSfixed32_.Add(value); return this; } public Builder AddRangeUnpackedSfixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSfixed32_); return this; } public Builder ClearUnpackedSfixed32() { + PrepareBuilder(); result.unpackedSfixed32_.Clear(); return this; } public pbc::IPopsicleList UnpackedSfixed64List { - get { return result.unpackedSfixed64_; } + get { return PrepareBuilder().unpackedSfixed64_; } } public int UnpackedSfixed64Count { get { return result.UnpackedSfixed64Count; } @@ -8145,24 +8641,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSfixed64(index); } public Builder SetUnpackedSfixed64(int index, long value) { + PrepareBuilder(); result.unpackedSfixed64_[index] = value; return this; } public Builder AddUnpackedSfixed64(long value) { + PrepareBuilder(); result.unpackedSfixed64_.Add(value); return this; } public Builder AddRangeUnpackedSfixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSfixed64_); return this; } public Builder ClearUnpackedSfixed64() { + PrepareBuilder(); result.unpackedSfixed64_.Clear(); return this; } public pbc::IPopsicleList UnpackedFloatList { - get { return result.unpackedFloat_; } + get { return PrepareBuilder().unpackedFloat_; } } public int UnpackedFloatCount { get { return result.UnpackedFloatCount; } @@ -8171,24 +8671,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedFloat(index); } public Builder SetUnpackedFloat(int index, float value) { + PrepareBuilder(); result.unpackedFloat_[index] = value; return this; } public Builder AddUnpackedFloat(float value) { + PrepareBuilder(); result.unpackedFloat_.Add(value); return this; } public Builder AddRangeUnpackedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedFloat_); return this; } public Builder ClearUnpackedFloat() { + PrepareBuilder(); result.unpackedFloat_.Clear(); return this; } public pbc::IPopsicleList UnpackedDoubleList { - get { return result.unpackedDouble_; } + get { return PrepareBuilder().unpackedDouble_; } } public int UnpackedDoubleCount { get { return result.UnpackedDoubleCount; } @@ -8197,24 +8701,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedDouble(index); } public Builder SetUnpackedDouble(int index, double value) { + PrepareBuilder(); result.unpackedDouble_[index] = value; return this; } public Builder AddUnpackedDouble(double value) { + PrepareBuilder(); result.unpackedDouble_.Add(value); return this; } public Builder AddRangeUnpackedDouble(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedDouble_); return this; } public Builder ClearUnpackedDouble() { + PrepareBuilder(); result.unpackedDouble_.Clear(); return this; } public pbc::IPopsicleList UnpackedBoolList { - get { return result.unpackedBool_; } + get { return PrepareBuilder().unpackedBool_; } } public int UnpackedBoolCount { get { return result.UnpackedBoolCount; } @@ -8223,24 +8731,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedBool(index); } public Builder SetUnpackedBool(int index, bool value) { + PrepareBuilder(); result.unpackedBool_[index] = value; return this; } public Builder AddUnpackedBool(bool value) { + PrepareBuilder(); result.unpackedBool_.Add(value); return this; } public Builder AddRangeUnpackedBool(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedBool_); return this; } public Builder ClearUnpackedBool() { + PrepareBuilder(); result.unpackedBool_.Clear(); return this; } public pbc::IPopsicleList UnpackedEnumList { - get { return result.unpackedEnum_; } + get { return PrepareBuilder().unpackedEnum_; } } public int UnpackedEnumCount { get { return result.UnpackedEnumCount; } @@ -8249,18 +8761,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedEnum(index); } public Builder SetUnpackedEnum(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite value) { + PrepareBuilder(); result.unpackedEnum_[index] = value; return this; } public Builder AddUnpackedEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnumLite value) { + PrepareBuilder(); result.unpackedEnum_.Add(value); return this; } public Builder AddRangeUnpackedEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedEnum_); return this; } public Builder ClearUnpackedEnum() { + PrepareBuilder(); result.unpackedEnum_.Clear(); return this; } @@ -8369,7 +8885,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestAllExtensionsLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -8379,21 +8895,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestAllExtensionsLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestAllExtensionsLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestAllExtensionsLite result = new TestAllExtensionsLite(); + bool builderIsReadOnly; + TestAllExtensionsLite result; + + private TestAllExtensionsLite PrepareBuilder() { + if (builderIsReadOnly) { + TestAllExtensionsLite original = result; + result = new TestAllExtensionsLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestAllExtensionsLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestAllExtensionsLite(); + result = DefaultInstance ?? new TestAllExtensionsLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestAllExtensionsLite DefaultInstanceForType { @@ -8401,12 +8944,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestAllExtensionsLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestAllExtensionsLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -8420,6 +8962,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestAllExtensionsLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllExtensionsLite.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); return this; } @@ -8429,6 +8972,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -8575,7 +9119,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OptionalGroup_extension_lite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -8585,21 +9129,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OptionalGroup_extension_lite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OptionalGroup_extension_lite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + OptionalGroup_extension_lite result; + + private OptionalGroup_extension_lite PrepareBuilder() { + if (builderIsReadOnly) { + OptionalGroup_extension_lite original = result; + result = new OptionalGroup_extension_lite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - OptionalGroup_extension_lite result = new OptionalGroup_extension_lite(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OptionalGroup_extension_lite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OptionalGroup_extension_lite(); + result = DefaultInstance ?? new OptionalGroup_extension_lite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override OptionalGroup_extension_lite DefaultInstanceForType { @@ -8607,12 +9178,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OptionalGroup_extension_lite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OptionalGroup_extension_lite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -8626,6 +9196,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OptionalGroup_extension_lite other) { if (other == global::Google.ProtocolBuffers.TestProtos.OptionalGroup_extension_lite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -8637,6 +9208,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -8679,11 +9251,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -8805,7 +9379,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(RepeatedGroup_extension_lite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -8815,21 +9389,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new RepeatedGroup_extension_lite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(RepeatedGroup_extension_lite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + RepeatedGroup_extension_lite result; + + private RepeatedGroup_extension_lite PrepareBuilder() { + if (builderIsReadOnly) { + RepeatedGroup_extension_lite original = result; + result = new RepeatedGroup_extension_lite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - RepeatedGroup_extension_lite result = new RepeatedGroup_extension_lite(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override RepeatedGroup_extension_lite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new RepeatedGroup_extension_lite(); + result = DefaultInstance ?? new RepeatedGroup_extension_lite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override RepeatedGroup_extension_lite DefaultInstanceForType { @@ -8837,12 +9438,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override RepeatedGroup_extension_lite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - RepeatedGroup_extension_lite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -8856,6 +9456,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(RepeatedGroup_extension_lite other) { if (other == global::Google.ProtocolBuffers.TestProtos.RepeatedGroup_extension_lite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -8867,6 +9468,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -8909,11 +9511,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -9023,7 +9627,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestPackedExtensionsLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9033,21 +9637,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestPackedExtensionsLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestPackedExtensionsLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestPackedExtensionsLite result = new TestPackedExtensionsLite(); + bool builderIsReadOnly; + TestPackedExtensionsLite result; + + private TestPackedExtensionsLite PrepareBuilder() { + if (builderIsReadOnly) { + TestPackedExtensionsLite original = result; + result = new TestPackedExtensionsLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestPackedExtensionsLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestPackedExtensionsLite(); + result = DefaultInstance ?? new TestPackedExtensionsLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestPackedExtensionsLite DefaultInstanceForType { @@ -9055,12 +9686,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestPackedExtensionsLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestPackedExtensionsLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -9074,6 +9704,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestPackedExtensionsLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestPackedExtensionsLite.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); return this; } @@ -9083,6 +9714,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -9217,7 +9849,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestUnpackedExtensionsLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9227,21 +9859,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestUnpackedExtensionsLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestUnpackedExtensionsLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestUnpackedExtensionsLite result; - TestUnpackedExtensionsLite result = new TestUnpackedExtensionsLite(); + private TestUnpackedExtensionsLite PrepareBuilder() { + if (builderIsReadOnly) { + TestUnpackedExtensionsLite original = result; + result = new TestUnpackedExtensionsLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestUnpackedExtensionsLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestUnpackedExtensionsLite(); + result = DefaultInstance ?? new TestUnpackedExtensionsLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestUnpackedExtensionsLite DefaultInstanceForType { @@ -9249,12 +9908,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestUnpackedExtensionsLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestUnpackedExtensionsLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -9268,6 +9926,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestUnpackedExtensionsLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensionsLite.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); return this; } @@ -9277,6 +9936,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -9406,7 +10066,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestNestedExtensionLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9416,21 +10076,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestNestedExtensionLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestNestedExtensionLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestNestedExtensionLite result; + + private TestNestedExtensionLite PrepareBuilder() { + if (builderIsReadOnly) { + TestNestedExtensionLite original = result; + result = new TestNestedExtensionLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestNestedExtensionLite result = new TestNestedExtensionLite(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestNestedExtensionLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestNestedExtensionLite(); + result = DefaultInstance ?? new TestNestedExtensionLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestNestedExtensionLite DefaultInstanceForType { @@ -9438,12 +10125,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestNestedExtensionLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestNestedExtensionLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -9457,6 +10143,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestNestedExtensionLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestNestedExtensionLite.DefaultInstance) return this; + PrepareBuilder(); return this; } @@ -9465,6 +10152,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -9611,7 +10299,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestDeprecatedLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9621,21 +10309,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestDeprecatedLite(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestDeprecatedLite cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestDeprecatedLite result = new TestDeprecatedLite(); + bool builderIsReadOnly; + TestDeprecatedLite result; + + private TestDeprecatedLite PrepareBuilder() { + if (builderIsReadOnly) { + TestDeprecatedLite original = result; + result = new TestDeprecatedLite(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestDeprecatedLite MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestDeprecatedLite(); + result = DefaultInstance ?? new TestDeprecatedLite(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override TestDeprecatedLite DefaultInstanceForType { @@ -9643,12 +10358,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestDeprecatedLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestDeprecatedLite returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessageLite other) { @@ -9662,6 +10376,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestDeprecatedLite other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDeprecatedLite.DefaultInstance) return this; + PrepareBuilder(); if (other.HasDeprecatedField) { DeprecatedField = other.DeprecatedField; } @@ -9673,6 +10388,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); uint tag; string field_name; while (input.ReadTag(out tag, out field_name)) { @@ -9715,11 +10431,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDeprecatedField(value); } } public Builder SetDeprecatedField(int value) { + PrepareBuilder(); result.hasDeprecatedField = true; result.deprecatedField_ = value; return this; } public Builder ClearDeprecatedField() { + PrepareBuilder(); result.hasDeprecatedField = false; result.deprecatedField_ = 0; return this; diff --git a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestProtoFile.cs b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestProtoFile.cs index d8824d49a4..aeea673d57 100644 --- a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestProtoFile.cs +++ b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestProtoFile.cs @@ -1260,7 +1260,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(NestedMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1270,21 +1270,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(NestedMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + NestedMessage result; + + private NestedMessage PrepareBuilder() { + if (builderIsReadOnly) { + NestedMessage original = result; + result = new NestedMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - NestedMessage result = new NestedMessage(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override NestedMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new NestedMessage(); + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1296,12 +1323,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override NestedMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - NestedMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1315,6 +1341,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(NestedMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasBb) { Bb = other.Bb; } @@ -1327,6 +1354,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1382,11 +1410,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetBb(value); } } public Builder SetBb(int value) { + PrepareBuilder(); result.hasBb = true; result.bb_ = value; return this; } public Builder ClearBb() { + PrepareBuilder(); result.hasBb = false; result.bb_ = 0; return this; @@ -1499,7 +1529,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OptionalGroup prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1509,21 +1539,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OptionalGroup(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OptionalGroup cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + OptionalGroup result; + + private OptionalGroup PrepareBuilder() { + if (builderIsReadOnly) { + OptionalGroup original = result; + result = new OptionalGroup(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - OptionalGroup result = new OptionalGroup(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OptionalGroup MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OptionalGroup(); + result = DefaultInstance ?? new OptionalGroup(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1535,12 +1592,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OptionalGroup BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OptionalGroup returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1554,6 +1610,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OptionalGroup other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -1566,6 +1623,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1621,11 +1679,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -1738,7 +1798,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(RepeatedGroup prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -1748,21 +1808,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new RepeatedGroup(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(RepeatedGroup cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + RepeatedGroup result; - RepeatedGroup result = new RepeatedGroup(); + private RepeatedGroup PrepareBuilder() { + if (builderIsReadOnly) { + RepeatedGroup original = result; + result = new RepeatedGroup(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override RepeatedGroup MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new RepeatedGroup(); + result = DefaultInstance ?? new RepeatedGroup(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -1774,12 +1861,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override RepeatedGroup BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - RepeatedGroup returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -1793,6 +1879,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(RepeatedGroup other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -1805,6 +1892,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -1860,11 +1948,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -3181,7 +3271,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestAllTypes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -3191,21 +3281,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestAllTypes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestAllTypes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestAllTypes result; + + private TestAllTypes PrepareBuilder() { + if (builderIsReadOnly) { + TestAllTypes original = result; + result = new TestAllTypes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestAllTypes result = new TestAllTypes(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestAllTypes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestAllTypes(); + result = DefaultInstance ?? new TestAllTypes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -3217,8 +3334,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestAllTypes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedInt32_.MakeReadOnly(); result.repeatedInt64_.MakeReadOnly(); @@ -3244,9 +3361,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.repeatedImportEnum_.MakeReadOnly(); result.repeatedStringPiece_.MakeReadOnly(); result.repeatedCord_.MakeReadOnly(); - TestAllTypes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -3260,6 +3376,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestAllTypes other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance) return this; + PrepareBuilder(); if (other.HasOptionalInt32) { OptionalInt32 = other.OptionalInt32; } @@ -3473,6 +3590,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -3907,11 +4025,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalInt32(value); } } public Builder SetOptionalInt32(int value) { + PrepareBuilder(); result.hasOptionalInt32 = true; result.optionalInt32_ = value; return this; } public Builder ClearOptionalInt32() { + PrepareBuilder(); result.hasOptionalInt32 = false; result.optionalInt32_ = 0; return this; @@ -3925,11 +4045,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalInt64(value); } } public Builder SetOptionalInt64(long value) { + PrepareBuilder(); result.hasOptionalInt64 = true; result.optionalInt64_ = value; return this; } public Builder ClearOptionalInt64() { + PrepareBuilder(); result.hasOptionalInt64 = false; result.optionalInt64_ = 0L; return this; @@ -3945,11 +4067,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalUint32(uint value) { + PrepareBuilder(); result.hasOptionalUint32 = true; result.optionalUint32_ = value; return this; } public Builder ClearOptionalUint32() { + PrepareBuilder(); result.hasOptionalUint32 = false; result.optionalUint32_ = 0; return this; @@ -3965,11 +4089,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalUint64(ulong value) { + PrepareBuilder(); result.hasOptionalUint64 = true; result.optionalUint64_ = value; return this; } public Builder ClearOptionalUint64() { + PrepareBuilder(); result.hasOptionalUint64 = false; result.optionalUint64_ = 0UL; return this; @@ -3983,11 +4109,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSint32(value); } } public Builder SetOptionalSint32(int value) { + PrepareBuilder(); result.hasOptionalSint32 = true; result.optionalSint32_ = value; return this; } public Builder ClearOptionalSint32() { + PrepareBuilder(); result.hasOptionalSint32 = false; result.optionalSint32_ = 0; return this; @@ -4001,11 +4129,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSint64(value); } } public Builder SetOptionalSint64(long value) { + PrepareBuilder(); result.hasOptionalSint64 = true; result.optionalSint64_ = value; return this; } public Builder ClearOptionalSint64() { + PrepareBuilder(); result.hasOptionalSint64 = false; result.optionalSint64_ = 0; return this; @@ -4021,11 +4151,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalFixed32(uint value) { + PrepareBuilder(); result.hasOptionalFixed32 = true; result.optionalFixed32_ = value; return this; } public Builder ClearOptionalFixed32() { + PrepareBuilder(); result.hasOptionalFixed32 = false; result.optionalFixed32_ = 0; return this; @@ -4041,11 +4173,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetOptionalFixed64(ulong value) { + PrepareBuilder(); result.hasOptionalFixed64 = true; result.optionalFixed64_ = value; return this; } public Builder ClearOptionalFixed64() { + PrepareBuilder(); result.hasOptionalFixed64 = false; result.optionalFixed64_ = 0; return this; @@ -4059,11 +4193,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSfixed32(value); } } public Builder SetOptionalSfixed32(int value) { + PrepareBuilder(); result.hasOptionalSfixed32 = true; result.optionalSfixed32_ = value; return this; } public Builder ClearOptionalSfixed32() { + PrepareBuilder(); result.hasOptionalSfixed32 = false; result.optionalSfixed32_ = 0; return this; @@ -4077,11 +4213,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalSfixed64(value); } } public Builder SetOptionalSfixed64(long value) { + PrepareBuilder(); result.hasOptionalSfixed64 = true; result.optionalSfixed64_ = value; return this; } public Builder ClearOptionalSfixed64() { + PrepareBuilder(); result.hasOptionalSfixed64 = false; result.optionalSfixed64_ = 0; return this; @@ -4095,11 +4233,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalFloat(value); } } public Builder SetOptionalFloat(float value) { + PrepareBuilder(); result.hasOptionalFloat = true; result.optionalFloat_ = value; return this; } public Builder ClearOptionalFloat() { + PrepareBuilder(); result.hasOptionalFloat = false; result.optionalFloat_ = 0F; return this; @@ -4113,11 +4253,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalDouble(value); } } public Builder SetOptionalDouble(double value) { + PrepareBuilder(); result.hasOptionalDouble = true; result.optionalDouble_ = value; return this; } public Builder ClearOptionalDouble() { + PrepareBuilder(); result.hasOptionalDouble = false; result.optionalDouble_ = 0D; return this; @@ -4131,11 +4273,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalBool(value); } } public Builder SetOptionalBool(bool value) { + PrepareBuilder(); result.hasOptionalBool = true; result.optionalBool_ = value; return this; } public Builder ClearOptionalBool() { + PrepareBuilder(); result.hasOptionalBool = false; result.optionalBool_ = false; return this; @@ -4150,11 +4294,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalString = true; result.optionalString_ = value; return this; } public Builder ClearOptionalString() { + PrepareBuilder(); result.hasOptionalString = false; result.optionalString_ = ""; return this; @@ -4169,11 +4315,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalBytes = true; result.optionalBytes_ = value; return this; } public Builder ClearOptionalBytes() { + PrepareBuilder(); result.hasOptionalBytes = false; result.optionalBytes_ = pb::ByteString.Empty; return this; @@ -4188,18 +4336,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalGroup = true; result.optionalGroup_ = value; return this; } public Builder SetOptionalGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalGroup = true; result.optionalGroup_ = builderForValue.Build(); return this; } public Builder MergeOptionalGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalGroup && result.optionalGroup_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.DefaultInstance) { result.optionalGroup_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.CreateBuilder(result.optionalGroup_).MergeFrom(value).BuildPartial(); @@ -4210,6 +4361,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalGroup() { + PrepareBuilder(); result.hasOptionalGroup = false; result.optionalGroup_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.OptionalGroup.DefaultInstance; return this; @@ -4224,18 +4376,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = value; return this; } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalNestedMessage && result.optionalNestedMessage_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance) { result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.CreateBuilder(result.optionalNestedMessage_).MergeFrom(value).BuildPartial(); @@ -4246,6 +4401,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalNestedMessage() { + PrepareBuilder(); result.hasOptionalNestedMessage = false; result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance; return this; @@ -4260,18 +4416,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalForeignMessage = true; result.optionalForeignMessage_ = value; return this; } public Builder SetOptionalForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalForeignMessage = true; result.optionalForeignMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalForeignMessage && result.optionalForeignMessage_ != global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) { result.optionalForeignMessage_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.CreateBuilder(result.optionalForeignMessage_).MergeFrom(value).BuildPartial(); @@ -4282,6 +4441,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalForeignMessage() { + PrepareBuilder(); result.hasOptionalForeignMessage = false; result.optionalForeignMessage_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance; return this; @@ -4296,18 +4456,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalImportMessage = true; result.optionalImportMessage_ = value; return this; } public Builder SetOptionalImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalImportMessage = true; result.optionalImportMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalImportMessage && result.optionalImportMessage_ != global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) { result.optionalImportMessage_ = global::Google.ProtocolBuffers.TestProtos.ImportMessage.CreateBuilder(result.optionalImportMessage_).MergeFrom(value).BuildPartial(); @@ -4318,6 +4481,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalImportMessage() { + PrepareBuilder(); result.hasOptionalImportMessage = false; result.optionalImportMessage_ = global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance; return this; @@ -4331,11 +4495,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalNestedEnum(value); } } public Builder SetOptionalNestedEnum(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum value) { + PrepareBuilder(); result.hasOptionalNestedEnum = true; result.optionalNestedEnum_ = value; return this; } public Builder ClearOptionalNestedEnum() { + PrepareBuilder(); result.hasOptionalNestedEnum = false; result.optionalNestedEnum_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum.FOO; return this; @@ -4349,11 +4515,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalForeignEnum(value); } } public Builder SetOptionalForeignEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.hasOptionalForeignEnum = true; result.optionalForeignEnum_ = value; return this; } public Builder ClearOptionalForeignEnum() { + PrepareBuilder(); result.hasOptionalForeignEnum = false; result.optionalForeignEnum_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnum.FOREIGN_FOO; return this; @@ -4367,11 +4535,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalImportEnum(value); } } public Builder SetOptionalImportEnum(global::Google.ProtocolBuffers.TestProtos.ImportEnum value) { + PrepareBuilder(); result.hasOptionalImportEnum = true; result.optionalImportEnum_ = value; return this; } public Builder ClearOptionalImportEnum() { + PrepareBuilder(); result.hasOptionalImportEnum = false; result.optionalImportEnum_ = global::Google.ProtocolBuffers.TestProtos.ImportEnum.IMPORT_FOO; return this; @@ -4386,11 +4556,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalStringPiece(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalStringPiece = true; result.optionalStringPiece_ = value; return this; } public Builder ClearOptionalStringPiece() { + PrepareBuilder(); result.hasOptionalStringPiece = false; result.optionalStringPiece_ = ""; return this; @@ -4405,18 +4577,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalCord(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalCord = true; result.optionalCord_ = value; return this; } public Builder ClearOptionalCord() { + PrepareBuilder(); result.hasOptionalCord = false; result.optionalCord_ = ""; return this; } public pbc::IPopsicleList RepeatedInt32List { - get { return result.repeatedInt32_; } + get { return PrepareBuilder().repeatedInt32_; } } public int RepeatedInt32Count { get { return result.RepeatedInt32Count; } @@ -4425,24 +4599,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt32(index); } public Builder SetRepeatedInt32(int index, int value) { + PrepareBuilder(); result.repeatedInt32_[index] = value; return this; } public Builder AddRepeatedInt32(int value) { + PrepareBuilder(); result.repeatedInt32_.Add(value); return this; } public Builder AddRangeRepeatedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt32_); return this; } public Builder ClearRepeatedInt32() { + PrepareBuilder(); result.repeatedInt32_.Clear(); return this; } public pbc::IPopsicleList RepeatedInt64List { - get { return result.repeatedInt64_; } + get { return PrepareBuilder().repeatedInt64_; } } public int RepeatedInt64Count { get { return result.RepeatedInt64Count; } @@ -4451,25 +4629,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt64(index); } public Builder SetRepeatedInt64(int index, long value) { + PrepareBuilder(); result.repeatedInt64_[index] = value; return this; } public Builder AddRepeatedInt64(long value) { + PrepareBuilder(); result.repeatedInt64_.Add(value); return this; } public Builder AddRangeRepeatedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt64_); return this; } public Builder ClearRepeatedInt64() { + PrepareBuilder(); result.repeatedInt64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedUint32List { - get { return result.repeatedUint32_; } + get { return PrepareBuilder().repeatedUint32_; } } public int RepeatedUint32Count { get { return result.RepeatedUint32Count; } @@ -4480,27 +4662,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedUint32(int index, uint value) { + PrepareBuilder(); result.repeatedUint32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedUint32(uint value) { + PrepareBuilder(); result.repeatedUint32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedUint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedUint32_); return this; } public Builder ClearRepeatedUint32() { + PrepareBuilder(); result.repeatedUint32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedUint64List { - get { return result.repeatedUint64_; } + get { return PrepareBuilder().repeatedUint64_; } } public int RepeatedUint64Count { get { return result.RepeatedUint64Count; } @@ -4511,26 +4697,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedUint64(int index, ulong value) { + PrepareBuilder(); result.repeatedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedUint64(ulong value) { + PrepareBuilder(); result.repeatedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedUint64_); return this; } public Builder ClearRepeatedUint64() { + PrepareBuilder(); result.repeatedUint64_.Clear(); return this; } public pbc::IPopsicleList RepeatedSint32List { - get { return result.repeatedSint32_; } + get { return PrepareBuilder().repeatedSint32_; } } public int RepeatedSint32Count { get { return result.RepeatedSint32Count; } @@ -4539,24 +4729,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSint32(index); } public Builder SetRepeatedSint32(int index, int value) { + PrepareBuilder(); result.repeatedSint32_[index] = value; return this; } public Builder AddRepeatedSint32(int value) { + PrepareBuilder(); result.repeatedSint32_.Add(value); return this; } public Builder AddRangeRepeatedSint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSint32_); return this; } public Builder ClearRepeatedSint32() { + PrepareBuilder(); result.repeatedSint32_.Clear(); return this; } public pbc::IPopsicleList RepeatedSint64List { - get { return result.repeatedSint64_; } + get { return PrepareBuilder().repeatedSint64_; } } public int RepeatedSint64Count { get { return result.RepeatedSint64Count; } @@ -4565,25 +4759,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSint64(index); } public Builder SetRepeatedSint64(int index, long value) { + PrepareBuilder(); result.repeatedSint64_[index] = value; return this; } public Builder AddRepeatedSint64(long value) { + PrepareBuilder(); result.repeatedSint64_.Add(value); return this; } public Builder AddRangeRepeatedSint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSint64_); return this; } public Builder ClearRepeatedSint64() { + PrepareBuilder(); result.repeatedSint64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed32List { - get { return result.repeatedFixed32_; } + get { return PrepareBuilder().repeatedFixed32_; } } public int RepeatedFixed32Count { get { return result.RepeatedFixed32Count; } @@ -4594,27 +4792,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed32(int index, uint value) { + PrepareBuilder(); result.repeatedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed32(uint value) { + PrepareBuilder(); result.repeatedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed32_); return this; } public Builder ClearRepeatedFixed32() { + PrepareBuilder(); result.repeatedFixed32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed64List { - get { return result.repeatedFixed64_; } + get { return PrepareBuilder().repeatedFixed64_; } } public int RepeatedFixed64Count { get { return result.RepeatedFixed64Count; } @@ -4625,26 +4827,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed64(int index, ulong value) { + PrepareBuilder(); result.repeatedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed64(ulong value) { + PrepareBuilder(); result.repeatedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed64_); return this; } public Builder ClearRepeatedFixed64() { + PrepareBuilder(); result.repeatedFixed64_.Clear(); return this; } public pbc::IPopsicleList RepeatedSfixed32List { - get { return result.repeatedSfixed32_; } + get { return PrepareBuilder().repeatedSfixed32_; } } public int RepeatedSfixed32Count { get { return result.RepeatedSfixed32Count; } @@ -4653,24 +4859,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSfixed32(index); } public Builder SetRepeatedSfixed32(int index, int value) { + PrepareBuilder(); result.repeatedSfixed32_[index] = value; return this; } public Builder AddRepeatedSfixed32(int value) { + PrepareBuilder(); result.repeatedSfixed32_.Add(value); return this; } public Builder AddRangeRepeatedSfixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSfixed32_); return this; } public Builder ClearRepeatedSfixed32() { + PrepareBuilder(); result.repeatedSfixed32_.Clear(); return this; } public pbc::IPopsicleList RepeatedSfixed64List { - get { return result.repeatedSfixed64_; } + get { return PrepareBuilder().repeatedSfixed64_; } } public int RepeatedSfixed64Count { get { return result.RepeatedSfixed64Count; } @@ -4679,24 +4889,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedSfixed64(index); } public Builder SetRepeatedSfixed64(int index, long value) { + PrepareBuilder(); result.repeatedSfixed64_[index] = value; return this; } public Builder AddRepeatedSfixed64(long value) { + PrepareBuilder(); result.repeatedSfixed64_.Add(value); return this; } public Builder AddRangeRepeatedSfixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedSfixed64_); return this; } public Builder ClearRepeatedSfixed64() { + PrepareBuilder(); result.repeatedSfixed64_.Clear(); return this; } public pbc::IPopsicleList RepeatedFloatList { - get { return result.repeatedFloat_; } + get { return PrepareBuilder().repeatedFloat_; } } public int RepeatedFloatCount { get { return result.RepeatedFloatCount; } @@ -4705,24 +4919,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedFloat(index); } public Builder SetRepeatedFloat(int index, float value) { + PrepareBuilder(); result.repeatedFloat_[index] = value; return this; } public Builder AddRepeatedFloat(float value) { + PrepareBuilder(); result.repeatedFloat_.Add(value); return this; } public Builder AddRangeRepeatedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFloat_); return this; } public Builder ClearRepeatedFloat() { + PrepareBuilder(); result.repeatedFloat_.Clear(); return this; } public pbc::IPopsicleList RepeatedDoubleList { - get { return result.repeatedDouble_; } + get { return PrepareBuilder().repeatedDouble_; } } public int RepeatedDoubleCount { get { return result.RepeatedDoubleCount; } @@ -4731,24 +4949,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedDouble(index); } public Builder SetRepeatedDouble(int index, double value) { + PrepareBuilder(); result.repeatedDouble_[index] = value; return this; } public Builder AddRepeatedDouble(double value) { + PrepareBuilder(); result.repeatedDouble_.Add(value); return this; } public Builder AddRangeRepeatedDouble(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedDouble_); return this; } public Builder ClearRepeatedDouble() { + PrepareBuilder(); result.repeatedDouble_.Clear(); return this; } public pbc::IPopsicleList RepeatedBoolList { - get { return result.repeatedBool_; } + get { return PrepareBuilder().repeatedBool_; } } public int RepeatedBoolCount { get { return result.RepeatedBoolCount; } @@ -4757,24 +4979,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedBool(index); } public Builder SetRepeatedBool(int index, bool value) { + PrepareBuilder(); result.repeatedBool_[index] = value; return this; } public Builder AddRepeatedBool(bool value) { + PrepareBuilder(); result.repeatedBool_.Add(value); return this; } public Builder AddRangeRepeatedBool(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedBool_); return this; } public Builder ClearRepeatedBool() { + PrepareBuilder(); result.repeatedBool_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringList { - get { return result.repeatedString_; } + get { return PrepareBuilder().repeatedString_; } } public int RepeatedStringCount { get { return result.RepeatedStringCount; } @@ -4784,25 +5010,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedString(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedString_[index] = value; return this; } public Builder AddRepeatedString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedString_.Add(value); return this; } public Builder AddRangeRepeatedString(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedString_); return this; } public Builder ClearRepeatedString() { + PrepareBuilder(); result.repeatedString_.Clear(); return this; } public pbc::IPopsicleList RepeatedBytesList { - get { return result.repeatedBytes_; } + get { return PrepareBuilder().repeatedBytes_; } } public int RepeatedBytesCount { get { return result.RepeatedBytesCount; } @@ -4812,25 +5042,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedBytes(int index, pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedBytes_[index] = value; return this; } public Builder AddRepeatedBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedBytes_.Add(value); return this; } public Builder AddRangeRepeatedBytes(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedBytes_); return this; } public Builder ClearRepeatedBytes() { + PrepareBuilder(); result.repeatedBytes_.Clear(); return this; } public pbc::IPopsicleList RepeatedGroupList { - get { return result.repeatedGroup_; } + get { return PrepareBuilder().repeatedGroup_; } } public int RepeatedGroupCount { get { return result.RepeatedGroupCount; } @@ -4840,35 +5074,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedGroup(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedGroup_[index] = value; return this; } public Builder SetRepeatedGroup(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedGroup_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedGroup_.Add(value); return this; } public Builder AddRepeatedGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedGroup_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedGroup(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedGroup_); return this; } public Builder ClearRepeatedGroup() { + PrepareBuilder(); result.repeatedGroup_.Clear(); return this; } public pbc::IPopsicleList RepeatedNestedMessageList { - get { return result.repeatedNestedMessage_; } + get { return PrepareBuilder().repeatedNestedMessage_; } } public int RepeatedNestedMessageCount { get { return result.RepeatedNestedMessageCount; } @@ -4878,35 +5118,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedNestedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedNestedMessage_[index] = value; return this; } public Builder SetRepeatedNestedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedNestedMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedNestedMessage_.Add(value); return this; } public Builder AddRepeatedNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedNestedMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedNestedMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedNestedMessage_); return this; } public Builder ClearRepeatedNestedMessage() { + PrepareBuilder(); result.repeatedNestedMessage_.Clear(); return this; } public pbc::IPopsicleList RepeatedForeignMessageList { - get { return result.repeatedForeignMessage_; } + get { return PrepareBuilder().repeatedForeignMessage_; } } public int RepeatedForeignMessageCount { get { return result.RepeatedForeignMessageCount; } @@ -4916,35 +5162,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedForeignMessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedForeignMessage_[index] = value; return this; } public Builder SetRepeatedForeignMessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedForeignMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedForeignMessage_.Add(value); return this; } public Builder AddRepeatedForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedForeignMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedForeignMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedForeignMessage_); return this; } public Builder ClearRepeatedForeignMessage() { + PrepareBuilder(); result.repeatedForeignMessage_.Clear(); return this; } public pbc::IPopsicleList RepeatedImportMessageList { - get { return result.repeatedImportMessage_; } + get { return PrepareBuilder().repeatedImportMessage_; } } public int RepeatedImportMessageCount { get { return result.RepeatedImportMessageCount; } @@ -4954,35 +5206,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedImportMessage(int index, global::Google.ProtocolBuffers.TestProtos.ImportMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedImportMessage_[index] = value; return this; } public Builder SetRepeatedImportMessage(int index, global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedImportMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedImportMessage_.Add(value); return this; } public Builder AddRepeatedImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedImportMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedImportMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedImportMessage_); return this; } public Builder ClearRepeatedImportMessage() { + PrepareBuilder(); result.repeatedImportMessage_.Clear(); return this; } public pbc::IPopsicleList RepeatedNestedEnumList { - get { return result.repeatedNestedEnum_; } + get { return PrepareBuilder().repeatedNestedEnum_; } } public int RepeatedNestedEnumCount { get { return result.RepeatedNestedEnumCount; } @@ -4991,24 +5249,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedNestedEnum(index); } public Builder SetRepeatedNestedEnum(int index, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum value) { + PrepareBuilder(); result.repeatedNestedEnum_[index] = value; return this; } public Builder AddRepeatedNestedEnum(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum value) { + PrepareBuilder(); result.repeatedNestedEnum_.Add(value); return this; } public Builder AddRangeRepeatedNestedEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedNestedEnum_); return this; } public Builder ClearRepeatedNestedEnum() { + PrepareBuilder(); result.repeatedNestedEnum_.Clear(); return this; } public pbc::IPopsicleList RepeatedForeignEnumList { - get { return result.repeatedForeignEnum_; } + get { return PrepareBuilder().repeatedForeignEnum_; } } public int RepeatedForeignEnumCount { get { return result.RepeatedForeignEnumCount; } @@ -5017,24 +5279,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedForeignEnum(index); } public Builder SetRepeatedForeignEnum(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.repeatedForeignEnum_[index] = value; return this; } public Builder AddRepeatedForeignEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.repeatedForeignEnum_.Add(value); return this; } public Builder AddRangeRepeatedForeignEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedForeignEnum_); return this; } public Builder ClearRepeatedForeignEnum() { + PrepareBuilder(); result.repeatedForeignEnum_.Clear(); return this; } public pbc::IPopsicleList RepeatedImportEnumList { - get { return result.repeatedImportEnum_; } + get { return PrepareBuilder().repeatedImportEnum_; } } public int RepeatedImportEnumCount { get { return result.RepeatedImportEnumCount; } @@ -5043,24 +5309,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedImportEnum(index); } public Builder SetRepeatedImportEnum(int index, global::Google.ProtocolBuffers.TestProtos.ImportEnum value) { + PrepareBuilder(); result.repeatedImportEnum_[index] = value; return this; } public Builder AddRepeatedImportEnum(global::Google.ProtocolBuffers.TestProtos.ImportEnum value) { + PrepareBuilder(); result.repeatedImportEnum_.Add(value); return this; } public Builder AddRangeRepeatedImportEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedImportEnum_); return this; } public Builder ClearRepeatedImportEnum() { + PrepareBuilder(); result.repeatedImportEnum_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringPieceList { - get { return result.repeatedStringPiece_; } + get { return PrepareBuilder().repeatedStringPiece_; } } public int RepeatedStringPieceCount { get { return result.RepeatedStringPieceCount; } @@ -5070,25 +5340,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedStringPiece(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPiece_[index] = value; return this; } public Builder AddRepeatedStringPiece(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPiece_.Add(value); return this; } public Builder AddRangeRepeatedStringPiece(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedStringPiece_); return this; } public Builder ClearRepeatedStringPiece() { + PrepareBuilder(); result.repeatedStringPiece_.Clear(); return this; } public pbc::IPopsicleList RepeatedCordList { - get { return result.repeatedCord_; } + get { return PrepareBuilder().repeatedCord_; } } public int RepeatedCordCount { get { return result.RepeatedCordCount; } @@ -5098,19 +5372,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedCord(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCord_[index] = value; return this; } public Builder AddRepeatedCord(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCord_.Add(value); return this; } public Builder AddRangeRepeatedCord(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedCord_); return this; } public Builder ClearRepeatedCord() { + PrepareBuilder(); result.repeatedCord_.Clear(); return this; } @@ -5123,11 +5401,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultInt32(value); } } public Builder SetDefaultInt32(int value) { + PrepareBuilder(); result.hasDefaultInt32 = true; result.defaultInt32_ = value; return this; } public Builder ClearDefaultInt32() { + PrepareBuilder(); result.hasDefaultInt32 = false; result.defaultInt32_ = 41; return this; @@ -5141,11 +5421,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultInt64(value); } } public Builder SetDefaultInt64(long value) { + PrepareBuilder(); result.hasDefaultInt64 = true; result.defaultInt64_ = value; return this; } public Builder ClearDefaultInt64() { + PrepareBuilder(); result.hasDefaultInt64 = false; result.defaultInt64_ = 42L; return this; @@ -5161,11 +5443,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultUint32(uint value) { + PrepareBuilder(); result.hasDefaultUint32 = true; result.defaultUint32_ = value; return this; } public Builder ClearDefaultUint32() { + PrepareBuilder(); result.hasDefaultUint32 = false; result.defaultUint32_ = 43; return this; @@ -5181,11 +5465,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultUint64(ulong value) { + PrepareBuilder(); result.hasDefaultUint64 = true; result.defaultUint64_ = value; return this; } public Builder ClearDefaultUint64() { + PrepareBuilder(); result.hasDefaultUint64 = false; result.defaultUint64_ = 44UL; return this; @@ -5199,11 +5485,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSint32(value); } } public Builder SetDefaultSint32(int value) { + PrepareBuilder(); result.hasDefaultSint32 = true; result.defaultSint32_ = value; return this; } public Builder ClearDefaultSint32() { + PrepareBuilder(); result.hasDefaultSint32 = false; result.defaultSint32_ = -45; return this; @@ -5217,11 +5505,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSint64(value); } } public Builder SetDefaultSint64(long value) { + PrepareBuilder(); result.hasDefaultSint64 = true; result.defaultSint64_ = value; return this; } public Builder ClearDefaultSint64() { + PrepareBuilder(); result.hasDefaultSint64 = false; result.defaultSint64_ = 46; return this; @@ -5237,11 +5527,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultFixed32(uint value) { + PrepareBuilder(); result.hasDefaultFixed32 = true; result.defaultFixed32_ = value; return this; } public Builder ClearDefaultFixed32() { + PrepareBuilder(); result.hasDefaultFixed32 = false; result.defaultFixed32_ = 47; return this; @@ -5257,11 +5549,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetDefaultFixed64(ulong value) { + PrepareBuilder(); result.hasDefaultFixed64 = true; result.defaultFixed64_ = value; return this; } public Builder ClearDefaultFixed64() { + PrepareBuilder(); result.hasDefaultFixed64 = false; result.defaultFixed64_ = 48; return this; @@ -5275,11 +5569,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSfixed32(value); } } public Builder SetDefaultSfixed32(int value) { + PrepareBuilder(); result.hasDefaultSfixed32 = true; result.defaultSfixed32_ = value; return this; } public Builder ClearDefaultSfixed32() { + PrepareBuilder(); result.hasDefaultSfixed32 = false; result.defaultSfixed32_ = 49; return this; @@ -5293,11 +5589,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultSfixed64(value); } } public Builder SetDefaultSfixed64(long value) { + PrepareBuilder(); result.hasDefaultSfixed64 = true; result.defaultSfixed64_ = value; return this; } public Builder ClearDefaultSfixed64() { + PrepareBuilder(); result.hasDefaultSfixed64 = false; result.defaultSfixed64_ = -50; return this; @@ -5311,11 +5609,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultFloat(value); } } public Builder SetDefaultFloat(float value) { + PrepareBuilder(); result.hasDefaultFloat = true; result.defaultFloat_ = value; return this; } public Builder ClearDefaultFloat() { + PrepareBuilder(); result.hasDefaultFloat = false; result.defaultFloat_ = 51.5F; return this; @@ -5329,11 +5629,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultDouble(value); } } public Builder SetDefaultDouble(double value) { + PrepareBuilder(); result.hasDefaultDouble = true; result.defaultDouble_ = value; return this; } public Builder ClearDefaultDouble() { + PrepareBuilder(); result.hasDefaultDouble = false; result.defaultDouble_ = 52000D; return this; @@ -5347,11 +5649,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultBool(value); } } public Builder SetDefaultBool(bool value) { + PrepareBuilder(); result.hasDefaultBool = true; result.defaultBool_ = value; return this; } public Builder ClearDefaultBool() { + PrepareBuilder(); result.hasDefaultBool = false; result.defaultBool_ = true; return this; @@ -5366,11 +5670,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultString = true; result.defaultString_ = value; return this; } public Builder ClearDefaultString() { + PrepareBuilder(); result.hasDefaultString = false; result.defaultString_ = "hello"; return this; @@ -5385,11 +5691,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultBytes = true; result.defaultBytes_ = value; return this; } public Builder ClearDefaultBytes() { + PrepareBuilder(); result.hasDefaultBytes = false; result.defaultBytes_ = (pb::ByteString) global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Descriptor.Fields[62].DefaultValue; return this; @@ -5403,11 +5711,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultNestedEnum(value); } } public Builder SetDefaultNestedEnum(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum value) { + PrepareBuilder(); result.hasDefaultNestedEnum = true; result.defaultNestedEnum_ = value; return this; } public Builder ClearDefaultNestedEnum() { + PrepareBuilder(); result.hasDefaultNestedEnum = false; result.defaultNestedEnum_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedEnum.BAR; return this; @@ -5421,11 +5731,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultForeignEnum(value); } } public Builder SetDefaultForeignEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.hasDefaultForeignEnum = true; result.defaultForeignEnum_ = value; return this; } public Builder ClearDefaultForeignEnum() { + PrepareBuilder(); result.hasDefaultForeignEnum = false; result.defaultForeignEnum_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnum.FOREIGN_BAR; return this; @@ -5439,11 +5751,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDefaultImportEnum(value); } } public Builder SetDefaultImportEnum(global::Google.ProtocolBuffers.TestProtos.ImportEnum value) { + PrepareBuilder(); result.hasDefaultImportEnum = true; result.defaultImportEnum_ = value; return this; } public Builder ClearDefaultImportEnum() { + PrepareBuilder(); result.hasDefaultImportEnum = false; result.defaultImportEnum_ = global::Google.ProtocolBuffers.TestProtos.ImportEnum.IMPORT_BAR; return this; @@ -5458,11 +5772,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultStringPiece(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultStringPiece = true; result.defaultStringPiece_ = value; return this; } public Builder ClearDefaultStringPiece() { + PrepareBuilder(); result.hasDefaultStringPiece = false; result.defaultStringPiece_ = "abc"; return this; @@ -5477,11 +5793,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDefaultCord(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDefaultCord = true; result.defaultCord_ = value; return this; } public Builder ClearDefaultCord() { + PrepareBuilder(); result.hasDefaultCord = false; result.defaultCord_ = "123"; return this; @@ -5594,7 +5912,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestDeprecatedFields prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -5604,21 +5922,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestDeprecatedFields(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestDeprecatedFields cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestDeprecatedFields result; - TestDeprecatedFields result = new TestDeprecatedFields(); + private TestDeprecatedFields PrepareBuilder() { + if (builderIsReadOnly) { + TestDeprecatedFields original = result; + result = new TestDeprecatedFields(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestDeprecatedFields MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestDeprecatedFields(); + result = DefaultInstance ?? new TestDeprecatedFields(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -5630,12 +5975,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestDeprecatedFields BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestDeprecatedFields returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -5649,6 +5993,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestDeprecatedFields other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDeprecatedFields.DefaultInstance) return this; + PrepareBuilder(); if (other.HasDeprecatedInt32) { DeprecatedInt32 = other.DeprecatedInt32; } @@ -5661,6 +6006,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -5716,11 +6062,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDeprecatedInt32(value); } } public Builder SetDeprecatedInt32(int value) { + PrepareBuilder(); result.hasDeprecatedInt32 = true; result.deprecatedInt32_ = value; return this; } public Builder ClearDeprecatedInt32() { + PrepareBuilder(); result.hasDeprecatedInt32 = false; result.deprecatedInt32_ = 0; return this; @@ -5833,7 +6181,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(ForeignMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -5843,21 +6191,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new ForeignMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(ForeignMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - ForeignMessage result = new ForeignMessage(); + bool builderIsReadOnly; + ForeignMessage result; + + private ForeignMessage PrepareBuilder() { + if (builderIsReadOnly) { + ForeignMessage original = result; + result = new ForeignMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override ForeignMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new ForeignMessage(); + result = DefaultInstance ?? new ForeignMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -5869,12 +6244,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override ForeignMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - ForeignMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -5888,6 +6262,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(ForeignMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasC) { C = other.C; } @@ -5900,6 +6275,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -5955,11 +6331,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetC(value); } } public Builder SetC(int value) { + PrepareBuilder(); result.hasC = true; result.c_ = value; return this; } public Builder ClearC() { + PrepareBuilder(); result.hasC = false; result.c_ = 0; return this; @@ -6060,7 +6438,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestAllExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6070,21 +6448,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestAllExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestAllExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestAllExtensions result = new TestAllExtensions(); + bool builderIsReadOnly; + TestAllExtensions result; + + private TestAllExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestAllExtensions original = result; + result = new TestAllExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestAllExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestAllExtensions(); + result = DefaultInstance ?? new TestAllExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6096,12 +6501,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestAllExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestAllExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6115,6 +6519,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestAllExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestAllExtensions.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -6125,6 +6530,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6275,7 +6681,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OptionalGroup_extension prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6285,21 +6691,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OptionalGroup_extension(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OptionalGroup_extension cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - OptionalGroup_extension result = new OptionalGroup_extension(); + bool builderIsReadOnly; + OptionalGroup_extension result; + + private OptionalGroup_extension PrepareBuilder() { + if (builderIsReadOnly) { + OptionalGroup_extension original = result; + result = new OptionalGroup_extension(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OptionalGroup_extension MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OptionalGroup_extension(); + result = DefaultInstance ?? new OptionalGroup_extension(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6311,12 +6744,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OptionalGroup_extension BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OptionalGroup_extension returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6330,6 +6762,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OptionalGroup_extension other) { if (other == global::Google.ProtocolBuffers.TestProtos.OptionalGroup_extension.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -6342,6 +6775,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6397,11 +6831,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -6514,7 +6950,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(RepeatedGroup_extension prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6524,21 +6960,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new RepeatedGroup_extension(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(RepeatedGroup_extension cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + RepeatedGroup_extension result; + + private RepeatedGroup_extension PrepareBuilder() { + if (builderIsReadOnly) { + RepeatedGroup_extension original = result; + result = new RepeatedGroup_extension(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - RepeatedGroup_extension result = new RepeatedGroup_extension(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override RepeatedGroup_extension MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new RepeatedGroup_extension(); + result = DefaultInstance ?? new RepeatedGroup_extension(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6550,12 +7013,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override RepeatedGroup_extension BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - RepeatedGroup_extension returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6569,6 +7031,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(RepeatedGroup_extension other) { if (other == global::Google.ProtocolBuffers.TestProtos.RepeatedGroup_extension.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -6581,6 +7044,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -6636,11 +7100,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -6739,7 +7205,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestNestedExtension prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -6749,21 +7215,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestNestedExtension(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestNestedExtension cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestNestedExtension result; + + private TestNestedExtension PrepareBuilder() { + if (builderIsReadOnly) { + TestNestedExtension original = result; + result = new TestNestedExtension(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestNestedExtension result = new TestNestedExtension(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestNestedExtension MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestNestedExtension(); + result = DefaultInstance ?? new TestNestedExtension(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -6775,12 +7268,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestNestedExtension BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestNestedExtension returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -6794,6 +7286,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestNestedExtension other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestNestedExtension.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -6803,6 +7296,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -7472,7 +7966,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRequired prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -7482,21 +7976,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRequired(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRequired cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestRequired result = new TestRequired(); + bool builderIsReadOnly; + TestRequired result; + + private TestRequired PrepareBuilder() { + if (builderIsReadOnly) { + TestRequired original = result; + result = new TestRequired(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRequired MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRequired(); + result = DefaultInstance ?? new TestRequired(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -7508,12 +8029,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRequired BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestRequired returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -7527,6 +8047,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestRequired other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestRequired.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -7635,6 +8156,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -7818,11 +8340,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -7836,11 +8360,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy2(value); } } public Builder SetDummy2(int value) { + PrepareBuilder(); result.hasDummy2 = true; result.dummy2_ = value; return this; } public Builder ClearDummy2() { + PrepareBuilder(); result.hasDummy2 = false; result.dummy2_ = 0; return this; @@ -7854,11 +8380,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetB(value); } } public Builder SetB(int value) { + PrepareBuilder(); result.hasB = true; result.b_ = value; return this; } public Builder ClearB() { + PrepareBuilder(); result.hasB = false; result.b_ = 0; return this; @@ -7872,11 +8400,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy4(value); } } public Builder SetDummy4(int value) { + PrepareBuilder(); result.hasDummy4 = true; result.dummy4_ = value; return this; } public Builder ClearDummy4() { + PrepareBuilder(); result.hasDummy4 = false; result.dummy4_ = 0; return this; @@ -7890,11 +8420,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy5(value); } } public Builder SetDummy5(int value) { + PrepareBuilder(); result.hasDummy5 = true; result.dummy5_ = value; return this; } public Builder ClearDummy5() { + PrepareBuilder(); result.hasDummy5 = false; result.dummy5_ = 0; return this; @@ -7908,11 +8440,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy6(value); } } public Builder SetDummy6(int value) { + PrepareBuilder(); result.hasDummy6 = true; result.dummy6_ = value; return this; } public Builder ClearDummy6() { + PrepareBuilder(); result.hasDummy6 = false; result.dummy6_ = 0; return this; @@ -7926,11 +8460,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy7(value); } } public Builder SetDummy7(int value) { + PrepareBuilder(); result.hasDummy7 = true; result.dummy7_ = value; return this; } public Builder ClearDummy7() { + PrepareBuilder(); result.hasDummy7 = false; result.dummy7_ = 0; return this; @@ -7944,11 +8480,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy8(value); } } public Builder SetDummy8(int value) { + PrepareBuilder(); result.hasDummy8 = true; result.dummy8_ = value; return this; } public Builder ClearDummy8() { + PrepareBuilder(); result.hasDummy8 = false; result.dummy8_ = 0; return this; @@ -7962,11 +8500,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy9(value); } } public Builder SetDummy9(int value) { + PrepareBuilder(); result.hasDummy9 = true; result.dummy9_ = value; return this; } public Builder ClearDummy9() { + PrepareBuilder(); result.hasDummy9 = false; result.dummy9_ = 0; return this; @@ -7980,11 +8520,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy10(value); } } public Builder SetDummy10(int value) { + PrepareBuilder(); result.hasDummy10 = true; result.dummy10_ = value; return this; } public Builder ClearDummy10() { + PrepareBuilder(); result.hasDummy10 = false; result.dummy10_ = 0; return this; @@ -7998,11 +8540,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy11(value); } } public Builder SetDummy11(int value) { + PrepareBuilder(); result.hasDummy11 = true; result.dummy11_ = value; return this; } public Builder ClearDummy11() { + PrepareBuilder(); result.hasDummy11 = false; result.dummy11_ = 0; return this; @@ -8016,11 +8560,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy12(value); } } public Builder SetDummy12(int value) { + PrepareBuilder(); result.hasDummy12 = true; result.dummy12_ = value; return this; } public Builder ClearDummy12() { + PrepareBuilder(); result.hasDummy12 = false; result.dummy12_ = 0; return this; @@ -8034,11 +8580,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy13(value); } } public Builder SetDummy13(int value) { + PrepareBuilder(); result.hasDummy13 = true; result.dummy13_ = value; return this; } public Builder ClearDummy13() { + PrepareBuilder(); result.hasDummy13 = false; result.dummy13_ = 0; return this; @@ -8052,11 +8600,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy14(value); } } public Builder SetDummy14(int value) { + PrepareBuilder(); result.hasDummy14 = true; result.dummy14_ = value; return this; } public Builder ClearDummy14() { + PrepareBuilder(); result.hasDummy14 = false; result.dummy14_ = 0; return this; @@ -8070,11 +8620,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy15(value); } } public Builder SetDummy15(int value) { + PrepareBuilder(); result.hasDummy15 = true; result.dummy15_ = value; return this; } public Builder ClearDummy15() { + PrepareBuilder(); result.hasDummy15 = false; result.dummy15_ = 0; return this; @@ -8088,11 +8640,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy16(value); } } public Builder SetDummy16(int value) { + PrepareBuilder(); result.hasDummy16 = true; result.dummy16_ = value; return this; } public Builder ClearDummy16() { + PrepareBuilder(); result.hasDummy16 = false; result.dummy16_ = 0; return this; @@ -8106,11 +8660,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy17(value); } } public Builder SetDummy17(int value) { + PrepareBuilder(); result.hasDummy17 = true; result.dummy17_ = value; return this; } public Builder ClearDummy17() { + PrepareBuilder(); result.hasDummy17 = false; result.dummy17_ = 0; return this; @@ -8124,11 +8680,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy18(value); } } public Builder SetDummy18(int value) { + PrepareBuilder(); result.hasDummy18 = true; result.dummy18_ = value; return this; } public Builder ClearDummy18() { + PrepareBuilder(); result.hasDummy18 = false; result.dummy18_ = 0; return this; @@ -8142,11 +8700,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy19(value); } } public Builder SetDummy19(int value) { + PrepareBuilder(); result.hasDummy19 = true; result.dummy19_ = value; return this; } public Builder ClearDummy19() { + PrepareBuilder(); result.hasDummy19 = false; result.dummy19_ = 0; return this; @@ -8160,11 +8720,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy20(value); } } public Builder SetDummy20(int value) { + PrepareBuilder(); result.hasDummy20 = true; result.dummy20_ = value; return this; } public Builder ClearDummy20() { + PrepareBuilder(); result.hasDummy20 = false; result.dummy20_ = 0; return this; @@ -8178,11 +8740,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy21(value); } } public Builder SetDummy21(int value) { + PrepareBuilder(); result.hasDummy21 = true; result.dummy21_ = value; return this; } public Builder ClearDummy21() { + PrepareBuilder(); result.hasDummy21 = false; result.dummy21_ = 0; return this; @@ -8196,11 +8760,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy22(value); } } public Builder SetDummy22(int value) { + PrepareBuilder(); result.hasDummy22 = true; result.dummy22_ = value; return this; } public Builder ClearDummy22() { + PrepareBuilder(); result.hasDummy22 = false; result.dummy22_ = 0; return this; @@ -8214,11 +8780,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy23(value); } } public Builder SetDummy23(int value) { + PrepareBuilder(); result.hasDummy23 = true; result.dummy23_ = value; return this; } public Builder ClearDummy23() { + PrepareBuilder(); result.hasDummy23 = false; result.dummy23_ = 0; return this; @@ -8232,11 +8800,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy24(value); } } public Builder SetDummy24(int value) { + PrepareBuilder(); result.hasDummy24 = true; result.dummy24_ = value; return this; } public Builder ClearDummy24() { + PrepareBuilder(); result.hasDummy24 = false; result.dummy24_ = 0; return this; @@ -8250,11 +8820,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy25(value); } } public Builder SetDummy25(int value) { + PrepareBuilder(); result.hasDummy25 = true; result.dummy25_ = value; return this; } public Builder ClearDummy25() { + PrepareBuilder(); result.hasDummy25 = false; result.dummy25_ = 0; return this; @@ -8268,11 +8840,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy26(value); } } public Builder SetDummy26(int value) { + PrepareBuilder(); result.hasDummy26 = true; result.dummy26_ = value; return this; } public Builder ClearDummy26() { + PrepareBuilder(); result.hasDummy26 = false; result.dummy26_ = 0; return this; @@ -8286,11 +8860,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy27(value); } } public Builder SetDummy27(int value) { + PrepareBuilder(); result.hasDummy27 = true; result.dummy27_ = value; return this; } public Builder ClearDummy27() { + PrepareBuilder(); result.hasDummy27 = false; result.dummy27_ = 0; return this; @@ -8304,11 +8880,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy28(value); } } public Builder SetDummy28(int value) { + PrepareBuilder(); result.hasDummy28 = true; result.dummy28_ = value; return this; } public Builder ClearDummy28() { + PrepareBuilder(); result.hasDummy28 = false; result.dummy28_ = 0; return this; @@ -8322,11 +8900,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy29(value); } } public Builder SetDummy29(int value) { + PrepareBuilder(); result.hasDummy29 = true; result.dummy29_ = value; return this; } public Builder ClearDummy29() { + PrepareBuilder(); result.hasDummy29 = false; result.dummy29_ = 0; return this; @@ -8340,11 +8920,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy30(value); } } public Builder SetDummy30(int value) { + PrepareBuilder(); result.hasDummy30 = true; result.dummy30_ = value; return this; } public Builder ClearDummy30() { + PrepareBuilder(); result.hasDummy30 = false; result.dummy30_ = 0; return this; @@ -8358,11 +8940,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy31(value); } } public Builder SetDummy31(int value) { + PrepareBuilder(); result.hasDummy31 = true; result.dummy31_ = value; return this; } public Builder ClearDummy31() { + PrepareBuilder(); result.hasDummy31 = false; result.dummy31_ = 0; return this; @@ -8376,11 +8960,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy32(value); } } public Builder SetDummy32(int value) { + PrepareBuilder(); result.hasDummy32 = true; result.dummy32_ = value; return this; } public Builder ClearDummy32() { + PrepareBuilder(); result.hasDummy32 = false; result.dummy32_ = 0; return this; @@ -8394,11 +8980,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetC(value); } } public Builder SetC(int value) { + PrepareBuilder(); result.hasC = true; result.c_ = value; return this; } public Builder ClearC() { + PrepareBuilder(); result.hasC = false; result.c_ = 0; return this; @@ -8551,7 +9139,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRequiredForeign prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -8561,21 +9149,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRequiredForeign(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRequiredForeign cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestRequiredForeign result; - TestRequiredForeign result = new TestRequiredForeign(); + private TestRequiredForeign PrepareBuilder() { + if (builderIsReadOnly) { + TestRequiredForeign original = result; + result = new TestRequiredForeign(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRequiredForeign MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRequiredForeign(); + result = DefaultInstance ?? new TestRequiredForeign(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -8587,13 +9202,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRequiredForeign BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedMessage_.MakeReadOnly(); - TestRequiredForeign returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -8607,6 +9221,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestRequiredForeign other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestRequiredForeign.DefaultInstance) return this; + PrepareBuilder(); if (other.HasOptionalMessage) { MergeOptionalMessage(other.OptionalMessage); } @@ -8625,6 +9240,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -8694,18 +9310,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalMessage = true; result.optionalMessage_ = value; return this; } public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalMessage = true; result.optionalMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalMessage && result.optionalMessage_ != global::Google.ProtocolBuffers.TestProtos.TestRequired.DefaultInstance) { result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestRequired.CreateBuilder(result.optionalMessage_).MergeFrom(value).BuildPartial(); @@ -8716,13 +9335,14 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalMessage() { + PrepareBuilder(); result.hasOptionalMessage = false; result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestRequired.DefaultInstance; return this; } public pbc::IPopsicleList RepeatedMessageList { - get { return result.repeatedMessage_; } + get { return PrepareBuilder().repeatedMessage_; } } public int RepeatedMessageCount { get { return result.RepeatedMessageCount; } @@ -8732,29 +9352,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestRequired value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessage_[index] = value; return this; } public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestRequired.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessage_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessage_.Add(value); return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedMessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedMessage_); return this; } public Builder ClearRepeatedMessage() { + PrepareBuilder(); result.repeatedMessage_.Clear(); return this; } @@ -8767,11 +9393,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDummy(value); } } public Builder SetDummy(int value) { + PrepareBuilder(); result.hasDummy = true; result.dummy_ = value; return this; } public Builder ClearDummy() { + PrepareBuilder(); result.hasDummy = false; result.dummy_ = 0; return this; @@ -8884,7 +9512,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestForeignNested prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -8894,21 +9522,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestForeignNested(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestForeignNested cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestForeignNested result = new TestForeignNested(); + bool builderIsReadOnly; + TestForeignNested result; + + private TestForeignNested PrepareBuilder() { + if (builderIsReadOnly) { + TestForeignNested original = result; + result = new TestForeignNested(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestForeignNested MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestForeignNested(); + result = DefaultInstance ?? new TestForeignNested(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -8920,12 +9575,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestForeignNested BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestForeignNested returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -8939,6 +9593,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestForeignNested other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestForeignNested.DefaultInstance) return this; + PrepareBuilder(); if (other.HasForeignNested) { MergeForeignNested(other.ForeignNested); } @@ -8951,6 +9606,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9012,18 +9668,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetForeignNested(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasForeignNested = true; result.foreignNested_ = value; return this; } public Builder SetForeignNested(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasForeignNested = true; result.foreignNested_ = builderForValue.Build(); return this; } public Builder MergeForeignNested(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasForeignNested && result.foreignNested_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance) { result.foreignNested_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.CreateBuilder(result.foreignNested_).MergeFrom(value).BuildPartial(); @@ -9034,6 +9693,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearForeignNested() { + PrepareBuilder(); result.hasForeignNested = false; result.foreignNested_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.DefaultInstance; return this; @@ -9130,7 +9790,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestEmptyMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9140,21 +9800,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestEmptyMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestEmptyMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestEmptyMessage result; + + private TestEmptyMessage PrepareBuilder() { + if (builderIsReadOnly) { + TestEmptyMessage original = result; + result = new TestEmptyMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestEmptyMessage result = new TestEmptyMessage(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestEmptyMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestEmptyMessage(); + result = DefaultInstance ?? new TestEmptyMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -9166,12 +9853,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestEmptyMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestEmptyMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -9185,6 +9871,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestEmptyMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestEmptyMessage.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -9194,6 +9881,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9332,7 +10020,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestEmptyMessageWithExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9342,21 +10030,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestEmptyMessageWithExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestEmptyMessageWithExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestEmptyMessageWithExtensions result = new TestEmptyMessageWithExtensions(); + bool builderIsReadOnly; + TestEmptyMessageWithExtensions result; + + private TestEmptyMessageWithExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestEmptyMessageWithExtensions original = result; + result = new TestEmptyMessageWithExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestEmptyMessageWithExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestEmptyMessageWithExtensions(); + result = DefaultInstance ?? new TestEmptyMessageWithExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -9368,12 +10083,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestEmptyMessageWithExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestEmptyMessageWithExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -9387,6 +10101,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestEmptyMessageWithExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestEmptyMessageWithExtensions.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -9397,6 +10112,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9537,7 +10253,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMultipleExtensionRanges prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9547,21 +10263,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMultipleExtensionRanges(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMultipleExtensionRanges cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestMultipleExtensionRanges result; + + private TestMultipleExtensionRanges PrepareBuilder() { + if (builderIsReadOnly) { + TestMultipleExtensionRanges original = result; + result = new TestMultipleExtensionRanges(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestMultipleExtensionRanges result = new TestMultipleExtensionRanges(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMultipleExtensionRanges MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMultipleExtensionRanges(); + result = DefaultInstance ?? new TestMultipleExtensionRanges(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -9573,12 +10316,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMultipleExtensionRanges BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMultipleExtensionRanges returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -9592,6 +10334,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMultipleExtensionRanges other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMultipleExtensionRanges.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -9602,6 +10345,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9768,7 +10512,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestReallyLargeTagNumber prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -9778,21 +10522,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestReallyLargeTagNumber(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestReallyLargeTagNumber cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestReallyLargeTagNumber result; + + private TestReallyLargeTagNumber PrepareBuilder() { + if (builderIsReadOnly) { + TestReallyLargeTagNumber original = result; + result = new TestReallyLargeTagNumber(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestReallyLargeTagNumber result = new TestReallyLargeTagNumber(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestReallyLargeTagNumber MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestReallyLargeTagNumber(); + result = DefaultInstance ?? new TestReallyLargeTagNumber(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -9804,12 +10575,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestReallyLargeTagNumber BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestReallyLargeTagNumber returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -9823,6 +10593,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestReallyLargeTagNumber other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestReallyLargeTagNumber.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -9838,6 +10609,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -9897,11 +10669,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -9915,11 +10689,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetBb(value); } } public Builder SetBb(int value) { + PrepareBuilder(); result.hasBb = true; result.bb_ = value; return this; } public Builder ClearBb() { + PrepareBuilder(); result.hasBb = false; result.bb_ = 0; return this; @@ -10048,7 +10824,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRecursiveMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -10058,21 +10834,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRecursiveMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRecursiveMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestRecursiveMessage result = new TestRecursiveMessage(); + bool builderIsReadOnly; + TestRecursiveMessage result; + + private TestRecursiveMessage PrepareBuilder() { + if (builderIsReadOnly) { + TestRecursiveMessage original = result; + result = new TestRecursiveMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRecursiveMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRecursiveMessage(); + result = DefaultInstance ?? new TestRecursiveMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -10084,12 +10887,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRecursiveMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestRecursiveMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -10103,6 +10905,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestRecursiveMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { MergeA(other.A); } @@ -10118,6 +10921,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -10183,18 +10987,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetA(global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder SetA(global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasA = true; result.a_ = builderForValue.Build(); return this; } public Builder MergeA(global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasA && result.a_ != global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.DefaultInstance) { result.a_ = global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.CreateBuilder(result.a_).MergeFrom(value).BuildPartial(); @@ -10205,6 +11012,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = global::Google.ProtocolBuffers.TestProtos.TestRecursiveMessage.DefaultInstance; return this; @@ -10218,11 +11026,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetI(value); } } public Builder SetI(int value) { + PrepareBuilder(); result.hasI = true; result.i_ = value; return this; } public Builder ClearI() { + PrepareBuilder(); result.hasI = false; result.i_ = 0; return this; @@ -10335,7 +11145,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMutualRecursionA prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -10345,21 +11155,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMutualRecursionA(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMutualRecursionA cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestMutualRecursionA result; + + private TestMutualRecursionA PrepareBuilder() { + if (builderIsReadOnly) { + TestMutualRecursionA original = result; + result = new TestMutualRecursionA(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestMutualRecursionA result = new TestMutualRecursionA(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMutualRecursionA MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMutualRecursionA(); + result = DefaultInstance ?? new TestMutualRecursionA(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -10371,12 +11208,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMutualRecursionA BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMutualRecursionA returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -10390,6 +11226,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMutualRecursionA other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.DefaultInstance) return this; + PrepareBuilder(); if (other.HasBb) { MergeBb(other.Bb); } @@ -10402,6 +11239,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -10463,18 +11301,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetBb(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasBb = true; result.bb_ = value; return this; } public Builder SetBb(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasBb = true; result.bb_ = builderForValue.Build(); return this; } public Builder MergeBb(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasBb && result.bb_ != global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.DefaultInstance) { result.bb_ = global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.CreateBuilder(result.bb_).MergeFrom(value).BuildPartial(); @@ -10485,6 +11326,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearBb() { + PrepareBuilder(); result.hasBb = false; result.bb_ = global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.DefaultInstance; return this; @@ -10613,7 +11455,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestMutualRecursionB prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -10623,21 +11465,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestMutualRecursionB(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestMutualRecursionB cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestMutualRecursionB result = new TestMutualRecursionB(); + bool builderIsReadOnly; + TestMutualRecursionB result; + + private TestMutualRecursionB PrepareBuilder() { + if (builderIsReadOnly) { + TestMutualRecursionB original = result; + result = new TestMutualRecursionB(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestMutualRecursionB MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestMutualRecursionB(); + result = DefaultInstance ?? new TestMutualRecursionB(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -10649,12 +11518,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestMutualRecursionB BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestMutualRecursionB returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -10668,6 +11536,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestMutualRecursionB other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionB.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { MergeA(other.A); } @@ -10683,6 +11552,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -10748,18 +11618,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetA(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder SetA(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasA = true; result.a_ = builderForValue.Build(); return this; } public Builder MergeA(global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasA && result.a_ != global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.DefaultInstance) { result.a_ = global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.CreateBuilder(result.a_).MergeFrom(value).BuildPartial(); @@ -10770,6 +11643,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = global::Google.ProtocolBuffers.TestProtos.TestMutualRecursionA.DefaultInstance; return this; @@ -10783,11 +11657,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOptionalInt32(value); } } public Builder SetOptionalInt32(int value) { + PrepareBuilder(); result.hasOptionalInt32 = true; result.optionalInt32_ = value; return this; } public Builder ClearOptionalInt32() { + PrepareBuilder(); result.hasOptionalInt32 = false; result.optionalInt32_ = 0; return this; @@ -10932,7 +11808,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Foo prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -10942,21 +11818,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Foo(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Foo cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + Foo result; - Foo result = new Foo(); + private Foo PrepareBuilder() { + if (builderIsReadOnly) { + Foo original = result; + result = new Foo(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Foo MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Foo(); + result = DefaultInstance ?? new Foo(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -10968,12 +11871,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Foo BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - Foo returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -10987,6 +11889,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(Foo other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -10999,6 +11902,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -11054,11 +11958,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -11171,7 +12077,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(Bar prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -11181,21 +12087,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new Bar(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(Bar cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - Bar result = new Bar(); + bool builderIsReadOnly; + Bar result; + + private Bar PrepareBuilder() { + if (builderIsReadOnly) { + Bar original = result; + result = new Bar(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override Bar MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new Bar(); + result = DefaultInstance ?? new Bar(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -11207,12 +12140,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Bar BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - Bar returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -11226,6 +12158,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(Bar other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -11238,6 +12171,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -11293,11 +12227,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -11418,7 +12354,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestDupFieldNumber prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -11428,21 +12364,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestDupFieldNumber(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestDupFieldNumber cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestDupFieldNumber result = new TestDupFieldNumber(); + bool builderIsReadOnly; + TestDupFieldNumber result; + + private TestDupFieldNumber PrepareBuilder() { + if (builderIsReadOnly) { + TestDupFieldNumber original = result; + result = new TestDupFieldNumber(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestDupFieldNumber MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestDupFieldNumber(); + result = DefaultInstance ?? new TestDupFieldNumber(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -11454,12 +12417,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestDupFieldNumber BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestDupFieldNumber returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -11473,6 +12435,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestDupFieldNumber other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.DefaultInstance) return this; + PrepareBuilder(); if (other.HasA) { A = other.A; } @@ -11491,6 +12454,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -11564,11 +12528,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetA(value); } } public Builder SetA(int value) { + PrepareBuilder(); result.hasA = true; result.a_ = value; return this; } public Builder ClearA() { + PrepareBuilder(); result.hasA = false; result.a_ = 0; return this; @@ -11583,18 +12549,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetFoo(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasFoo = true; result.foo_ = value; return this; } public Builder SetFoo(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasFoo = true; result.foo_ = builderForValue.Build(); return this; } public Builder MergeFoo(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasFoo && result.foo_ != global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.DefaultInstance) { result.foo_ = global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.CreateBuilder(result.foo_).MergeFrom(value).BuildPartial(); @@ -11605,6 +12574,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearFoo() { + PrepareBuilder(); result.hasFoo = false; result.foo_ = global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Foo.DefaultInstance; return this; @@ -11619,18 +12589,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetBar(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasBar = true; result.bar_ = value; return this; } public Builder SetBar(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasBar = true; result.bar_ = builderForValue.Build(); return this; } public Builder MergeBar(global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasBar && result.bar_ != global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.DefaultInstance) { result.bar_ = global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.CreateBuilder(result.bar_).MergeFrom(value).BuildPartial(); @@ -11641,6 +12614,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearBar() { + PrepareBuilder(); result.hasBar = false; result.bar_ = global::Google.ProtocolBuffers.TestProtos.TestDupFieldNumber.Types.Bar.DefaultInstance; return this; @@ -11810,7 +12784,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(NestedMessage prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -11820,21 +12794,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(NestedMessage cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + NestedMessage result; + + private NestedMessage PrepareBuilder() { + if (builderIsReadOnly) { + NestedMessage original = result; + result = new NestedMessage(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - NestedMessage result = new NestedMessage(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override NestedMessage MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new NestedMessage(); + result = DefaultInstance ?? new NestedMessage(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -11846,14 +12847,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public override NestedMessage BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.nestedmessageRepeatedInt32_.MakeReadOnly(); result.nestedmessageRepeatedForeignmessage_.MakeReadOnly(); - NestedMessage returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -11867,6 +12867,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(NestedMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.DefaultInstance) return this; + PrepareBuilder(); if (other.nestedmessageRepeatedInt32_.Count != 0) { base.AddRange(other.nestedmessageRepeatedInt32_, result.nestedmessageRepeatedInt32_); } @@ -11882,6 +12883,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -11935,7 +12937,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList NestedmessageRepeatedInt32List { - get { return result.nestedmessageRepeatedInt32_; } + get { return PrepareBuilder().nestedmessageRepeatedInt32_; } } public int NestedmessageRepeatedInt32Count { get { return result.NestedmessageRepeatedInt32Count; } @@ -11944,24 +12946,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetNestedmessageRepeatedInt32(index); } public Builder SetNestedmessageRepeatedInt32(int index, int value) { + PrepareBuilder(); result.nestedmessageRepeatedInt32_[index] = value; return this; } public Builder AddNestedmessageRepeatedInt32(int value) { + PrepareBuilder(); result.nestedmessageRepeatedInt32_.Add(value); return this; } public Builder AddRangeNestedmessageRepeatedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.nestedmessageRepeatedInt32_); return this; } public Builder ClearNestedmessageRepeatedInt32() { + PrepareBuilder(); result.nestedmessageRepeatedInt32_.Clear(); return this; } public pbc::IPopsicleList NestedmessageRepeatedForeignmessageList { - get { return result.nestedmessageRepeatedForeignmessage_; } + get { return PrepareBuilder().nestedmessageRepeatedForeignmessage_; } } public int NestedmessageRepeatedForeignmessageCount { get { return result.NestedmessageRepeatedForeignmessageCount; } @@ -11971,29 +12977,35 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetNestedmessageRepeatedForeignmessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_[index] = value; return this; } public Builder SetNestedmessageRepeatedForeignmessage(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_[index] = builderForValue.Build(); return this; } public Builder AddNestedmessageRepeatedForeignmessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_.Add(value); return this; } public Builder AddNestedmessageRepeatedForeignmessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeNestedmessageRepeatedForeignmessage(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.nestedmessageRepeatedForeignmessage_); return this; } public Builder ClearNestedmessageRepeatedForeignmessage() { + PrepareBuilder(); result.nestedmessageRepeatedForeignmessage_.Clear(); return this; } @@ -12081,7 +13093,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestNestedMessageHasBits prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -12091,21 +13103,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestNestedMessageHasBits(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestNestedMessageHasBits cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestNestedMessageHasBits result = new TestNestedMessageHasBits(); + bool builderIsReadOnly; + TestNestedMessageHasBits result; + + private TestNestedMessageHasBits PrepareBuilder() { + if (builderIsReadOnly) { + TestNestedMessageHasBits original = result; + result = new TestNestedMessageHasBits(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestNestedMessageHasBits MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestNestedMessageHasBits(); + result = DefaultInstance ?? new TestNestedMessageHasBits(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -12117,12 +13156,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestNestedMessageHasBits BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestNestedMessageHasBits returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -12136,6 +13174,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestNestedMessageHasBits other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.DefaultInstance) return this; + PrepareBuilder(); if (other.HasOptionalNestedMessage) { MergeOptionalNestedMessage(other.OptionalNestedMessage); } @@ -12148,6 +13187,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -12209,18 +13249,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = value; return this; } public Builder SetOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasOptionalNestedMessage = true; result.optionalNestedMessage_ = builderForValue.Build(); return this; } public Builder MergeOptionalNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasOptionalNestedMessage && result.optionalNestedMessage_ != global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.DefaultInstance) { result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.CreateBuilder(result.optionalNestedMessage_).MergeFrom(value).BuildPartial(); @@ -12231,6 +13274,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearOptionalNestedMessage() { + PrepareBuilder(); result.hasOptionalNestedMessage = false; result.optionalNestedMessage_ = global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.DefaultInstance; return this; @@ -12558,7 +13602,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestCamelCaseFieldNames prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -12568,21 +13612,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestCamelCaseFieldNames(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestCamelCaseFieldNames cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestCamelCaseFieldNames result; + + private TestCamelCaseFieldNames PrepareBuilder() { + if (builderIsReadOnly) { + TestCamelCaseFieldNames original = result; + result = new TestCamelCaseFieldNames(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestCamelCaseFieldNames result = new TestCamelCaseFieldNames(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestCamelCaseFieldNames MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestCamelCaseFieldNames(); + result = DefaultInstance ?? new TestCamelCaseFieldNames(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -12594,8 +13665,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestCamelCaseFieldNames BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedPrimitiveField_.MakeReadOnly(); result.repeatedStringField_.MakeReadOnly(); @@ -12603,9 +13674,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.repeatedMessageField_.MakeReadOnly(); result.repeatedStringPieceField_.MakeReadOnly(); result.repeatedCordField_.MakeReadOnly(); - TestCamelCaseFieldNames returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -12619,6 +13689,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestCamelCaseFieldNames other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestCamelCaseFieldNames.DefaultInstance) return this; + PrepareBuilder(); if (other.HasPrimitiveField) { PrimitiveField = other.PrimitiveField; } @@ -12664,6 +13735,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -12787,11 +13859,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetPrimitiveField(value); } } public Builder SetPrimitiveField(int value) { + PrepareBuilder(); result.hasPrimitiveField = true; result.primitiveField_ = value; return this; } public Builder ClearPrimitiveField() { + PrepareBuilder(); result.hasPrimitiveField = false; result.primitiveField_ = 0; return this; @@ -12806,11 +13880,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetStringField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasStringField = true; result.stringField_ = value; return this; } public Builder ClearStringField() { + PrepareBuilder(); result.hasStringField = false; result.stringField_ = ""; return this; @@ -12824,11 +13900,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetEnumField(value); } } public Builder SetEnumField(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.hasEnumField = true; result.enumField_ = value; return this; } public Builder ClearEnumField() { + PrepareBuilder(); result.hasEnumField = false; result.enumField_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnum.FOREIGN_FOO; return this; @@ -12843,18 +13921,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMessageField = true; result.messageField_ = value; return this; } public Builder SetMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasMessageField = true; result.messageField_ = builderForValue.Build(); return this; } public Builder MergeMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasMessageField && result.messageField_ != global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) { result.messageField_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.CreateBuilder(result.messageField_).MergeFrom(value).BuildPartial(); @@ -12865,6 +13946,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearMessageField() { + PrepareBuilder(); result.hasMessageField = false; result.messageField_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance; return this; @@ -12879,11 +13961,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetStringPieceField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasStringPieceField = true; result.stringPieceField_ = value; return this; } public Builder ClearStringPieceField() { + PrepareBuilder(); result.hasStringPieceField = false; result.stringPieceField_ = ""; return this; @@ -12898,18 +13982,20 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetCordField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasCordField = true; result.cordField_ = value; return this; } public Builder ClearCordField() { + PrepareBuilder(); result.hasCordField = false; result.cordField_ = ""; return this; } public pbc::IPopsicleList RepeatedPrimitiveFieldList { - get { return result.repeatedPrimitiveField_; } + get { return PrepareBuilder().repeatedPrimitiveField_; } } public int RepeatedPrimitiveFieldCount { get { return result.RepeatedPrimitiveFieldCount; } @@ -12918,24 +14004,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedPrimitiveField(index); } public Builder SetRepeatedPrimitiveField(int index, int value) { + PrepareBuilder(); result.repeatedPrimitiveField_[index] = value; return this; } public Builder AddRepeatedPrimitiveField(int value) { + PrepareBuilder(); result.repeatedPrimitiveField_.Add(value); return this; } public Builder AddRangeRepeatedPrimitiveField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedPrimitiveField_); return this; } public Builder ClearRepeatedPrimitiveField() { + PrepareBuilder(); result.repeatedPrimitiveField_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringFieldList { - get { return result.repeatedStringField_; } + get { return PrepareBuilder().repeatedStringField_; } } public int RepeatedStringFieldCount { get { return result.RepeatedStringFieldCount; } @@ -12945,25 +14035,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedStringField(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringField_[index] = value; return this; } public Builder AddRepeatedStringField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringField_.Add(value); return this; } public Builder AddRangeRepeatedStringField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedStringField_); return this; } public Builder ClearRepeatedStringField() { + PrepareBuilder(); result.repeatedStringField_.Clear(); return this; } public pbc::IPopsicleList RepeatedEnumFieldList { - get { return result.repeatedEnumField_; } + get { return PrepareBuilder().repeatedEnumField_; } } public int RepeatedEnumFieldCount { get { return result.RepeatedEnumFieldCount; } @@ -12972,24 +14066,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedEnumField(index); } public Builder SetRepeatedEnumField(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.repeatedEnumField_[index] = value; return this; } public Builder AddRepeatedEnumField(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.repeatedEnumField_.Add(value); return this; } public Builder AddRangeRepeatedEnumField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedEnumField_); return this; } public Builder ClearRepeatedEnumField() { + PrepareBuilder(); result.repeatedEnumField_.Clear(); return this; } public pbc::IPopsicleList RepeatedMessageFieldList { - get { return result.repeatedMessageField_; } + get { return PrepareBuilder().repeatedMessageField_; } } public int RepeatedMessageFieldCount { get { return result.RepeatedMessageFieldCount; } @@ -12999,35 +14097,41 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedMessageField(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessageField_[index] = value; return this; } public Builder SetRepeatedMessageField(int index, global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessageField_[index] = builderForValue.Build(); return this; } public Builder AddRepeatedMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedMessageField_.Add(value); return this; } public Builder AddRepeatedMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.repeatedMessageField_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedMessageField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedMessageField_); return this; } public Builder ClearRepeatedMessageField() { + PrepareBuilder(); result.repeatedMessageField_.Clear(); return this; } public pbc::IPopsicleList RepeatedStringPieceFieldList { - get { return result.repeatedStringPieceField_; } + get { return PrepareBuilder().repeatedStringPieceField_; } } public int RepeatedStringPieceFieldCount { get { return result.RepeatedStringPieceFieldCount; } @@ -13037,25 +14141,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedStringPieceField(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPieceField_[index] = value; return this; } public Builder AddRepeatedStringPieceField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedStringPieceField_.Add(value); return this; } public Builder AddRangeRepeatedStringPieceField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedStringPieceField_); return this; } public Builder ClearRepeatedStringPieceField() { + PrepareBuilder(); result.repeatedStringPieceField_.Clear(); return this; } public pbc::IPopsicleList RepeatedCordFieldList { - get { return result.repeatedCordField_; } + get { return PrepareBuilder().repeatedCordField_; } } public int RepeatedCordFieldCount { get { return result.RepeatedCordFieldCount; } @@ -13065,19 +14173,23 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedCordField(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCordField_[index] = value; return this; } public Builder AddRepeatedCordField(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedCordField_.Add(value); return this; } public Builder AddRangeRepeatedCordField(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedCordField_); return this; } public Builder ClearRepeatedCordField() { + PrepareBuilder(); result.repeatedCordField_.Clear(); return this; } @@ -13226,7 +14338,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestFieldOrderings prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -13236,21 +14348,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestFieldOrderings(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestFieldOrderings cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestFieldOrderings result; + + private TestFieldOrderings PrepareBuilder() { + if (builderIsReadOnly) { + TestFieldOrderings original = result; + result = new TestFieldOrderings(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestFieldOrderings result = new TestFieldOrderings(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestFieldOrderings MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestFieldOrderings(); + result = DefaultInstance ?? new TestFieldOrderings(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -13262,12 +14401,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestFieldOrderings BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestFieldOrderings returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -13281,6 +14419,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestFieldOrderings other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestFieldOrderings.DefaultInstance) return this; + PrepareBuilder(); if (other.HasMyString) { MyString = other.MyString; } @@ -13300,6 +14439,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -13364,11 +14504,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMyString(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMyString = true; result.myString_ = value; return this; } public Builder ClearMyString() { + PrepareBuilder(); result.hasMyString = false; result.myString_ = ""; return this; @@ -13382,11 +14524,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetMyInt(value); } } public Builder SetMyInt(long value) { + PrepareBuilder(); result.hasMyInt = true; result.myInt_ = value; return this; } public Builder ClearMyInt() { + PrepareBuilder(); result.hasMyInt = false; result.myInt_ = 0L; return this; @@ -13400,11 +14544,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetMyFloat(value); } } public Builder SetMyFloat(float value) { + PrepareBuilder(); result.hasMyFloat = true; result.myFloat_ = value; return this; } public Builder ClearMyFloat() { + PrepareBuilder(); result.hasMyFloat = false; result.myFloat_ = 0F; return this; @@ -13807,7 +14953,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestExtremeDefaultValues prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -13817,21 +14963,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestExtremeDefaultValues(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestExtremeDefaultValues cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestExtremeDefaultValues result; - TestExtremeDefaultValues result = new TestExtremeDefaultValues(); + private TestExtremeDefaultValues PrepareBuilder() { + if (builderIsReadOnly) { + TestExtremeDefaultValues original = result; + result = new TestExtremeDefaultValues(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestExtremeDefaultValues MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestExtremeDefaultValues(); + result = DefaultInstance ?? new TestExtremeDefaultValues(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -13843,12 +15016,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestExtremeDefaultValues BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestExtremeDefaultValues returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -13862,6 +15034,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestExtremeDefaultValues other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestExtremeDefaultValues.DefaultInstance) return this; + PrepareBuilder(); if (other.HasEscapedBytes) { EscapedBytes = other.EscapedBytes; } @@ -13928,6 +15101,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -14056,11 +15230,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetEscapedBytes(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasEscapedBytes = true; result.escapedBytes_ = value; return this; } public Builder ClearEscapedBytes() { + PrepareBuilder(); result.hasEscapedBytes = false; result.escapedBytes_ = (pb::ByteString) global::Google.ProtocolBuffers.TestProtos.TestExtremeDefaultValues.Descriptor.Fields[0].DefaultValue; return this; @@ -14076,11 +15252,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetLargeUint32(uint value) { + PrepareBuilder(); result.hasLargeUint32 = true; result.largeUint32_ = value; return this; } public Builder ClearLargeUint32() { + PrepareBuilder(); result.hasLargeUint32 = false; result.largeUint32_ = 4294967295; return this; @@ -14096,11 +15274,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetLargeUint64(ulong value) { + PrepareBuilder(); result.hasLargeUint64 = true; result.largeUint64_ = value; return this; } public Builder ClearLargeUint64() { + PrepareBuilder(); result.hasLargeUint64 = false; result.largeUint64_ = 18446744073709551615UL; return this; @@ -14114,11 +15294,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetSmallInt32(value); } } public Builder SetSmallInt32(int value) { + PrepareBuilder(); result.hasSmallInt32 = true; result.smallInt32_ = value; return this; } public Builder ClearSmallInt32() { + PrepareBuilder(); result.hasSmallInt32 = false; result.smallInt32_ = -2147483647; return this; @@ -14132,11 +15314,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetSmallInt64(value); } } public Builder SetSmallInt64(long value) { + PrepareBuilder(); result.hasSmallInt64 = true; result.smallInt64_ = value; return this; } public Builder ClearSmallInt64() { + PrepareBuilder(); result.hasSmallInt64 = false; result.smallInt64_ = -9223372036854775807L; return this; @@ -14151,11 +15335,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetUtf8String(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasUtf8String = true; result.utf8String_ = value; return this; } public Builder ClearUtf8String() { + PrepareBuilder(); result.hasUtf8String = false; result.utf8String_ = (string) global::Google.ProtocolBuffers.TestProtos.TestExtremeDefaultValues.Descriptor.Fields[5].DefaultValue; return this; @@ -14169,11 +15355,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetZeroFloat(value); } } public Builder SetZeroFloat(float value) { + PrepareBuilder(); result.hasZeroFloat = true; result.zeroFloat_ = value; return this; } public Builder ClearZeroFloat() { + PrepareBuilder(); result.hasZeroFloat = false; result.zeroFloat_ = 0F; return this; @@ -14187,11 +15375,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetOneFloat(value); } } public Builder SetOneFloat(float value) { + PrepareBuilder(); result.hasOneFloat = true; result.oneFloat_ = value; return this; } public Builder ClearOneFloat() { + PrepareBuilder(); result.hasOneFloat = false; result.oneFloat_ = 1F; return this; @@ -14205,11 +15395,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetSmallFloat(value); } } public Builder SetSmallFloat(float value) { + PrepareBuilder(); result.hasSmallFloat = true; result.smallFloat_ = value; return this; } public Builder ClearSmallFloat() { + PrepareBuilder(); result.hasSmallFloat = false; result.smallFloat_ = 1.5F; return this; @@ -14223,11 +15415,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNegativeOneFloat(value); } } public Builder SetNegativeOneFloat(float value) { + PrepareBuilder(); result.hasNegativeOneFloat = true; result.negativeOneFloat_ = value; return this; } public Builder ClearNegativeOneFloat() { + PrepareBuilder(); result.hasNegativeOneFloat = false; result.negativeOneFloat_ = -1F; return this; @@ -14241,11 +15435,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNegativeFloat(value); } } public Builder SetNegativeFloat(float value) { + PrepareBuilder(); result.hasNegativeFloat = true; result.negativeFloat_ = value; return this; } public Builder ClearNegativeFloat() { + PrepareBuilder(); result.hasNegativeFloat = false; result.negativeFloat_ = -1.5F; return this; @@ -14259,11 +15455,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetLargeFloat(value); } } public Builder SetLargeFloat(float value) { + PrepareBuilder(); result.hasLargeFloat = true; result.largeFloat_ = value; return this; } public Builder ClearLargeFloat() { + PrepareBuilder(); result.hasLargeFloat = false; result.largeFloat_ = 2E+08F; return this; @@ -14277,11 +15475,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetSmallNegativeFloat(value); } } public Builder SetSmallNegativeFloat(float value) { + PrepareBuilder(); result.hasSmallNegativeFloat = true; result.smallNegativeFloat_ = value; return this; } public Builder ClearSmallNegativeFloat() { + PrepareBuilder(); result.hasSmallNegativeFloat = false; result.smallNegativeFloat_ = -8E-28F; return this; @@ -14295,11 +15495,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetInfDouble(value); } } public Builder SetInfDouble(double value) { + PrepareBuilder(); result.hasInfDouble = true; result.infDouble_ = value; return this; } public Builder ClearInfDouble() { + PrepareBuilder(); result.hasInfDouble = false; result.infDouble_ = double.PositiveInfinity; return this; @@ -14313,11 +15515,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNegInfDouble(value); } } public Builder SetNegInfDouble(double value) { + PrepareBuilder(); result.hasNegInfDouble = true; result.negInfDouble_ = value; return this; } public Builder ClearNegInfDouble() { + PrepareBuilder(); result.hasNegInfDouble = false; result.negInfDouble_ = double.NegativeInfinity; return this; @@ -14331,11 +15535,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNanDouble(value); } } public Builder SetNanDouble(double value) { + PrepareBuilder(); result.hasNanDouble = true; result.nanDouble_ = value; return this; } public Builder ClearNanDouble() { + PrepareBuilder(); result.hasNanDouble = false; result.nanDouble_ = double.NaN; return this; @@ -14349,11 +15555,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetInfFloat(value); } } public Builder SetInfFloat(float value) { + PrepareBuilder(); result.hasInfFloat = true; result.infFloat_ = value; return this; } public Builder ClearInfFloat() { + PrepareBuilder(); result.hasInfFloat = false; result.infFloat_ = float.PositiveInfinity; return this; @@ -14367,11 +15575,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNegInfFloat(value); } } public Builder SetNegInfFloat(float value) { + PrepareBuilder(); result.hasNegInfFloat = true; result.negInfFloat_ = value; return this; } public Builder ClearNegInfFloat() { + PrepareBuilder(); result.hasNegInfFloat = false; result.negInfFloat_ = float.NegativeInfinity; return this; @@ -14385,11 +15595,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetNanFloat(value); } } public Builder SetNanFloat(float value) { + PrepareBuilder(); result.hasNanFloat = true; result.nanFloat_ = value; return this; } public Builder ClearNanFloat() { + PrepareBuilder(); result.hasNanFloat = false; result.nanFloat_ = float.NaN; return this; @@ -14502,7 +15714,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OneString prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -14512,21 +15724,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OneString(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OneString cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - OneString result = new OneString(); + bool builderIsReadOnly; + OneString result; + + private OneString PrepareBuilder() { + if (builderIsReadOnly) { + OneString original = result; + result = new OneString(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OneString MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OneString(); + result = DefaultInstance ?? new OneString(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -14538,12 +15777,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OneString BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OneString returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -14557,6 +15795,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OneString other) { if (other == global::Google.ProtocolBuffers.TestProtos.OneString.DefaultInstance) return this; + PrepareBuilder(); if (other.HasData) { Data = other.Data; } @@ -14569,6 +15808,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -14625,11 +15865,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetData(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasData = true; result.data_ = value; return this; } public Builder ClearData() { + PrepareBuilder(); result.hasData = false; result.data_ = ""; return this; @@ -14742,7 +15984,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(OneBytes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -14752,21 +15994,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new OneBytes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(OneBytes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - OneBytes result = new OneBytes(); + bool builderIsReadOnly; + OneBytes result; + + private OneBytes PrepareBuilder() { + if (builderIsReadOnly) { + OneBytes original = result; + result = new OneBytes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override OneBytes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new OneBytes(); + result = DefaultInstance ?? new OneBytes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -14778,12 +16047,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override OneBytes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - OneBytes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -14797,6 +16065,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(OneBytes other) { if (other == global::Google.ProtocolBuffers.TestProtos.OneBytes.DefaultInstance) return this; + PrepareBuilder(); if (other.HasData) { Data = other.Data; } @@ -14809,6 +16078,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -14865,11 +16135,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetData(pb::ByteString value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasData = true; result.data_ = value; return this; } public Builder ClearData() { + PrepareBuilder(); result.hasData = false; result.data_ = pb::ByteString.Empty; return this; @@ -15339,7 +16611,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestPackedTypes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -15349,21 +16621,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestPackedTypes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestPackedTypes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestPackedTypes result = new TestPackedTypes(); + bool builderIsReadOnly; + TestPackedTypes result; + + private TestPackedTypes PrepareBuilder() { + if (builderIsReadOnly) { + TestPackedTypes original = result; + result = new TestPackedTypes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestPackedTypes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestPackedTypes(); + result = DefaultInstance ?? new TestPackedTypes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -15375,8 +16674,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestPackedTypes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.packedInt32_.MakeReadOnly(); result.packedInt64_.MakeReadOnly(); @@ -15392,9 +16691,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.packedDouble_.MakeReadOnly(); result.packedBool_.MakeReadOnly(); result.packedEnum_.MakeReadOnly(); - TestPackedTypes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -15408,6 +16706,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestPackedTypes other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestPackedTypes.DefaultInstance) return this; + PrepareBuilder(); if (other.packedInt32_.Count != 0) { base.AddRange(other.packedInt32_, result.packedInt32_); } @@ -15459,6 +16758,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -15582,7 +16882,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList PackedInt32List { - get { return result.packedInt32_; } + get { return PrepareBuilder().packedInt32_; } } public int PackedInt32Count { get { return result.PackedInt32Count; } @@ -15591,24 +16891,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedInt32(index); } public Builder SetPackedInt32(int index, int value) { + PrepareBuilder(); result.packedInt32_[index] = value; return this; } public Builder AddPackedInt32(int value) { + PrepareBuilder(); result.packedInt32_.Add(value); return this; } public Builder AddRangePackedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedInt32_); return this; } public Builder ClearPackedInt32() { + PrepareBuilder(); result.packedInt32_.Clear(); return this; } public pbc::IPopsicleList PackedInt64List { - get { return result.packedInt64_; } + get { return PrepareBuilder().packedInt64_; } } public int PackedInt64Count { get { return result.PackedInt64Count; } @@ -15617,25 +16921,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedInt64(index); } public Builder SetPackedInt64(int index, long value) { + PrepareBuilder(); result.packedInt64_[index] = value; return this; } public Builder AddPackedInt64(long value) { + PrepareBuilder(); result.packedInt64_.Add(value); return this; } public Builder AddRangePackedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedInt64_); return this; } public Builder ClearPackedInt64() { + PrepareBuilder(); result.packedInt64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedUint32List { - get { return result.packedUint32_; } + get { return PrepareBuilder().packedUint32_; } } public int PackedUint32Count { get { return result.PackedUint32Count; } @@ -15646,27 +16954,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedUint32(int index, uint value) { + PrepareBuilder(); result.packedUint32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedUint32(uint value) { + PrepareBuilder(); result.packedUint32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedUint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedUint32_); return this; } public Builder ClearPackedUint32() { + PrepareBuilder(); result.packedUint32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedUint64List { - get { return result.packedUint64_; } + get { return PrepareBuilder().packedUint64_; } } public int PackedUint64Count { get { return result.PackedUint64Count; } @@ -15677,26 +16989,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedUint64(int index, ulong value) { + PrepareBuilder(); result.packedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedUint64(ulong value) { + PrepareBuilder(); result.packedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedUint64_); return this; } public Builder ClearPackedUint64() { + PrepareBuilder(); result.packedUint64_.Clear(); return this; } public pbc::IPopsicleList PackedSint32List { - get { return result.packedSint32_; } + get { return PrepareBuilder().packedSint32_; } } public int PackedSint32Count { get { return result.PackedSint32Count; } @@ -15705,24 +17021,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSint32(index); } public Builder SetPackedSint32(int index, int value) { + PrepareBuilder(); result.packedSint32_[index] = value; return this; } public Builder AddPackedSint32(int value) { + PrepareBuilder(); result.packedSint32_.Add(value); return this; } public Builder AddRangePackedSint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSint32_); return this; } public Builder ClearPackedSint32() { + PrepareBuilder(); result.packedSint32_.Clear(); return this; } public pbc::IPopsicleList PackedSint64List { - get { return result.packedSint64_; } + get { return PrepareBuilder().packedSint64_; } } public int PackedSint64Count { get { return result.PackedSint64Count; } @@ -15731,25 +17051,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSint64(index); } public Builder SetPackedSint64(int index, long value) { + PrepareBuilder(); result.packedSint64_[index] = value; return this; } public Builder AddPackedSint64(long value) { + PrepareBuilder(); result.packedSint64_.Add(value); return this; } public Builder AddRangePackedSint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSint64_); return this; } public Builder ClearPackedSint64() { + PrepareBuilder(); result.packedSint64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedFixed32List { - get { return result.packedFixed32_; } + get { return PrepareBuilder().packedFixed32_; } } public int PackedFixed32Count { get { return result.PackedFixed32Count; } @@ -15760,27 +17084,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedFixed32(int index, uint value) { + PrepareBuilder(); result.packedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedFixed32(uint value) { + PrepareBuilder(); result.packedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedFixed32_); return this; } public Builder ClearPackedFixed32() { + PrepareBuilder(); result.packedFixed32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList PackedFixed64List { - get { return result.packedFixed64_; } + get { return PrepareBuilder().packedFixed64_; } } public int PackedFixed64Count { get { return result.PackedFixed64Count; } @@ -15791,26 +17119,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetPackedFixed64(int index, ulong value) { + PrepareBuilder(); result.packedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddPackedFixed64(ulong value) { + PrepareBuilder(); result.packedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangePackedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedFixed64_); return this; } public Builder ClearPackedFixed64() { + PrepareBuilder(); result.packedFixed64_.Clear(); return this; } public pbc::IPopsicleList PackedSfixed32List { - get { return result.packedSfixed32_; } + get { return PrepareBuilder().packedSfixed32_; } } public int PackedSfixed32Count { get { return result.PackedSfixed32Count; } @@ -15819,24 +17151,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSfixed32(index); } public Builder SetPackedSfixed32(int index, int value) { + PrepareBuilder(); result.packedSfixed32_[index] = value; return this; } public Builder AddPackedSfixed32(int value) { + PrepareBuilder(); result.packedSfixed32_.Add(value); return this; } public Builder AddRangePackedSfixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSfixed32_); return this; } public Builder ClearPackedSfixed32() { + PrepareBuilder(); result.packedSfixed32_.Clear(); return this; } public pbc::IPopsicleList PackedSfixed64List { - get { return result.packedSfixed64_; } + get { return PrepareBuilder().packedSfixed64_; } } public int PackedSfixed64Count { get { return result.PackedSfixed64Count; } @@ -15845,24 +17181,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedSfixed64(index); } public Builder SetPackedSfixed64(int index, long value) { + PrepareBuilder(); result.packedSfixed64_[index] = value; return this; } public Builder AddPackedSfixed64(long value) { + PrepareBuilder(); result.packedSfixed64_.Add(value); return this; } public Builder AddRangePackedSfixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedSfixed64_); return this; } public Builder ClearPackedSfixed64() { + PrepareBuilder(); result.packedSfixed64_.Clear(); return this; } public pbc::IPopsicleList PackedFloatList { - get { return result.packedFloat_; } + get { return PrepareBuilder().packedFloat_; } } public int PackedFloatCount { get { return result.PackedFloatCount; } @@ -15871,24 +17211,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedFloat(index); } public Builder SetPackedFloat(int index, float value) { + PrepareBuilder(); result.packedFloat_[index] = value; return this; } public Builder AddPackedFloat(float value) { + PrepareBuilder(); result.packedFloat_.Add(value); return this; } public Builder AddRangePackedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedFloat_); return this; } public Builder ClearPackedFloat() { + PrepareBuilder(); result.packedFloat_.Clear(); return this; } public pbc::IPopsicleList PackedDoubleList { - get { return result.packedDouble_; } + get { return PrepareBuilder().packedDouble_; } } public int PackedDoubleCount { get { return result.PackedDoubleCount; } @@ -15897,24 +17241,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedDouble(index); } public Builder SetPackedDouble(int index, double value) { + PrepareBuilder(); result.packedDouble_[index] = value; return this; } public Builder AddPackedDouble(double value) { + PrepareBuilder(); result.packedDouble_.Add(value); return this; } public Builder AddRangePackedDouble(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedDouble_); return this; } public Builder ClearPackedDouble() { + PrepareBuilder(); result.packedDouble_.Clear(); return this; } public pbc::IPopsicleList PackedBoolList { - get { return result.packedBool_; } + get { return PrepareBuilder().packedBool_; } } public int PackedBoolCount { get { return result.PackedBoolCount; } @@ -15923,24 +17271,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedBool(index); } public Builder SetPackedBool(int index, bool value) { + PrepareBuilder(); result.packedBool_[index] = value; return this; } public Builder AddPackedBool(bool value) { + PrepareBuilder(); result.packedBool_.Add(value); return this; } public Builder AddRangePackedBool(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedBool_); return this; } public Builder ClearPackedBool() { + PrepareBuilder(); result.packedBool_.Clear(); return this; } public pbc::IPopsicleList PackedEnumList { - get { return result.packedEnum_; } + get { return PrepareBuilder().packedEnum_; } } public int PackedEnumCount { get { return result.PackedEnumCount; } @@ -15949,18 +17301,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedEnum(index); } public Builder SetPackedEnum(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.packedEnum_[index] = value; return this; } public Builder AddPackedEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.packedEnum_.Add(value); return this; } public Builder AddRangePackedEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedEnum_); return this; } public Builder ClearPackedEnum() { + PrepareBuilder(); result.packedEnum_.Clear(); return this; } @@ -16374,7 +17730,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestUnpackedTypes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -16384,21 +17740,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestUnpackedTypes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestUnpackedTypes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestUnpackedTypes result; + + private TestUnpackedTypes PrepareBuilder() { + if (builderIsReadOnly) { + TestUnpackedTypes original = result; + result = new TestUnpackedTypes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestUnpackedTypes result = new TestUnpackedTypes(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestUnpackedTypes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestUnpackedTypes(); + result = DefaultInstance ?? new TestUnpackedTypes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -16410,8 +17793,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestUnpackedTypes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.unpackedInt32_.MakeReadOnly(); result.unpackedInt64_.MakeReadOnly(); @@ -16427,9 +17810,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.unpackedDouble_.MakeReadOnly(); result.unpackedBool_.MakeReadOnly(); result.unpackedEnum_.MakeReadOnly(); - TestUnpackedTypes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -16443,6 +17825,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestUnpackedTypes other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestUnpackedTypes.DefaultInstance) return this; + PrepareBuilder(); if (other.unpackedInt32_.Count != 0) { base.AddRange(other.unpackedInt32_, result.unpackedInt32_); } @@ -16494,6 +17877,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -16617,7 +18001,7 @@ namespace Google.ProtocolBuffers.TestProtos { public pbc::IPopsicleList UnpackedInt32List { - get { return result.unpackedInt32_; } + get { return PrepareBuilder().unpackedInt32_; } } public int UnpackedInt32Count { get { return result.UnpackedInt32Count; } @@ -16626,24 +18010,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedInt32(index); } public Builder SetUnpackedInt32(int index, int value) { + PrepareBuilder(); result.unpackedInt32_[index] = value; return this; } public Builder AddUnpackedInt32(int value) { + PrepareBuilder(); result.unpackedInt32_.Add(value); return this; } public Builder AddRangeUnpackedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedInt32_); return this; } public Builder ClearUnpackedInt32() { + PrepareBuilder(); result.unpackedInt32_.Clear(); return this; } public pbc::IPopsicleList UnpackedInt64List { - get { return result.unpackedInt64_; } + get { return PrepareBuilder().unpackedInt64_; } } public int UnpackedInt64Count { get { return result.UnpackedInt64Count; } @@ -16652,25 +18040,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedInt64(index); } public Builder SetUnpackedInt64(int index, long value) { + PrepareBuilder(); result.unpackedInt64_[index] = value; return this; } public Builder AddUnpackedInt64(long value) { + PrepareBuilder(); result.unpackedInt64_.Add(value); return this; } public Builder AddRangeUnpackedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedInt64_); return this; } public Builder ClearUnpackedInt64() { + PrepareBuilder(); result.unpackedInt64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedUint32List { - get { return result.unpackedUint32_; } + get { return PrepareBuilder().unpackedUint32_; } } public int UnpackedUint32Count { get { return result.UnpackedUint32Count; } @@ -16681,27 +18073,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedUint32(int index, uint value) { + PrepareBuilder(); result.unpackedUint32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedUint32(uint value) { + PrepareBuilder(); result.unpackedUint32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedUint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedUint32_); return this; } public Builder ClearUnpackedUint32() { + PrepareBuilder(); result.unpackedUint32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedUint64List { - get { return result.unpackedUint64_; } + get { return PrepareBuilder().unpackedUint64_; } } public int UnpackedUint64Count { get { return result.UnpackedUint64Count; } @@ -16712,26 +18108,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedUint64(int index, ulong value) { + PrepareBuilder(); result.unpackedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedUint64(ulong value) { + PrepareBuilder(); result.unpackedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedUint64_); return this; } public Builder ClearUnpackedUint64() { + PrepareBuilder(); result.unpackedUint64_.Clear(); return this; } public pbc::IPopsicleList UnpackedSint32List { - get { return result.unpackedSint32_; } + get { return PrepareBuilder().unpackedSint32_; } } public int UnpackedSint32Count { get { return result.UnpackedSint32Count; } @@ -16740,24 +18140,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSint32(index); } public Builder SetUnpackedSint32(int index, int value) { + PrepareBuilder(); result.unpackedSint32_[index] = value; return this; } public Builder AddUnpackedSint32(int value) { + PrepareBuilder(); result.unpackedSint32_.Add(value); return this; } public Builder AddRangeUnpackedSint32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSint32_); return this; } public Builder ClearUnpackedSint32() { + PrepareBuilder(); result.unpackedSint32_.Clear(); return this; } public pbc::IPopsicleList UnpackedSint64List { - get { return result.unpackedSint64_; } + get { return PrepareBuilder().unpackedSint64_; } } public int UnpackedSint64Count { get { return result.UnpackedSint64Count; } @@ -16766,25 +18170,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSint64(index); } public Builder SetUnpackedSint64(int index, long value) { + PrepareBuilder(); result.unpackedSint64_[index] = value; return this; } public Builder AddUnpackedSint64(long value) { + PrepareBuilder(); result.unpackedSint64_.Add(value); return this; } public Builder AddRangeUnpackedSint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSint64_); return this; } public Builder ClearUnpackedSint64() { + PrepareBuilder(); result.unpackedSint64_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedFixed32List { - get { return result.unpackedFixed32_; } + get { return PrepareBuilder().unpackedFixed32_; } } public int UnpackedFixed32Count { get { return result.UnpackedFixed32Count; } @@ -16795,27 +18203,31 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedFixed32(int index, uint value) { + PrepareBuilder(); result.unpackedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedFixed32(uint value) { + PrepareBuilder(); result.unpackedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedFixed32_); return this; } public Builder ClearUnpackedFixed32() { + PrepareBuilder(); result.unpackedFixed32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList UnpackedFixed64List { - get { return result.unpackedFixed64_; } + get { return PrepareBuilder().unpackedFixed64_; } } public int UnpackedFixed64Count { get { return result.UnpackedFixed64Count; } @@ -16826,26 +18238,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetUnpackedFixed64(int index, ulong value) { + PrepareBuilder(); result.unpackedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddUnpackedFixed64(ulong value) { + PrepareBuilder(); result.unpackedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeUnpackedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedFixed64_); return this; } public Builder ClearUnpackedFixed64() { + PrepareBuilder(); result.unpackedFixed64_.Clear(); return this; } public pbc::IPopsicleList UnpackedSfixed32List { - get { return result.unpackedSfixed32_; } + get { return PrepareBuilder().unpackedSfixed32_; } } public int UnpackedSfixed32Count { get { return result.UnpackedSfixed32Count; } @@ -16854,24 +18270,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSfixed32(index); } public Builder SetUnpackedSfixed32(int index, int value) { + PrepareBuilder(); result.unpackedSfixed32_[index] = value; return this; } public Builder AddUnpackedSfixed32(int value) { + PrepareBuilder(); result.unpackedSfixed32_.Add(value); return this; } public Builder AddRangeUnpackedSfixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSfixed32_); return this; } public Builder ClearUnpackedSfixed32() { + PrepareBuilder(); result.unpackedSfixed32_.Clear(); return this; } public pbc::IPopsicleList UnpackedSfixed64List { - get { return result.unpackedSfixed64_; } + get { return PrepareBuilder().unpackedSfixed64_; } } public int UnpackedSfixed64Count { get { return result.UnpackedSfixed64Count; } @@ -16880,24 +18300,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedSfixed64(index); } public Builder SetUnpackedSfixed64(int index, long value) { + PrepareBuilder(); result.unpackedSfixed64_[index] = value; return this; } public Builder AddUnpackedSfixed64(long value) { + PrepareBuilder(); result.unpackedSfixed64_.Add(value); return this; } public Builder AddRangeUnpackedSfixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedSfixed64_); return this; } public Builder ClearUnpackedSfixed64() { + PrepareBuilder(); result.unpackedSfixed64_.Clear(); return this; } public pbc::IPopsicleList UnpackedFloatList { - get { return result.unpackedFloat_; } + get { return PrepareBuilder().unpackedFloat_; } } public int UnpackedFloatCount { get { return result.UnpackedFloatCount; } @@ -16906,24 +18330,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedFloat(index); } public Builder SetUnpackedFloat(int index, float value) { + PrepareBuilder(); result.unpackedFloat_[index] = value; return this; } public Builder AddUnpackedFloat(float value) { + PrepareBuilder(); result.unpackedFloat_.Add(value); return this; } public Builder AddRangeUnpackedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedFloat_); return this; } public Builder ClearUnpackedFloat() { + PrepareBuilder(); result.unpackedFloat_.Clear(); return this; } public pbc::IPopsicleList UnpackedDoubleList { - get { return result.unpackedDouble_; } + get { return PrepareBuilder().unpackedDouble_; } } public int UnpackedDoubleCount { get { return result.UnpackedDoubleCount; } @@ -16932,24 +18360,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedDouble(index); } public Builder SetUnpackedDouble(int index, double value) { + PrepareBuilder(); result.unpackedDouble_[index] = value; return this; } public Builder AddUnpackedDouble(double value) { + PrepareBuilder(); result.unpackedDouble_.Add(value); return this; } public Builder AddRangeUnpackedDouble(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedDouble_); return this; } public Builder ClearUnpackedDouble() { + PrepareBuilder(); result.unpackedDouble_.Clear(); return this; } public pbc::IPopsicleList UnpackedBoolList { - get { return result.unpackedBool_; } + get { return PrepareBuilder().unpackedBool_; } } public int UnpackedBoolCount { get { return result.UnpackedBoolCount; } @@ -16958,24 +18390,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedBool(index); } public Builder SetUnpackedBool(int index, bool value) { + PrepareBuilder(); result.unpackedBool_[index] = value; return this; } public Builder AddUnpackedBool(bool value) { + PrepareBuilder(); result.unpackedBool_.Add(value); return this; } public Builder AddRangeUnpackedBool(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedBool_); return this; } public Builder ClearUnpackedBool() { + PrepareBuilder(); result.unpackedBool_.Clear(); return this; } public pbc::IPopsicleList UnpackedEnumList { - get { return result.unpackedEnum_; } + get { return PrepareBuilder().unpackedEnum_; } } public int UnpackedEnumCount { get { return result.UnpackedEnumCount; } @@ -16984,18 +18420,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetUnpackedEnum(index); } public Builder SetUnpackedEnum(int index, global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.unpackedEnum_[index] = value; return this; } public Builder AddUnpackedEnum(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.unpackedEnum_.Add(value); return this; } public Builder AddRangeUnpackedEnum(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.unpackedEnum_); return this; } public Builder ClearUnpackedEnum() { + PrepareBuilder(); result.unpackedEnum_.Clear(); return this; } @@ -17095,7 +18535,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestPackedExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -17105,21 +18545,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestPackedExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestPackedExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestPackedExtensions result; + + private TestPackedExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestPackedExtensions original = result; + result = new TestPackedExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestPackedExtensions result = new TestPackedExtensions(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestPackedExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestPackedExtensions(); + result = DefaultInstance ?? new TestPackedExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -17131,12 +18598,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestPackedExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestPackedExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -17150,6 +18616,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestPackedExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestPackedExtensions.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -17160,6 +18627,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -17298,7 +18766,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestUnpackedExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -17308,21 +18776,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestUnpackedExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestUnpackedExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestUnpackedExtensions result; + + private TestUnpackedExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestUnpackedExtensions original = result; + result = new TestUnpackedExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestUnpackedExtensions result = new TestUnpackedExtensions(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestUnpackedExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestUnpackedExtensions(); + result = DefaultInstance ?? new TestUnpackedExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -17334,12 +18829,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestUnpackedExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - TestUnpackedExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -17353,6 +18847,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestUnpackedExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensions.DefaultInstance) return this; + PrepareBuilder(); this.MergeExtensionFields(other); this.MergeUnknownFields(other.UnknownFields); return this; @@ -17363,6 +18858,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -17553,7 +19049,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(DynamicMessageType prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -17563,21 +19059,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new DynamicMessageType(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(DynamicMessageType cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + DynamicMessageType result; - DynamicMessageType result = new DynamicMessageType(); + private DynamicMessageType PrepareBuilder() { + if (builderIsReadOnly) { + DynamicMessageType original = result; + result = new DynamicMessageType(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override DynamicMessageType MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new DynamicMessageType(); + result = DefaultInstance ?? new DynamicMessageType(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -17589,12 +19112,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override DynamicMessageType BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - DynamicMessageType returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -17608,6 +19130,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(DynamicMessageType other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.DefaultInstance) return this; + PrepareBuilder(); if (other.HasDynamicField) { DynamicField = other.DynamicField; } @@ -17620,6 +19143,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -17675,11 +19199,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDynamicField(value); } } public Builder SetDynamicField(int value) { + PrepareBuilder(); result.hasDynamicField = true; result.dynamicField_ = value; return this; } public Builder ClearDynamicField() { + PrepareBuilder(); result.hasDynamicField = false; result.dynamicField_ = 0; return this; @@ -17883,7 +19409,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestDynamicExtensions prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -17893,21 +19419,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestDynamicExtensions(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestDynamicExtensions cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - TestDynamicExtensions result = new TestDynamicExtensions(); + bool builderIsReadOnly; + TestDynamicExtensions result; + + private TestDynamicExtensions PrepareBuilder() { + if (builderIsReadOnly) { + TestDynamicExtensions original = result; + result = new TestDynamicExtensions(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestDynamicExtensions MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestDynamicExtensions(); + result = DefaultInstance ?? new TestDynamicExtensions(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -17919,14 +19472,13 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestDynamicExtensions BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedExtension_.MakeReadOnly(); result.packedExtension_.MakeReadOnly(); - TestDynamicExtensions returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -17940,6 +19492,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestDynamicExtensions other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.DefaultInstance) return this; + PrepareBuilder(); if (other.HasScalarExtension) { ScalarExtension = other.ScalarExtension; } @@ -17970,6 +19523,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -18078,11 +19632,13 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetScalarExtension(uint value) { + PrepareBuilder(); result.hasScalarExtension = true; result.scalarExtension_ = value; return this; } public Builder ClearScalarExtension() { + PrepareBuilder(); result.hasScalarExtension = false; result.scalarExtension_ = 0; return this; @@ -18096,11 +19652,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetEnumExtension(value); } } public Builder SetEnumExtension(global::Google.ProtocolBuffers.TestProtos.ForeignEnum value) { + PrepareBuilder(); result.hasEnumExtension = true; result.enumExtension_ = value; return this; } public Builder ClearEnumExtension() { + PrepareBuilder(); result.hasEnumExtension = false; result.enumExtension_ = global::Google.ProtocolBuffers.TestProtos.ForeignEnum.FOREIGN_FOO; return this; @@ -18114,11 +19672,13 @@ namespace Google.ProtocolBuffers.TestProtos { set { SetDynamicEnumExtension(value); } } public Builder SetDynamicEnumExtension(global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicEnumType value) { + PrepareBuilder(); result.hasDynamicEnumExtension = true; result.dynamicEnumExtension_ = value; return this; } public Builder ClearDynamicEnumExtension() { + PrepareBuilder(); result.hasDynamicEnumExtension = false; result.dynamicEnumExtension_ = global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicEnumType.DYNAMIC_FOO; return this; @@ -18133,18 +19693,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetMessageExtension(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasMessageExtension = true; result.messageExtension_ = value; return this; } public Builder SetMessageExtension(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasMessageExtension = true; result.messageExtension_ = builderForValue.Build(); return this; } public Builder MergeMessageExtension(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasMessageExtension && result.messageExtension_ != global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) { result.messageExtension_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.CreateBuilder(result.messageExtension_).MergeFrom(value).BuildPartial(); @@ -18155,6 +19718,7 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearMessageExtension() { + PrepareBuilder(); result.hasMessageExtension = false; result.messageExtension_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance; return this; @@ -18169,18 +19733,21 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetDynamicMessageExtension(global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.hasDynamicMessageExtension = true; result.dynamicMessageExtension_ = value; return this; } public Builder SetDynamicMessageExtension(global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.Builder builderForValue) { pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); + PrepareBuilder(); result.hasDynamicMessageExtension = true; result.dynamicMessageExtension_ = builderForValue.Build(); return this; } public Builder MergeDynamicMessageExtension(global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); if (result.hasDynamicMessageExtension && result.dynamicMessageExtension_ != global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.DefaultInstance) { result.dynamicMessageExtension_ = global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.CreateBuilder(result.dynamicMessageExtension_).MergeFrom(value).BuildPartial(); @@ -18191,13 +19758,14 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder ClearDynamicMessageExtension() { + PrepareBuilder(); result.hasDynamicMessageExtension = false; result.dynamicMessageExtension_ = global::Google.ProtocolBuffers.TestProtos.TestDynamicExtensions.Types.DynamicMessageType.DefaultInstance; return this; } public pbc::IPopsicleList RepeatedExtensionList { - get { return result.repeatedExtension_; } + get { return PrepareBuilder().repeatedExtension_; } } public int RepeatedExtensionCount { get { return result.RepeatedExtensionCount; } @@ -18207,25 +19775,29 @@ namespace Google.ProtocolBuffers.TestProtos { } public Builder SetRepeatedExtension(int index, string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedExtension_[index] = value; return this; } public Builder AddRepeatedExtension(string value) { pb::ThrowHelper.ThrowIfNull(value, "value"); + PrepareBuilder(); result.repeatedExtension_.Add(value); return this; } public Builder AddRangeRepeatedExtension(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedExtension_); return this; } public Builder ClearRepeatedExtension() { + PrepareBuilder(); result.repeatedExtension_.Clear(); return this; } public pbc::IPopsicleList PackedExtensionList { - get { return result.packedExtension_; } + get { return PrepareBuilder().packedExtension_; } } public int PackedExtensionCount { get { return result.PackedExtensionCount; } @@ -18234,18 +19806,22 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetPackedExtension(index); } public Builder SetPackedExtension(int index, int value) { + PrepareBuilder(); result.packedExtension_[index] = value; return this; } public Builder AddPackedExtension(int value) { + PrepareBuilder(); result.packedExtension_.Add(value); return this; } public Builder AddRangePackedExtension(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.packedExtension_); return this; } public Builder ClearPackedExtension() { + PrepareBuilder(); result.packedExtension_.Clear(); return this; } @@ -18479,7 +20055,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(TestRepeatedScalarDifferentTagSizes prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -18489,21 +20065,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new TestRepeatedScalarDifferentTagSizes(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(TestRepeatedScalarDifferentTagSizes cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + TestRepeatedScalarDifferentTagSizes result; + + private TestRepeatedScalarDifferentTagSizes PrepareBuilder() { + if (builderIsReadOnly) { + TestRepeatedScalarDifferentTagSizes original = result; + result = new TestRepeatedScalarDifferentTagSizes(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - TestRepeatedScalarDifferentTagSizes result = new TestRepeatedScalarDifferentTagSizes(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override TestRepeatedScalarDifferentTagSizes MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new TestRepeatedScalarDifferentTagSizes(); + result = DefaultInstance ?? new TestRepeatedScalarDifferentTagSizes(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -18515,8 +20118,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override TestRepeatedScalarDifferentTagSizes BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } result.repeatedFixed32_.MakeReadOnly(); result.repeatedInt32_.MakeReadOnly(); @@ -18524,9 +20127,8 @@ namespace Google.ProtocolBuffers.TestProtos { result.repeatedInt64_.MakeReadOnly(); result.repeatedFloat_.MakeReadOnly(); result.repeatedUint64_.MakeReadOnly(); - TestRepeatedScalarDifferentTagSizes returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -18540,6 +20142,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(TestRepeatedScalarDifferentTagSizes other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestRepeatedScalarDifferentTagSizes.DefaultInstance) return this; + PrepareBuilder(); if (other.repeatedFixed32_.Count != 0) { base.AddRange(other.repeatedFixed32_, result.repeatedFixed32_); } @@ -18567,6 +20170,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -18642,7 +20246,7 @@ namespace Google.ProtocolBuffers.TestProtos { [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed32List { - get { return result.repeatedFixed32_; } + get { return PrepareBuilder().repeatedFixed32_; } } public int RepeatedFixed32Count { get { return result.RepeatedFixed32Count; } @@ -18653,26 +20257,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed32(int index, uint value) { + PrepareBuilder(); result.repeatedFixed32_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed32(uint value) { + PrepareBuilder(); result.repeatedFixed32_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed32_); return this; } public Builder ClearRepeatedFixed32() { + PrepareBuilder(); result.repeatedFixed32_.Clear(); return this; } public pbc::IPopsicleList RepeatedInt32List { - get { return result.repeatedInt32_; } + get { return PrepareBuilder().repeatedInt32_; } } public int RepeatedInt32Count { get { return result.RepeatedInt32Count; } @@ -18681,25 +20289,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt32(index); } public Builder SetRepeatedInt32(int index, int value) { + PrepareBuilder(); result.repeatedInt32_[index] = value; return this; } public Builder AddRepeatedInt32(int value) { + PrepareBuilder(); result.repeatedInt32_.Add(value); return this; } public Builder AddRangeRepeatedInt32(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt32_); return this; } public Builder ClearRepeatedInt32() { + PrepareBuilder(); result.repeatedInt32_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedFixed64List { - get { return result.repeatedFixed64_; } + get { return PrepareBuilder().repeatedFixed64_; } } public int RepeatedFixed64Count { get { return result.RepeatedFixed64Count; } @@ -18710,26 +20322,30 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedFixed64(int index, ulong value) { + PrepareBuilder(); result.repeatedFixed64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedFixed64(ulong value) { + PrepareBuilder(); result.repeatedFixed64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedFixed64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFixed64_); return this; } public Builder ClearRepeatedFixed64() { + PrepareBuilder(); result.repeatedFixed64_.Clear(); return this; } public pbc::IPopsicleList RepeatedInt64List { - get { return result.repeatedInt64_; } + get { return PrepareBuilder().repeatedInt64_; } } public int RepeatedInt64Count { get { return result.RepeatedInt64Count; } @@ -18738,24 +20354,28 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedInt64(index); } public Builder SetRepeatedInt64(int index, long value) { + PrepareBuilder(); result.repeatedInt64_[index] = value; return this; } public Builder AddRepeatedInt64(long value) { + PrepareBuilder(); result.repeatedInt64_.Add(value); return this; } public Builder AddRangeRepeatedInt64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedInt64_); return this; } public Builder ClearRepeatedInt64() { + PrepareBuilder(); result.repeatedInt64_.Clear(); return this; } public pbc::IPopsicleList RepeatedFloatList { - get { return result.repeatedFloat_; } + get { return PrepareBuilder().repeatedFloat_; } } public int RepeatedFloatCount { get { return result.RepeatedFloatCount; } @@ -18764,25 +20384,29 @@ namespace Google.ProtocolBuffers.TestProtos { return result.GetRepeatedFloat(index); } public Builder SetRepeatedFloat(int index, float value) { + PrepareBuilder(); result.repeatedFloat_[index] = value; return this; } public Builder AddRepeatedFloat(float value) { + PrepareBuilder(); result.repeatedFloat_.Add(value); return this; } public Builder AddRangeRepeatedFloat(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedFloat_); return this; } public Builder ClearRepeatedFloat() { + PrepareBuilder(); result.repeatedFloat_.Clear(); return this; } [global::System.CLSCompliant(false)] public pbc::IPopsicleList RepeatedUint64List { - get { return result.repeatedUint64_; } + get { return PrepareBuilder().repeatedUint64_; } } public int RepeatedUint64Count { get { return result.RepeatedUint64Count; } @@ -18793,20 +20417,24 @@ namespace Google.ProtocolBuffers.TestProtos { } [global::System.CLSCompliant(false)] public Builder SetRepeatedUint64(int index, ulong value) { + PrepareBuilder(); result.repeatedUint64_[index] = value; return this; } [global::System.CLSCompliant(false)] public Builder AddRepeatedUint64(ulong value) { + PrepareBuilder(); result.repeatedUint64_.Add(value); return this; } [global::System.CLSCompliant(false)] public Builder AddRangeRepeatedUint64(scg::IEnumerable values) { + PrepareBuilder(); base.AddRange(values, result.repeatedUint64_); return this; } public Builder ClearRepeatedUint64() { + PrepareBuilder(); result.repeatedUint64_.Clear(); return this; } @@ -18902,7 +20530,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(FooRequest prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -18912,21 +20540,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new FooRequest(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(FooRequest cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - FooRequest result = new FooRequest(); + bool builderIsReadOnly; + FooRequest result; + + private FooRequest PrepareBuilder() { + if (builderIsReadOnly) { + FooRequest original = result; + result = new FooRequest(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override FooRequest MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new FooRequest(); + result = DefaultInstance ?? new FooRequest(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -18938,12 +20593,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override FooRequest BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - FooRequest returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -18957,6 +20611,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(FooRequest other) { if (other == global::Google.ProtocolBuffers.TestProtos.FooRequest.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -18966,6 +20621,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -19100,7 +20756,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(FooResponse prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -19110,21 +20766,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new FooResponse(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(FooResponse cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + FooResponse result; + + private FooResponse PrepareBuilder() { + if (builderIsReadOnly) { + FooResponse original = result; + result = new FooResponse(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - FooResponse result = new FooResponse(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override FooResponse MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new FooResponse(); + result = DefaultInstance ?? new FooResponse(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -19136,12 +20819,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override FooResponse BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - FooResponse returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -19155,6 +20837,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(FooResponse other) { if (other == global::Google.ProtocolBuffers.TestProtos.FooResponse.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -19164,6 +20847,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -19298,7 +20982,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(BarRequest prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -19308,21 +20992,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new BarRequest(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(BarRequest cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } + + bool builderIsReadOnly; + BarRequest result; + + private BarRequest PrepareBuilder() { + if (builderIsReadOnly) { + BarRequest original = result; + result = new BarRequest(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } - BarRequest result = new BarRequest(); + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override BarRequest MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new BarRequest(); + result = DefaultInstance ?? new BarRequest(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -19334,12 +21045,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override BarRequest BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - BarRequest returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -19353,6 +21063,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(BarRequest other) { if (other == global::Google.ProtocolBuffers.TestProtos.BarRequest.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -19362,6 +21073,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; @@ -19496,7 +21208,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder CreateBuilderForType() { return new Builder(); } public static Builder CreateBuilder(BarResponse prototype) { - return (Builder) new Builder().MergeFrom(prototype); + return new Builder(prototype); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -19506,21 +21218,48 @@ namespace Google.ProtocolBuffers.TestProtos { protected override Builder ThisBuilder { get { return this; } } - public Builder() {} + public Builder() { + result = DefaultInstance ?? new BarResponse(); + builderIsReadOnly = result == DefaultInstance; + } + internal Builder(BarResponse cloneFrom) { + result = cloneFrom; + builderIsReadOnly = true; + } - BarResponse result = new BarResponse(); + bool builderIsReadOnly; + BarResponse result; + + private BarResponse PrepareBuilder() { + if (builderIsReadOnly) { + BarResponse original = result; + result = new BarResponse(); + builderIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } protected override BarResponse MessageBeingBuilt { - get { return result; } + get { return PrepareBuilder(); } } public override Builder Clear() { - result = new BarResponse(); + result = DefaultInstance ?? new BarResponse(); + builderIsReadOnly = true; return this; } public override Builder Clone() { - return new Builder().MergeFrom(result); + if (builderIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } } public override pbd::MessageDescriptor DescriptorForType { @@ -19532,12 +21271,11 @@ namespace Google.ProtocolBuffers.TestProtos { } public override BarResponse BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); + if (builderIsReadOnly) { + return result; } - BarResponse returnMe = result; - result = null; - return returnMe; + builderIsReadOnly = true; + return result; } public override Builder MergeFrom(pb::IMessage other) { @@ -19551,6 +21289,7 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(BarResponse other) { if (other == global::Google.ProtocolBuffers.TestProtos.BarResponse.DefaultInstance) return this; + PrepareBuilder(); this.MergeUnknownFields(other.UnknownFields); return this; } @@ -19560,6 +21299,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); pb::UnknownFieldSet.Builder unknownFields = null; uint tag; string field_name; From 7b6044f88865ae035f75acf742748df74181483d Mon Sep 17 00:00:00 2001 From: csharptest Date: Fri, 9 Sep 2011 21:40:13 -0500 Subject: [PATCH 2/4] one more test, we are done. --- .../ReusableBuilderTest.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ProtocolBuffers.Test/ReusableBuilderTest.cs b/src/ProtocolBuffers.Test/ReusableBuilderTest.cs index 4184971f08..9a5e3f3699 100644 --- a/src/ProtocolBuffers.Test/ReusableBuilderTest.cs +++ b/src/ProtocolBuffers.Test/ReusableBuilderTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text; using NUnit.Framework; using Google.ProtocolBuffers.TestProtos; +using Google.ProtocolBuffers.Serialization; namespace Google.ProtocolBuffers { @@ -50,6 +51,26 @@ namespace Google.ProtocolBuffers TestAllTypes.CreateBuilder().SetOptionalBool(true).Build().ToBuilder().Clear().Build())); } + [Test] + public void BuildModifyAndRebuild() + { + TestAllTypes.Builder b1 = new TestAllTypes.Builder(); + b1.SetDefaultInt32(1); + b1.AddRepeatedInt32(2); + b1.SetOptionalForeignMessage(ForeignMessage.DefaultInstance); + + TestAllTypes m1 = b1.Build(); + + b1.SetDefaultInt32(5); + b1.AddRepeatedInt32(6); + b1.SetOptionalForeignMessage(b1.OptionalForeignMessage.ToBuilder().SetC(7)); + + TestAllTypes m2 = b1.Build(); + + Assert.AreEqual("{\"optional_foreign_message\":{},\"repeated_int32\":[2],\"default_int32\":1}", m1.ToJson()); + Assert.AreEqual("{\"optional_foreign_message\":{\"c\":7},\"repeated_int32\":[2,6],\"default_int32\":5}", m2.ToJson()); + } + [Test] public void CloneOnChangePrimitive() { From 2a1f0bd44078abb6271091657cde9a1d7dba99e0 Mon Sep 17 00:00:00 2001 From: csharptest Date: Thu, 15 Sep 2011 18:16:15 -0500 Subject: [PATCH 3/4] Added a few more tests to ensure XxxxList { get; } clones readonly builder --- src/ProtocolBuffers.Test/ReusableBuilderTest.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ProtocolBuffers.Test/ReusableBuilderTest.cs b/src/ProtocolBuffers.Test/ReusableBuilderTest.cs index 9a5e3f3699..2f81a8144f 100644 --- a/src/ProtocolBuffers.Test/ReusableBuilderTest.cs +++ b/src/ProtocolBuffers.Test/ReusableBuilderTest.cs @@ -89,6 +89,15 @@ namespace Google.ProtocolBuffers Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); } + [Test] + public void CloneOnGetRepeatedBoolList() + { + TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); + Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + GC.KeepAlive(builder.RepeatedBoolList); + Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); + } + [Test] public void CloneOnChangeMessage() { @@ -108,11 +117,11 @@ namespace Google.ProtocolBuffers } [Test] - public void CloneOnAddRepeatedForeignMessage() + public void CloneOnGetRepeatedForeignMessageList() { TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); - builder.AddRepeatedForeignMessage(ForeignMessage.DefaultInstance); + GC.KeepAlive(builder.RepeatedForeignMessageList); Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); } @@ -126,11 +135,11 @@ namespace Google.ProtocolBuffers } [Test] - public void CloneOnAddRepeatedForeignEnum() + public void CloneOnGetRepeatedForeignEnumList() { TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder(); Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); - builder.AddRepeatedForeignEnum(ForeignEnum.FOREIGN_BAR); + GC.KeepAlive(builder.RepeatedForeignEnumList); Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build())); } From 3b625064e8e40f37ec510cc4f25035a9c1554c73 Mon Sep 17 00:00:00 2001 From: csharptest Date: Fri, 23 Sep 2011 10:14:14 -0500 Subject: [PATCH 4/4] One more test to ensure DefaultInstance is read-only --- src/ProtocolBuffers.Test/ReusableBuilderTest.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ProtocolBuffers.Test/ReusableBuilderTest.cs b/src/ProtocolBuffers.Test/ReusableBuilderTest.cs index 2f81a8144f..194313cba3 100644 --- a/src/ProtocolBuffers.Test/ReusableBuilderTest.cs +++ b/src/ProtocolBuffers.Test/ReusableBuilderTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using Google.ProtocolBuffers.Collections; using NUnit.Framework; using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.Serialization; @@ -10,6 +11,15 @@ namespace Google.ProtocolBuffers [TestFixture] public class ReusableBuilderTest { + [Test] + public void TestModifyDefaultInstance() + { + //verify that the default instance has correctly been marked as read-only + Assert.AreEqual(typeof(PopsicleList), TestAllTypes.DefaultInstance.RepeatedBoolList.GetType()); + PopsicleList list = (PopsicleList)TestAllTypes.DefaultInstance.RepeatedBoolList; + Assert.IsTrue(list.IsReadOnly); + } + [Test] public void TestUnmodifiedDefaultInstance() {