Commit e81a9d7c authored by Jon Skeet's avatar Jon Skeet

Added ToBuilder and WeakToBuilder

parent 25a28580
......@@ -179,6 +179,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -435,6 +436,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -732,6 +734,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......
......@@ -525,6 +525,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(Message1 prototype) {
return (Builder) new Builder().MergeFrom(prototype);
......@@ -1568,6 +1569,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(Message2 prototype) {
return (Builder) new Builder().MergeFrom(prototype);
......@@ -2194,6 +2196,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -2886,6 +2889,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(Message3 prototype) {
return (Builder) new Builder().MergeFrom(prototype);
......@@ -3670,6 +3674,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(Message4 prototype) {
return (Builder) new Builder().MergeFrom(prototype);
......
......@@ -803,6 +803,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -2320,6 +2321,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -3267,6 +3269,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -4339,6 +4342,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(SpeedMessage3 prototype) {
return (Builder) new Builder().MergeFrom(prototype);
......@@ -5463,6 +5467,7 @@ namespace Google.ProtocolBuffers.ProtoBench {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(SpeedMessage4 prototype) {
return (Builder) new Builder().MergeFrom(prototype);
......
......@@ -267,6 +267,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
private void GenerateBuilder(TextGenerator writer) {
writer.WriteLine("public static Builder CreateBuilder() { return new Builder(); }");
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);");
......
......@@ -297,6 +297,10 @@ namespace Google.ProtocolBuffers {
return new Builder(wrappedMessage.WeakCreateBuilderForType());
}
public override Builder ToBuilder() {
return new Builder(wrappedMessage.WeakToBuilder());
}
internal class Builder : AbstractBuilder<AbstractMessageWrapper, Builder> {
private readonly IBuilder wrappedBuilder;
......
using System.Collections.Generic;
using Google.ProtocolBuffers.TestProtos;
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
......@@ -173,5 +174,26 @@ namespace Google.ProtocolBuffers {
DynamicMessage copy = DynamicMessage.CreateBuilder(message).Build();
reflectionTester.AssertAllFieldsSetViaReflection(copy);
}
[Test]
public void ToBuilder() {
DynamicMessage.Builder builder =
DynamicMessage.CreateBuilder(TestAllTypes.Descriptor);
reflectionTester.SetAllFieldsViaReflection(builder);
int unknownFieldNum = 9;
ulong unknownFieldVal = 90;
builder.SetUnknownFields(UnknownFieldSet.CreateBuilder()
.AddField(unknownFieldNum,
UnknownField.CreateBuilder().AddVarint(unknownFieldVal).Build())
.Build());
DynamicMessage message = builder.Build();
DynamicMessage derived = message.ToBuilder().Build();
reflectionTester.AssertAllFieldsSetViaReflection(derived);
IList<ulong> values = derived.UnknownFields.FieldDictionary[unknownFieldNum].VarintList;
Assert.AreEqual(1, values.Count);
Assert.AreEqual(unknownFieldVal, values[0]);
}
}
}
......@@ -385,5 +385,13 @@ namespace Google.ProtocolBuffers {
Assert.IsTrue(builder.IsInitialized);
Assert.IsTrue(builder.BuildPartial().IsInitialized);
}
[Test]
public void ToBuilder() {
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
TestUtil.SetAllFields(builder);
TestAllTypes message = builder.Build();
TestUtil.AssertAllFieldsSet(message.ToBuilder().Build());
}
}
}
......@@ -344,6 +344,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -453,6 +454,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -543,6 +545,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -643,6 +646,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -733,6 +737,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -823,6 +828,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -913,6 +919,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1003,6 +1010,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1093,6 +1101,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1183,6 +1192,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1282,6 +1292,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1425,6 +1436,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1541,6 +1553,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1754,6 +1767,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1861,6 +1875,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -2014,6 +2029,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -2122,6 +2138,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......
......@@ -146,6 +146,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......
......@@ -129,6 +129,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......
......@@ -143,6 +143,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -311,6 +312,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -528,6 +530,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -722,6 +725,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -956,6 +960,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1157,6 +1162,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......
......@@ -122,6 +122,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -275,6 +276,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -392,6 +394,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......
......@@ -58,12 +58,17 @@ namespace Google.ProtocolBuffers {
public abstract UnknownFieldSet UnknownFields { get; }
public abstract TMessage DefaultInstanceForType { get; }
public abstract TBuilder CreateBuilderForType();
public abstract TBuilder ToBuilder();
#endregion
public IBuilder WeakCreateBuilderForType() {
return CreateBuilderForType();
}
public IBuilder WeakToBuilder() {
return ToBuilder();
}
public IMessage WeakDefaultInstanceForType {
get { return DefaultInstanceForType; }
}
......
......@@ -143,6 +143,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -334,6 +335,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......
......@@ -279,6 +279,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -631,6 +632,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1165,6 +1167,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -1478,6 +1481,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -2099,6 +2103,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -2541,6 +2546,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -2863,6 +2869,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -3167,6 +3174,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -3504,6 +3512,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -3876,6 +3885,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -4223,6 +4233,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -4528,6 +4539,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -4834,6 +4846,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -5059,6 +5072,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -5284,6 +5298,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -5509,6 +5524,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -5766,6 +5782,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......@@ -6045,6 +6062,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
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);
......
......@@ -74,7 +74,6 @@ namespace Google.ProtocolBuffers {
Builder builder = CreateBuilder(type);
Builder dynamicBuilder = builder.MergeFrom(input);
return dynamicBuilder.BuildParsed();
}
/// <summary>
......@@ -247,6 +246,10 @@ namespace Google.ProtocolBuffers {
return new Builder(type);
}
public override Builder ToBuilder() {
return CreateBuilderForType().MergeFrom(this);
}
/// <summary>
/// Verifies that the field is a field of this message.
/// </summary>
......
......@@ -326,8 +326,7 @@ namespace Google.ProtocolBuffers {
}
} else if (field.MappedType == MappedType.Message && existingValue != null) {
IMessage existingMessage = (IMessage)existingValue;
IMessage merged = existingMessage.WeakCreateBuilderForType()
.WeakMergeFrom(existingMessage)
IMessage merged = existingMessage.WeakToBuilder()
.WeakMergeFrom((IMessage) entry.Value)
.WeakBuild();
this[field] = merged;
......
......@@ -168,11 +168,18 @@ namespace Google.ProtocolBuffers {
/// <summary>
/// Creates a builder for the type, but in a weakly typed manner. This
/// is typically implemented by strongly typed builders by just returning
/// is typically implemented by strongly typed messages by just returning
/// the result of CreateBuilderForType.
/// </summary>
IBuilder WeakCreateBuilderForType();
/// <summary>
/// Creates a builder with the same contents as this message. This
/// is typically implemented by strongly typed messages by just returning
/// the result of ToBuilder.
/// </summary>
IBuilder WeakToBuilder();
IMessage WeakDefaultInstanceForType { get; }
}
......@@ -198,6 +205,12 @@ namespace Google.ProtocolBuffers {
/// Constructs a new builder for a message of the same type as this message.
/// </summary>
TBuilder CreateBuilderForType();
/// <summary>
/// Creates a builder with the same contents as this current instance.
/// This is typically implemented by strongly typed messages by just
/// returning the result of ToBuilder().
/// </summary>
TBuilder ToBuilder();
#endregion
}
}
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