Commit 8c2b8d11 authored by csharptest's avatar csharptest Committed by rogerk

merged issue-22

parents 7f20cc90 3b625064
This diff is collapsed.
...@@ -72,12 +72,14 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -72,12 +72,14 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("}"); writer.WriteLine("}");
AddPublicMemberAttributes(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = value;", Name); writer.WriteLine(" result.{0}_ = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = false;", PropertyName); writer.WriteLine(" result.has{0} = false;", PropertyName);
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue); writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
......
...@@ -73,6 +73,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -73,6 +73,7 @@ namespace Google.ProtocolBuffers.ProtoGen
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = value;", Name); writer.WriteLine(" result.{0}_ = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
...@@ -80,6 +81,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -80,6 +81,7 @@ namespace Google.ProtocolBuffers.ProtoGen
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}({1}.Builder builderForValue) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}({1}.Builder builderForValue) {{", PropertyName, TypeName);
AddNullCheck(writer, "builderForValue"); AddNullCheck(writer, "builderForValue");
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = builderForValue.Build();", Name); writer.WriteLine(" result.{0}_ = builderForValue.Build();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
...@@ -87,6 +89,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -87,6 +89,7 @@ namespace Google.ProtocolBuffers.ProtoGen
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Merge{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Merge{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" if (result.has{0} &&", PropertyName); writer.WriteLine(" if (result.has{0} &&", PropertyName);
writer.WriteLine(" result.{0}_ != {1}) {{", Name, DefaultValue); writer.WriteLine(" result.{0}_ != {1}) {{", Name, DefaultValue);
writer.WriteLine(" result.{0}_ = {1}.CreateBuilder(result.{0}_).MergeFrom(value).BuildPartial();", Name, writer.WriteLine(" result.{0}_ = {1}.CreateBuilder(result.{0}_).MergeFrom(value).BuildPartial();", Name,
...@@ -99,6 +102,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -99,6 +102,7 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = false;", PropertyName); writer.WriteLine(" result.has{0} = false;", PropertyName);
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue); writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
......
...@@ -556,7 +556,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -556,7 +556,7 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("public override Builder ToBuilder() { return CreateBuilder(this); }"); writer.WriteLine("public override Builder ToBuilder() { return CreateBuilder(this); }");
writer.WriteLine("public override Builder CreateBuilderForType() { return new Builder(); }"); writer.WriteLine("public override Builder CreateBuilderForType() { return new Builder(); }");
writer.WriteLine("public static Builder CreateBuilder({0} prototype) {{", ClassName); 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(); writer.WriteLine();
if (Descriptor.File.CSharpOptions.AddSerializable) if (Descriptor.File.CSharpOptions.AddSerializable)
...@@ -591,21 +591,52 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -591,21 +591,52 @@ namespace Google.ProtocolBuffers.ProtoGen
private void GenerateCommonBuilderMethods(TextGenerator writer) 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();
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();
writer.WriteLine("protected override {0} MessageBeingBuilt {{", ClassName); writer.WriteLine("protected override {0} MessageBeingBuilt {{", ClassName);
writer.WriteLine(" get { return result; }"); writer.WriteLine(" get { return PrepareBuilder(); }");
writer.WriteLine("}"); writer.WriteLine("}");
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("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(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
writer.WriteLine("public override Builder Clone() {"); 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("}");
writer.WriteLine(); writer.WriteLine();
if (!UseLiteRuntime) if (!UseLiteRuntime)
...@@ -622,17 +653,15 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -622,17 +653,15 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("public override {0} BuildPartial() {{", ClassName); writer.WriteLine("public override {0} BuildPartial() {{", ClassName);
writer.Indent(); writer.Indent();
writer.WriteLine("if (result == null) {"); writer.WriteLine("if (builderIsReadOnly) {");
writer.WriteLine( writer.WriteLine(" return result;");
" throw new global::System.InvalidOperationException(\"build() has already been called on this Builder\");");
writer.WriteLine("}"); writer.WriteLine("}");
foreach (FieldDescriptor field in Descriptor.Fields) foreach (FieldDescriptor field in Descriptor.Fields)
{ {
CreateFieldGenerator(field).GenerateBuildingCode(writer); CreateFieldGenerator(field).GenerateBuildingCode(writer);
} }
writer.WriteLine("{0} returnMe = result;", ClassName); writer.WriteLine("builderIsReadOnly = true;");
writer.WriteLine("result = null;"); writer.WriteLine("return result;");
writer.WriteLine("return returnMe;");
writer.Outdent(); writer.Outdent();
writer.WriteLine("}"); writer.WriteLine("}");
writer.WriteLine(); writer.WriteLine();
...@@ -653,6 +682,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -653,6 +682,7 @@ namespace Google.ProtocolBuffers.ProtoGen
// fields are set so we can skip the merge. // fields are set so we can skip the merge.
writer.Indent(); writer.Indent();
writer.WriteLine("if (other == {0}.DefaultInstance) return this;", FullClassName); writer.WriteLine("if (other == {0}.DefaultInstance) return this;", FullClassName);
writer.WriteLine("PrepareBuilder();");
foreach (FieldDescriptor field in Descriptor.Fields) foreach (FieldDescriptor field in Descriptor.Fields)
{ {
CreateFieldGenerator(field).GenerateMergingCode(writer); CreateFieldGenerator(field).GenerateMergingCode(writer);
...@@ -685,6 +715,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -685,6 +715,7 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine( writer.WriteLine(
"public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {"); "public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {");
writer.Indent(); writer.Indent();
writer.WriteLine("PrepareBuilder();");
if (!UseLiteRuntime) if (!UseLiteRuntime)
{ {
writer.WriteLine("pb::UnknownFieldSet.Builder unknownFields = null;"); writer.WriteLine("pb::UnknownFieldSet.Builder unknownFields = null;");
......
...@@ -74,12 +74,14 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -74,12 +74,14 @@ namespace Google.ProtocolBuffers.ProtoGen
AddPublicMemberAttributes(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = true;", PropertyName); writer.WriteLine(" result.has{0} = true;", PropertyName);
writer.WriteLine(" result.{0}_ = value;", Name); writer.WriteLine(" result.{0}_ = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.has{0} = false;", PropertyName); writer.WriteLine(" result.has{0} = false;", PropertyName);
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue); writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
......
...@@ -75,7 +75,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -75,7 +75,7 @@ namespace Google.ProtocolBuffers.ProtoGen
// We return it via IPopsicleList so that collection initializers work more pleasantly. // We return it via IPopsicleList so that collection initializers work more pleasantly.
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName); 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("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine("public int {0}Count {{", PropertyName);
...@@ -87,21 +87,25 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -87,21 +87,25 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_[index] = value;", Name); writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName); writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName); writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(values);", Name); writer.WriteLine(" result.{0}_.Add(values);", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Clear();", Name); writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
......
...@@ -71,7 +71,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -71,7 +71,7 @@ namespace Google.ProtocolBuffers.ProtoGen
// We return it via IPopsicleList so that collection initializers work more pleasantly. // We return it via IPopsicleList so that collection initializers work more pleasantly.
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName); 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("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine("public int {0}Count {{", PropertyName);
...@@ -84,6 +84,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -84,6 +84,7 @@ namespace Google.ProtocolBuffers.ProtoGen
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_[index] = value;", Name); writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -91,12 +92,14 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -91,12 +92,14 @@ namespace Google.ProtocolBuffers.ProtoGen
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Set{0}(int index, {1}.Builder builderForValue) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}(int index, {1}.Builder builderForValue) {{", PropertyName, TypeName);
AddNullCheck(writer, "builderForValue"); AddNullCheck(writer, "builderForValue");
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_[index] = builderForValue.Build();", Name); writer.WriteLine(" result.{0}_[index] = builderForValue.Build();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName); writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
...@@ -104,16 +107,19 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -104,16 +107,19 @@ namespace Google.ProtocolBuffers.ProtoGen
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Add{0}({1}.Builder builderForValue) {{", PropertyName, TypeName); writer.WriteLine("public Builder Add{0}({1}.Builder builderForValue) {{", PropertyName, TypeName);
AddNullCheck(writer, "builderForValue"); AddNullCheck(writer, "builderForValue");
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(builderForValue.Build());", Name); writer.WriteLine(" result.{0}_.Add(builderForValue.Build());", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName); writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(values);", Name); writer.WriteLine(" result.{0}_.Add(values);", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Clear();", Name); writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
......
...@@ -75,7 +75,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -75,7 +75,7 @@ namespace Google.ProtocolBuffers.ProtoGen
// We return it via IPopsicleList so that collection initializers work more pleasantly. // We return it via IPopsicleList so that collection initializers work more pleasantly.
AddPublicMemberAttributes(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName); 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("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public int {0}Count {{", PropertyName); writer.WriteLine("public int {0}Count {{", PropertyName);
...@@ -88,22 +88,26 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -88,22 +88,26 @@ namespace Google.ProtocolBuffers.ProtoGen
AddPublicMemberAttributes(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_[index] = value;", Name); writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddPublicMemberAttributes(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName); writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer); AddNullCheck(writer);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName); writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddPublicMemberAttributes(writer); AddPublicMemberAttributes(writer);
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName); writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(values);", Name); writer.WriteLine(" result.{0}_.Add(values);", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
AddDeprecatedFlag(writer); AddDeprecatedFlag(writer);
writer.WriteLine("public Builder Clear{0}() {{", PropertyName); writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Clear();", Name); writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;"); writer.WriteLine(" return this;");
writer.WriteLine("}"); writer.WriteLine("}");
......
...@@ -111,22 +111,6 @@ namespace Google.ProtocolBuffers ...@@ -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] [Test]
public void DefaultInstance() public void DefaultInstance()
{ {
......
...@@ -103,6 +103,7 @@ ...@@ -103,6 +103,7 @@
<Compile Include="NameHelpersTest.cs" /> <Compile Include="NameHelpersTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReflectionTester.cs" /> <Compile Include="ReflectionTester.cs" />
<Compile Include="ReusableBuilderTest.cs" />
<Compile Include="SerializableTest.cs" /> <Compile Include="SerializableTest.cs" />
<Compile Include="ServiceTest.cs" /> <Compile Include="ServiceTest.cs" />
<Compile Include="TestCornerCases.cs" /> <Compile Include="TestCornerCases.cs" />
......
using System;
using System.Collections.Generic;
using System.Text;
using Google.ProtocolBuffers.Collections;
using NUnit.Framework;
using Google.ProtocolBuffers.TestProtos;
using Google.ProtocolBuffers.Serialization;
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<bool>), TestAllTypes.DefaultInstance.RepeatedBoolList.GetType());
PopsicleList<bool> list = (PopsicleList<bool>)TestAllTypes.DefaultInstance.RepeatedBoolList;
Assert.IsTrue(list.IsReadOnly);
}
[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 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()
{
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 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()
{
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 CloneOnGetRepeatedForeignMessageList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedForeignMessageList);
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 CloneOnGetRepeatedForeignEnumList()
{
TestAllTypes.Builder builder = TestAllTypes.DefaultInstance.ToBuilder();
Assert.IsTrue(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
GC.KeepAlive(builder.RepeatedForeignEnumList);
Assert.IsFalse(ReferenceEquals(TestAllTypes.DefaultInstance, builder.Build()));
}
}
}
...@@ -191,7 +191,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -191,7 +191,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(OptionsMessage prototype) { public static Builder CreateBuilder(OptionsMessage prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -201,21 +201,48 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -201,21 +201,48 @@ namespace Google.ProtocolBuffers.TestProtos {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } 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 { protected override OptionsMessage MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new OptionsMessage(); result = DefaultInstance ?? new OptionsMessage();
builderIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { 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 { public override pbd::MessageDescriptor DescriptorForType {
...@@ -227,12 +254,11 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -227,12 +254,11 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override OptionsMessage BuildPartial() { public override OptionsMessage BuildPartial() {
if (result == null) { if (builderIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
OptionsMessage returnMe = result; builderIsReadOnly = true;
result = null; return result;
return returnMe;
} }
public override Builder MergeFrom(pb::IMessage other) { public override Builder MergeFrom(pb::IMessage other) {
...@@ -246,6 +272,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -246,6 +272,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(OptionsMessage other) { public override Builder MergeFrom(OptionsMessage other) {
if (other == global::Google.ProtocolBuffers.TestProtos.OptionsMessage.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.OptionsMessage.DefaultInstance) return this;
PrepareBuilder();
if (other.HasNormal) { if (other.HasNormal) {
Normal = other.Normal; Normal = other.Normal;
} }
...@@ -264,6 +291,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -264,6 +291,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
pb::UnknownFieldSet.Builder unknownFields = null; pb::UnknownFieldSet.Builder unknownFields = null;
uint tag; uint tag;
string field_name; string field_name;
...@@ -328,11 +356,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -328,11 +356,13 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public Builder SetNormal(string value) { public Builder SetNormal(string value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
result.hasNormal = true; result.hasNormal = true;
result.normal_ = value; result.normal_ = value;
return this; return this;
} }
public Builder ClearNormal() { public Builder ClearNormal() {
PrepareBuilder();
result.hasNormal = false; result.hasNormal = false;
result.normal_ = ""; result.normal_ = "";
return this; return this;
...@@ -347,11 +377,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -347,11 +377,13 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public Builder SetOptionsMessage_(string value) { public Builder SetOptionsMessage_(string value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
result.hasOptionsMessage_ = true; result.hasOptionsMessage_ = true;
result.optionsMessage_ = value; result.optionsMessage_ = value;
return this; return this;
} }
public Builder ClearOptionsMessage_() { public Builder ClearOptionsMessage_() {
PrepareBuilder();
result.hasOptionsMessage_ = false; result.hasOptionsMessage_ = false;
result.optionsMessage_ = ""; result.optionsMessage_ = "";
return this; return this;
...@@ -366,11 +398,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -366,11 +398,13 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public Builder SetCustomName(string value) { public Builder SetCustomName(string value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
result.hasCustomName = true; result.hasCustomName = true;
result.customized_ = value; result.customized_ = value;
return this; return this;
} }
public Builder ClearCustomName() { public Builder ClearCustomName() {
PrepareBuilder();
result.hasCustomName = false; result.hasCustomName = false;
result.customized_ = ""; result.customized_ = "";
return this; return this;
......
...@@ -187,7 +187,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -187,7 +187,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(TestEmbedOptimizedForSize prototype) { public static Builder CreateBuilder(TestEmbedOptimizedForSize prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -197,21 +197,48 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -197,21 +197,48 @@ namespace Google.ProtocolBuffers.TestProtos {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } 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 { protected override TestEmbedOptimizedForSize MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new TestEmbedOptimizedForSize(); result = DefaultInstance ?? new TestEmbedOptimizedForSize();
builderIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { 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 { public override pbd::MessageDescriptor DescriptorForType {
...@@ -223,13 +250,12 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -223,13 +250,12 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override TestEmbedOptimizedForSize BuildPartial() { public override TestEmbedOptimizedForSize BuildPartial() {
if (result == null) { if (builderIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
result.repeatedMessage_.MakeReadOnly(); result.repeatedMessage_.MakeReadOnly();
TestEmbedOptimizedForSize returnMe = result; builderIsReadOnly = true;
result = null; return result;
return returnMe;
} }
public override Builder MergeFrom(pb::IMessage other) { public override Builder MergeFrom(pb::IMessage other) {
...@@ -243,6 +269,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -243,6 +269,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(TestEmbedOptimizedForSize other) { public override Builder MergeFrom(TestEmbedOptimizedForSize other) {
if (other == global::Google.ProtocolBuffers.TestProtos.TestEmbedOptimizedForSize.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.TestEmbedOptimizedForSize.DefaultInstance) return this;
PrepareBuilder();
if (other.HasOptionalMessage) { if (other.HasOptionalMessage) {
MergeOptionalMessage(other.OptionalMessage); MergeOptionalMessage(other.OptionalMessage);
} }
...@@ -258,6 +285,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -258,6 +285,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
pb::UnknownFieldSet.Builder unknownFields = null; pb::UnknownFieldSet.Builder unknownFields = null;
uint tag; uint tag;
string field_name; string field_name;
...@@ -323,18 +351,21 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -323,18 +351,21 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) { public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
result.hasOptionalMessage = true; result.hasOptionalMessage = true;
result.optionalMessage_ = value; result.optionalMessage_ = value;
return this; return this;
} }
public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) { public Builder SetOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) {
pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
PrepareBuilder();
result.hasOptionalMessage = true; result.hasOptionalMessage = true;
result.optionalMessage_ = builderForValue.Build(); result.optionalMessage_ = builderForValue.Build();
return this; return this;
} }
public Builder MergeOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) { public Builder MergeOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
if (result.hasOptionalMessage && if (result.hasOptionalMessage &&
result.optionalMessage_ != global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.DefaultInstance) { result.optionalMessage_ != global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.DefaultInstance) {
result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.CreateBuilder(result.optionalMessage_).MergeFrom(value).BuildPartial(); result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.CreateBuilder(result.optionalMessage_).MergeFrom(value).BuildPartial();
...@@ -345,13 +376,14 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -345,13 +376,14 @@ namespace Google.ProtocolBuffers.TestProtos {
return this; return this;
} }
public Builder ClearOptionalMessage() { public Builder ClearOptionalMessage() {
PrepareBuilder();
result.hasOptionalMessage = false; result.hasOptionalMessage = false;
result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.DefaultInstance; result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.DefaultInstance;
return this; return this;
} }
public pbc::IPopsicleList<global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize> RepeatedMessageList { public pbc::IPopsicleList<global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize> RepeatedMessageList {
get { return result.repeatedMessage_; } get { return PrepareBuilder().repeatedMessage_; }
} }
public int RepeatedMessageCount { public int RepeatedMessageCount {
get { return result.RepeatedMessageCount; } get { return result.RepeatedMessageCount; }
...@@ -361,29 +393,35 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -361,29 +393,35 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) { public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
result.repeatedMessage_[index] = value; result.repeatedMessage_[index] = value;
return this; return this;
} }
public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) { public Builder SetRepeatedMessage(int index, global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) {
pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
PrepareBuilder();
result.repeatedMessage_[index] = builderForValue.Build(); result.repeatedMessage_[index] = builderForValue.Build();
return this; return this;
} }
public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) { public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) {
pb::ThrowHelper.ThrowIfNull(value, "value"); pb::ThrowHelper.ThrowIfNull(value, "value");
PrepareBuilder();
result.repeatedMessage_.Add(value); result.repeatedMessage_.Add(value);
return this; return this;
} }
public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) { public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) {
pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
PrepareBuilder();
result.repeatedMessage_.Add(builderForValue.Build()); result.repeatedMessage_.Add(builderForValue.Build());
return this; return this;
} }
public Builder AddRangeRepeatedMessage(scg::IEnumerable<global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize> values) { public Builder AddRangeRepeatedMessage(scg::IEnumerable<global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize> values) {
PrepareBuilder();
result.repeatedMessage_.Add(values); result.repeatedMessage_.Add(values);
return this; return this;
} }
public Builder ClearRepeatedMessage() { public Builder ClearRepeatedMessage() {
PrepareBuilder();
result.repeatedMessage_.Clear(); result.repeatedMessage_.Clear();
return this; return this;
} }
......
...@@ -151,7 +151,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -151,7 +151,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(ImportMessageLite prototype) { public static Builder CreateBuilder(ImportMessageLite prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -161,21 +161,48 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -161,21 +161,48 @@ namespace Google.ProtocolBuffers.TestProtos {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } 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 { protected override ImportMessageLite MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new ImportMessageLite(); result = DefaultInstance ?? new ImportMessageLite();
builderIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { 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 { public override ImportMessageLite DefaultInstanceForType {
...@@ -183,12 +210,11 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -183,12 +210,11 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override ImportMessageLite BuildPartial() { public override ImportMessageLite BuildPartial() {
if (result == null) { if (builderIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
ImportMessageLite returnMe = result; builderIsReadOnly = true;
result = null; return result;
return returnMe;
} }
public override Builder MergeFrom(pb::IMessageLite other) { public override Builder MergeFrom(pb::IMessageLite other) {
...@@ -202,6 +228,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -202,6 +228,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(ImportMessageLite other) { public override Builder MergeFrom(ImportMessageLite other) {
if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this;
PrepareBuilder();
if (other.HasD) { if (other.HasD) {
D = other.D; D = other.D;
} }
...@@ -213,6 +240,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -213,6 +240,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
...@@ -255,11 +283,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -255,11 +283,13 @@ namespace Google.ProtocolBuffers.TestProtos {
set { SetD(value); } set { SetD(value); }
} }
public Builder SetD(int value) { public Builder SetD(int value) {
PrepareBuilder();
result.hasD = true; result.hasD = true;
result.d_ = value; result.d_ = value;
return this; return this;
} }
public Builder ClearD() { public Builder ClearD() {
PrepareBuilder();
result.hasD = false; result.hasD = false;
result.d_ = 0; result.d_ = 0;
return this; return this;
......
...@@ -170,7 +170,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -170,7 +170,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(ImportMessage prototype) { public static Builder CreateBuilder(ImportMessage prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -180,21 +180,48 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -180,21 +180,48 @@ namespace Google.ProtocolBuffers.TestProtos {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } 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 { protected override ImportMessage MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new ImportMessage(); result = DefaultInstance ?? new ImportMessage();
builderIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { 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 { public override pbd::MessageDescriptor DescriptorForType {
...@@ -206,12 +233,11 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -206,12 +233,11 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override ImportMessage BuildPartial() { public override ImportMessage BuildPartial() {
if (result == null) { if (builderIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
ImportMessage returnMe = result; builderIsReadOnly = true;
result = null; return result;
return returnMe;
} }
public override Builder MergeFrom(pb::IMessage other) { public override Builder MergeFrom(pb::IMessage other) {
...@@ -225,6 +251,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -225,6 +251,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(ImportMessage other) { public override Builder MergeFrom(ImportMessage other) {
if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) return this;
PrepareBuilder();
if (other.HasD) { if (other.HasD) {
D = other.D; D = other.D;
} }
...@@ -237,6 +264,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -237,6 +264,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
pb::UnknownFieldSet.Builder unknownFields = null; pb::UnknownFieldSet.Builder unknownFields = null;
uint tag; uint tag;
string field_name; string field_name;
...@@ -292,11 +320,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -292,11 +320,13 @@ namespace Google.ProtocolBuffers.TestProtos {
set { SetD(value); } set { SetD(value); }
} }
public Builder SetD(int value) { public Builder SetD(int value) {
PrepareBuilder();
result.hasD = true; result.hasD = true;
result.d_ = value; result.d_ = value;
return this; return this;
} }
public Builder ClearD() { public Builder ClearD() {
PrepareBuilder();
result.hasD = false; result.hasD = false;
result.d_ = 0; result.d_ = 0;
return this; return this;
......
...@@ -184,7 +184,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -184,7 +184,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(TestMessage prototype) { public static Builder CreateBuilder(TestMessage prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -194,21 +194,48 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -194,21 +194,48 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } 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 { protected override TestMessage MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new TestMessage(); result = DefaultInstance ?? new TestMessage();
builderIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { 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 { public override pbd::MessageDescriptor DescriptorForType {
...@@ -220,12 +247,11 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -220,12 +247,11 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
} }
public override TestMessage BuildPartial() { public override TestMessage BuildPartial() {
if (result == null) { if (builderIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
TestMessage returnMe = result; builderIsReadOnly = true;
result = null; return result;
return returnMe;
} }
public override Builder MergeFrom(pb::IMessage other) { public override Builder MergeFrom(pb::IMessage other) {
...@@ -239,6 +265,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -239,6 +265,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
public override Builder MergeFrom(TestMessage other) { public override Builder MergeFrom(TestMessage other) {
if (other == global::Google.ProtocolBuffers.TestProtos.NoGenericService.TestMessage.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.NoGenericService.TestMessage.DefaultInstance) return this;
PrepareBuilder();
if (other.HasA) { if (other.HasA) {
A = other.A; A = other.A;
} }
...@@ -252,6 +279,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -252,6 +279,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
pb::UnknownFieldSet.Builder unknownFields = null; pb::UnknownFieldSet.Builder unknownFields = null;
uint tag; uint tag;
string field_name; string field_name;
...@@ -307,11 +335,13 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -307,11 +335,13 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
set { SetA(value); } set { SetA(value); }
} }
public Builder SetA(int value) { public Builder SetA(int value) {
PrepareBuilder();
result.hasA = true; result.hasA = true;
result.a_ = value; result.a_ = value;
return this; return this;
} }
public Builder ClearA() { public Builder ClearA() {
PrepareBuilder();
result.hasA = false; result.hasA = false;
result.a_ = 0; result.a_ = 0;
return this; return this;
......
...@@ -58,12 +58,7 @@ namespace Google.ProtocolBuffers ...@@ -58,12 +58,7 @@ namespace Google.ProtocolBuffers
protected internal FieldAccessorTable<TMessage, TBuilder> InternalFieldAccessors protected internal FieldAccessorTable<TMessage, TBuilder> InternalFieldAccessors
{ {
get { return MessageBeingBuilt.FieldAccessorsFromBuilder; } get { return DefaultInstanceForType.FieldAccessorsFromBuilder; }
}
public override bool IsInitialized
{
get { return MessageBeingBuilt.IsInitialized; }
} }
public override IDictionary<FieldDescriptor, object> AllFields public override IDictionary<FieldDescriptor, object> AllFields
...@@ -97,7 +92,7 @@ namespace Google.ProtocolBuffers ...@@ -97,7 +92,7 @@ namespace Google.ProtocolBuffers
public override MessageDescriptor DescriptorForType public override MessageDescriptor DescriptorForType
{ {
get { return MessageBeingBuilt.DescriptorForType; } get { return DefaultInstanceForType.DescriptorForType; }
} }
public override int GetRepeatedFieldCount(FieldDescriptor field) public override int GetRepeatedFieldCount(FieldDescriptor field)
...@@ -204,7 +199,7 @@ namespace Google.ProtocolBuffers ...@@ -204,7 +199,7 @@ namespace Google.ProtocolBuffers
public override TMessage Build() public override TMessage Build()
{ {
// If the message is null, we'll throw a more appropriate exception in BuildPartial. // If the message is null, we'll throw a more appropriate exception in BuildPartial.
if (MessageBeingBuilt != null && !IsInitialized) if (!IsInitialized)
{ {
throw new UninitializedMessageException(MessageBeingBuilt); throw new UninitializedMessageException(MessageBeingBuilt);
} }
......
...@@ -61,11 +61,6 @@ namespace Google.ProtocolBuffers ...@@ -61,11 +61,6 @@ namespace Google.ProtocolBuffers
public abstract TBuilder MergeFrom(TMessage other); public abstract TBuilder MergeFrom(TMessage other);
public override bool IsInitialized
{
get { return MessageBeingBuilt.IsInitialized; }
}
/// <summary> /// <summary>
/// Called by derived classes to parse an unknown field. /// Called by derived classes to parse an unknown field.
/// </summary> /// </summary>
...@@ -96,7 +91,7 @@ namespace Google.ProtocolBuffers ...@@ -96,7 +91,7 @@ namespace Google.ProtocolBuffers
public override TMessage Build() public override TMessage Build()
{ {
// If the message is null, we'll throw a more appropriate exception in BuildPartial. // If the message is null, we'll throw a more appropriate exception in BuildPartial.
if (MessageBeingBuilt != null && !IsInitialized) if (!IsInitialized)
{ {
throw new UninitializedMessageException(MessageBeingBuilt); throw new UninitializedMessageException(MessageBeingBuilt);
} }
......
...@@ -151,7 +151,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -151,7 +151,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder ToBuilder() { return CreateBuilder(this); } public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(ImportMessageLite prototype) { public static Builder CreateBuilder(ImportMessageLite prototype) {
return (Builder) new Builder().MergeFrom(prototype); return new Builder(prototype);
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
...@@ -161,21 +161,48 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -161,21 +161,48 @@ namespace Google.ProtocolBuffers.TestProtos {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } 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 { protected override ImportMessageLite MessageBeingBuilt {
get { return result; } get { return PrepareBuilder(); }
} }
public override Builder Clear() { public override Builder Clear() {
result = new ImportMessageLite(); result = DefaultInstance ?? new ImportMessageLite();
builderIsReadOnly = true;
return this; return this;
} }
public override Builder Clone() { 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 { public override ImportMessageLite DefaultInstanceForType {
...@@ -183,12 +210,11 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -183,12 +210,11 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override ImportMessageLite BuildPartial() { public override ImportMessageLite BuildPartial() {
if (result == null) { if (builderIsReadOnly) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder"); return result;
} }
ImportMessageLite returnMe = result; builderIsReadOnly = true;
result = null; return result;
return returnMe;
} }
public override Builder MergeFrom(pb::IMessageLite other) { public override Builder MergeFrom(pb::IMessageLite other) {
...@@ -202,6 +228,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -202,6 +228,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(ImportMessageLite other) { public override Builder MergeFrom(ImportMessageLite other) {
if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this;
PrepareBuilder();
if (other.HasD) { if (other.HasD) {
D = other.D; D = other.D;
} }
...@@ -213,6 +240,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -213,6 +240,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
...@@ -255,11 +283,13 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -255,11 +283,13 @@ namespace Google.ProtocolBuffers.TestProtos {
set { SetD(value); } set { SetD(value); }
} }
public Builder SetD(int value) { public Builder SetD(int value) {
PrepareBuilder();
result.hasD = true; result.hasD = true;
result.d_ = value; result.d_ = value;
return this; return this;
} }
public Builder ClearD() { public Builder ClearD() {
PrepareBuilder();
result.hasD = false; result.hasD = false;
result.d_ = 0; result.d_ = 0;
return this; return this;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment