From 0bf2ad145daf4ed7eb0f72c111b496d55233e0b9 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 21 Aug 2008 21:57:58 +0100 Subject: Implemented popsicle immutability for lists. Modified MessageStreamIterator to be singly generic. --- .../Collections/PopsicleListTest.cs | 64 +++ .../ProtocolBuffers.Test/GeneratedMessageTest.cs | 47 +- .../MessageStreamIteratorTest.cs | 2 +- .../ProtocolBuffers.Test.csproj | 1 + .../TestProtos/MessageWithNoOuter.cs | 23 +- .../UnitTestEmbedOptimizeForProtoFile.cs | 24 +- .../TestProtos/UnitTestImportProtoFile.cs | 2 +- .../TestProtos/UnitTestMessageSetProtoFile.cs | 34 +- .../TestProtos/UnitTestOptimizeForProtoFile.cs | 2 +- .../TestProtos/UnitTestProtoFile.cs | 630 ++++++--------------- csharp/ProtocolBuffers/Collections/PopsicleList.cs | 95 ++++ csharp/ProtocolBuffers/Delegates.cs | 28 +- .../DescriptorProtos/DescriptorProtoFile.cs | 315 +++-------- csharp/ProtocolBuffers/FieldAccess/Delegates.cs | 26 - csharp/ProtocolBuffers/MessageStreamIterator.cs | 148 +++-- csharp/ProtocolBuffers/ProtocolBuffers.csproj | 2 +- 16 files changed, 580 insertions(+), 863 deletions(-) create mode 100644 csharp/ProtocolBuffers.Test/Collections/PopsicleListTest.cs create mode 100644 csharp/ProtocolBuffers/Collections/PopsicleList.cs delete mode 100644 csharp/ProtocolBuffers/FieldAccess/Delegates.cs (limited to 'csharp') diff --git a/csharp/ProtocolBuffers.Test/Collections/PopsicleListTest.cs b/csharp/ProtocolBuffers.Test/Collections/PopsicleListTest.cs new file mode 100644 index 00000000..6943672d --- /dev/null +++ b/csharp/ProtocolBuffers.Test/Collections/PopsicleListTest.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; + +namespace Google.ProtocolBuffers.Collections { + [TestFixture] + public class PopsicleListTest { + + [Test] + public void MutatingOperationsOnFrozenList() { + PopsicleList list = new PopsicleList(); + list.MakeReadOnly(); + AssertNotSupported(() => list.Add("")); + AssertNotSupported(() => list.Clear()); + AssertNotSupported(() => list.Insert(0, "")); + AssertNotSupported(() => list.Remove("")); + AssertNotSupported(() => list.RemoveAt(0)); + } + + [Test] + public void NonMutatingOperationsOnFrozenList() { + PopsicleList list = new PopsicleList(); + list.MakeReadOnly(); + Assert.IsFalse(list.Contains("")); + Assert.AreEqual(0, list.Count); + list.CopyTo(new string[5], 0); + list.GetEnumerator(); + Assert.AreEqual(-1, list.IndexOf("")); + Assert.IsTrue(list.IsReadOnly); + } + + [Test] + public void MutatingOperationsOnFluidList() { + PopsicleList list = new PopsicleList(); + list.Add(""); + list.Clear(); + list.Insert(0, ""); + list.Remove(""); + list.Add("x"); // Just to make the next call valid + list.RemoveAt(0); + } + + [Test] + public void NonMutatingOperationsOnFluidList() { + PopsicleList list = new PopsicleList(); + Assert.IsFalse(list.Contains("")); + Assert.AreEqual(0, list.Count); + list.CopyTo(new string[5], 0); + list.GetEnumerator(); + Assert.AreEqual(-1, list.IndexOf("")); + Assert.IsFalse(list.IsReadOnly); + } + + private static void AssertNotSupported(Action action) { + try { + action(); + Assert.Fail("Expected NotSupportedException"); + } catch (NotSupportedException) { + // Expected + } + } + } +} diff --git a/csharp/ProtocolBuffers.Test/GeneratedMessageTest.cs b/csharp/ProtocolBuffers.Test/GeneratedMessageTest.cs index 9a08ed95..f51f9755 100644 --- a/csharp/ProtocolBuffers.Test/GeneratedMessageTest.cs +++ b/csharp/ProtocolBuffers.Test/GeneratedMessageTest.cs @@ -13,6 +13,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using Google.ProtocolBuffers.Descriptors; using Google.ProtocolBuffers.TestProtos; using NUnit.Framework; @@ -28,7 +30,50 @@ namespace Google.ProtocolBuffers { reflectionTester = ReflectionTester.CreateTestAllTypesInstance(); extensionsReflectionTester = ReflectionTester.CreateTestAllExtensionsInstance(); } - + + [Test] + public void RepeatedAddPrimitiveBeforeBuild() { + TestAllTypes message = new TestAllTypes.Builder { RepeatedInt32List = { 1, 2, 3 } }.Build(); + TestUtil.AssertEqual(new int[]{1, 2, 3}, message.RepeatedInt32List); + } + + [Test] + public void AddPrimitiveFailsAfterBuild() { + TestAllTypes.Builder builder = new TestAllTypes.Builder(); + IList list = builder.RepeatedInt32List; + list.Add(1); // Fine + builder.Build(); + + try { + list.Add(2); + Assert.Fail("List should be frozen"); + } catch (NotSupportedException) { + // Expected + } + } + + [Test] + public void RepeatedAddMessageBeforeBuild() { + TestAllTypes message = new TestAllTypes.Builder { + RepeatedNestedMessageList = { new TestAllTypes.Types.NestedMessage.Builder { Bb = 10 }.Build() } }.Build(); + Assert.AreEqual(1, message.RepeatedNestedMessageCount); + Assert.AreEqual(10, message.RepeatedNestedMessageList[0].Bb); + } + + [Test] + public void AddMessageFailsAfterBuild() { + TestAllTypes.Builder builder = new TestAllTypes.Builder(); + IList list = builder.RepeatedNestedMessageList; + builder.Build(); + + try { + list.Add(new TestAllTypes.Types.NestedMessage.Builder { Bb = 10 }.Build()); + Assert.Fail("List should be frozen"); + } catch (NotSupportedException) { + // Expected + } + } + [Test] public void DefaultInstance() { Assert.AreSame(TestAllTypes.DefaultInstance, TestAllTypes.DefaultInstance.DefaultInstanceForType); diff --git a/csharp/ProtocolBuffers.Test/MessageStreamIteratorTest.cs b/csharp/ProtocolBuffers.Test/MessageStreamIteratorTest.cs index 063f06d5..0cccd4a7 100644 --- a/csharp/ProtocolBuffers.Test/MessageStreamIteratorTest.cs +++ b/csharp/ProtocolBuffers.Test/MessageStreamIteratorTest.cs @@ -11,7 +11,7 @@ namespace Google.ProtocolBuffers { [Test] public void ThreeMessagesInMemory() { MemoryStream stream = new MemoryStream(MessageStreamWriterTest.ThreeMessageData); - IEnumerable iterator = MessageStreamIterator.FromStreamProvider(() => stream); + IEnumerable iterator = MessageStreamIterator.FromStreamProvider(() => stream); List messages = new List(iterator); Assert.AreEqual(3, messages.Count); diff --git a/csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj b/csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj index 027a159f..99de695e 100644 --- a/csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj +++ b/csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj @@ -50,6 +50,7 @@ + diff --git a/csharp/ProtocolBuffers.Test/TestProtos/MessageWithNoOuter.cs b/csharp/ProtocolBuffers.Test/TestProtos/MessageWithNoOuter.cs index 6e44a0c9..64f09f86 100644 --- a/csharp/ProtocolBuffers.Test/TestProtos/MessageWithNoOuter.cs +++ b/csharp/ProtocolBuffers.Test/TestProtos/MessageWithNoOuter.cs @@ -7,7 +7,7 @@ using scg = global::System.Collections.Generic; namespace Google.ProtocolBuffers.TestProtos { public sealed partial class MessageWithNoOuter : pb::GeneratedMessage { - private static readonly MessageWithNoOuter defaultInstance = new MessageWithNoOuter(); + private static readonly MessageWithNoOuter defaultInstance = new Builder().BuildPartial(); public static MessageWithNoOuter DefaultInstance { get { return defaultInstance; } } @@ -35,7 +35,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class NestedMessage : pb::GeneratedMessage { - private static readonly NestedMessage defaultInstance = new NestedMessage(); + private static readonly NestedMessage defaultInstance = new Builder().BuildPartial(); public static NestedMessage DefaultInstance { get { return defaultInstance; } } @@ -179,7 +179,7 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated .protobuf_unittest.TestAllTypes foreign = 2; - private scg::IList foreign_ = pbc::Lists.Empty; + private pbc::PopsicleList foreign_ = new pbc::PopsicleList(); public scg::IList ForeignList { get { return foreign_; } } @@ -278,9 +278,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter BuildPartial() { - if (result.foreign_ != pbc::Lists.Empty) { - result.foreign_ = pbc::Lists.AsReadOnly(result.foreign_); - } + result.foreign_.MakeReadOnly(); global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter returnMe = result; result = null; return returnMe; @@ -324,7 +322,7 @@ namespace Google.ProtocolBuffers.TestProtos { // repeated .protobuf_unittest.TestAllTypes foreign = 2; public scg::IList ForeignList { - get { return pbc::Lists.AsReadOnly(result.foreign_); } + get { return result.foreign_; } } public int ForeignCount { get { return result.ForeignCount; } @@ -341,28 +339,19 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddForeign(global::Google.ProtocolBuffers.TestProtos.TestAllTypes value) { - if (result.foreign_ == pbc::Lists.Empty) { - result.foreign_ = new scg::List(); - } result.foreign_.Add(value); return this; } public Builder AddForeign(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Builder builderForValue) { - if (result.foreign_ == pbc::Lists.Empty) { - result.foreign_ = new scg::List(); - } result.foreign_.Add(builderForValue.Build()); return this; } public Builder AddRangeForeign(scg::IEnumerable values) { - if (result.foreign_ == pbc::Lists.Empty) { - result.foreign_ = new scg::List(); - } base.AddRange(values, result.foreign_); return this; } public Builder ClearForeign() { - result.foreign_ = pbc::Lists.Empty; + result.foreign_.Clear(); return this; } diff --git a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestEmbedOptimizeForProtoFile.cs b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestEmbedOptimizeForProtoFile.cs index cae05bf8..8f4f3076 100644 --- a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestEmbedOptimizeForProtoFile.cs +++ b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestEmbedOptimizeForProtoFile.cs @@ -55,7 +55,7 @@ namespace Google.ProtocolBuffers.TestProtos { #region Messages public sealed partial class TestEmbedOptimizedForSize : pb::GeneratedMessage { - private static readonly TestEmbedOptimizedForSize defaultInstance = new TestEmbedOptimizedForSize(); + private static readonly TestEmbedOptimizedForSize defaultInstance = new Builder().BuildPartial(); public static TestEmbedOptimizedForSize DefaultInstance { get { return defaultInstance; } } @@ -87,7 +87,7 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated .protobuf_unittest.TestOptimizedForSize repeated_message = 2; - private scg::IList repeatedMessage_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedMessage_ = new pbc::PopsicleList(); public scg::IList RepeatedMessageList { get { return repeatedMessage_; } } @@ -211,9 +211,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override global::Google.ProtocolBuffers.TestProtos.TestEmbedOptimizedForSize BuildPartial() { - if (result.repeatedMessage_ != pbc::Lists.Empty) { - result.repeatedMessage_ = pbc::Lists.AsReadOnly(result.repeatedMessage_); - } + result.repeatedMessage_.MakeReadOnly(); global::Google.ProtocolBuffers.TestProtos.TestEmbedOptimizedForSize returnMe = result; result = null; return returnMe; @@ -234,9 +232,6 @@ namespace Google.ProtocolBuffers.TestProtos { MergeOptionalMessage(other.OptionalMessage); } if (other.repeatedMessage_.Count != 0) { - if (result.repeatedMessage_.Count == 0) { - result.repeatedMessage_ = new scg::List(); - } base.AddRange(other.repeatedMessage_, result.repeatedMessage_); } this.MergeUnknownFields(other.UnknownFields); @@ -321,7 +316,7 @@ namespace Google.ProtocolBuffers.TestProtos { // repeated .protobuf_unittest.TestOptimizedForSize repeated_message = 2; public scg::IList RepeatedMessageList { - get { return pbc::Lists.AsReadOnly(result.repeatedMessage_); } + get { return result.repeatedMessage_; } } public int RepeatedMessageCount { get { return result.RepeatedMessageCount; } @@ -338,28 +333,19 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) { - if (result.repeatedMessage_ == pbc::Lists.Empty) { - result.repeatedMessage_ = new scg::List(); - } result.repeatedMessage_.Add(value); return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder builderForValue) { - if (result.repeatedMessage_ == pbc::Lists.Empty) { - result.repeatedMessage_ = new scg::List(); - } result.repeatedMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedMessage(scg::IEnumerable values) { - if (result.repeatedMessage_ == pbc::Lists.Empty) { - result.repeatedMessage_ = new scg::List(); - } base.AddRange(values, result.repeatedMessage_); return this; } public Builder ClearRepeatedMessage() { - result.repeatedMessage_ = pbc::Lists.Empty; + result.repeatedMessage_.Clear(); return this; } } diff --git a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestImportProtoFile.cs b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestImportProtoFile.cs index 5713e1c9..7d8d1d0e 100644 --- a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestImportProtoFile.cs +++ b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestImportProtoFile.cs @@ -55,7 +55,7 @@ namespace Google.ProtocolBuffers.TestProtos { #region Messages public sealed partial class ImportMessage : pb::GeneratedMessage { - private static readonly ImportMessage defaultInstance = new ImportMessage(); + private static readonly ImportMessage defaultInstance = new Builder().BuildPartial(); public static ImportMessage DefaultInstance { get { return defaultInstance; } } diff --git a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs index b3b53adf..e03eac92 100644 --- a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs +++ b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs @@ -95,7 +95,7 @@ namespace Google.ProtocolBuffers.TestProtos { #region Messages public sealed partial class TestMessageSet : pb::ExtendableMessage { - private static readonly TestMessageSet defaultInstance = new TestMessageSet(); + private static readonly TestMessageSet defaultInstance = new Builder().BuildPartial(); public static TestMessageSet DefaultInstance { get { return defaultInstance; } } @@ -264,7 +264,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestMessageSetContainer : pb::GeneratedMessage { - private static readonly TestMessageSetContainer defaultInstance = new TestMessageSetContainer(); + private static readonly TestMessageSetContainer defaultInstance = new Builder().BuildPartial(); public static TestMessageSetContainer DefaultInstance { get { return defaultInstance; } } @@ -495,7 +495,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestMessageSetExtension1 : pb::GeneratedMessage { - private static readonly TestMessageSetExtension1 defaultInstance = new TestMessageSetExtension1(); + private static readonly TestMessageSetExtension1 defaultInstance = new Builder().BuildPartial(); public static TestMessageSetExtension1 DefaultInstance { get { return defaultInstance; } } @@ -709,7 +709,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestMessageSetExtension2 : pb::GeneratedMessage { - private static readonly TestMessageSetExtension2 defaultInstance = new TestMessageSetExtension2(); + private static readonly TestMessageSetExtension2 defaultInstance = new Builder().BuildPartial(); public static TestMessageSetExtension2 DefaultInstance { get { return defaultInstance; } } @@ -923,7 +923,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class RawMessageSet : pb::GeneratedMessage { - private static readonly RawMessageSet defaultInstance = new RawMessageSet(); + private static readonly RawMessageSet defaultInstance = new Builder().BuildPartial(); public static RawMessageSet DefaultInstance { get { return defaultInstance; } } @@ -947,7 +947,7 @@ namespace Google.ProtocolBuffers.TestProtos { #region Nested types public static class Types { public sealed partial class Item : pb::GeneratedMessage { - private static readonly Item defaultInstance = new Item(); + private static readonly Item defaultInstance = new Builder().BuildPartial(); public static Item DefaultInstance { get { return defaultInstance; } } @@ -1201,7 +1201,7 @@ namespace Google.ProtocolBuffers.TestProtos { #endregion // repeated group Item = 1 { - private scg::IList item_ = pbc::Lists.Empty; + private pbc::PopsicleList item_ = new pbc::PopsicleList(); public scg::IList ItemList { get { return item_; } } @@ -1316,9 +1316,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override global::Google.ProtocolBuffers.TestProtos.RawMessageSet BuildPartial() { - if (result.item_ != pbc::Lists.Empty) { - result.item_ = pbc::Lists.AsReadOnly(result.item_); - } + result.item_.MakeReadOnly(); global::Google.ProtocolBuffers.TestProtos.RawMessageSet returnMe = result; result = null; return returnMe; @@ -1336,9 +1334,6 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(global::Google.ProtocolBuffers.TestProtos.RawMessageSet other) { if (other == global::Google.ProtocolBuffers.TestProtos.RawMessageSet.DefaultInstance) return this; if (other.item_.Count != 0) { - if (result.item_.Count == 0) { - result.item_ = new scg::List(); - } base.AddRange(other.item_, result.item_); } this.MergeUnknownFields(other.UnknownFields); @@ -1379,7 +1374,7 @@ namespace Google.ProtocolBuffers.TestProtos { // repeated group Item = 1 { public scg::IList ItemList { - get { return pbc::Lists.AsReadOnly(result.item_); } + get { return result.item_; } } public int ItemCount { get { return result.ItemCount; } @@ -1396,28 +1391,19 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddItem(global::Google.ProtocolBuffers.TestProtos.RawMessageSet.Types.Item value) { - if (result.item_ == pbc::Lists.Empty) { - result.item_ = new scg::List(); - } result.item_.Add(value); return this; } public Builder AddItem(global::Google.ProtocolBuffers.TestProtos.RawMessageSet.Types.Item.Builder builderForValue) { - if (result.item_ == pbc::Lists.Empty) { - result.item_ = new scg::List(); - } result.item_.Add(builderForValue.Build()); return this; } public Builder AddRangeItem(scg::IEnumerable values) { - if (result.item_ == pbc::Lists.Empty) { - result.item_ = new scg::List(); - } base.AddRange(values, result.item_); return this; } public Builder ClearItem() { - result.item_ = pbc::Lists.Empty; + result.item_.Clear(); return this; } } diff --git a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs index 52143f2c..de07d033 100644 --- a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs +++ b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs @@ -54,7 +54,7 @@ namespace Google.ProtocolBuffers.TestProtos { #region Messages public sealed partial class TestOptimizedForSize : pb::ExtendableMessage { - private static readonly TestOptimizedForSize defaultInstance = new TestOptimizedForSize(); + private static readonly TestOptimizedForSize defaultInstance = new Builder().BuildPartial(); public static TestOptimizedForSize DefaultInstance { get { return defaultInstance; } } diff --git a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs index 167f8718..a971832b 100644 --- a/csharp/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs +++ b/csharp/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs @@ -975,7 +975,7 @@ namespace Google.ProtocolBuffers.TestProtos { #region Messages public sealed partial class TestAllTypes : pb::GeneratedMessage { - private static readonly TestAllTypes defaultInstance = new TestAllTypes(); + private static readonly TestAllTypes defaultInstance = new Builder().BuildPartial(); public static TestAllTypes DefaultInstance { get { return defaultInstance; } } @@ -1005,7 +1005,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class NestedMessage : pb::GeneratedMessage { - private static readonly NestedMessage defaultInstance = new NestedMessage(); + private static readonly NestedMessage defaultInstance = new Builder().BuildPartial(); public static NestedMessage DefaultInstance { get { return defaultInstance; } } @@ -1212,7 +1212,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class OptionalGroup : pb::GeneratedMessage { - private static readonly OptionalGroup defaultInstance = new OptionalGroup(); + private static readonly OptionalGroup defaultInstance = new Builder().BuildPartial(); public static OptionalGroup DefaultInstance { get { return defaultInstance; } } @@ -1419,7 +1419,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class RepeatedGroup : pb::GeneratedMessage { - private static readonly RepeatedGroup defaultInstance = new RepeatedGroup(); + private static readonly RepeatedGroup defaultInstance = new Builder().BuildPartial(); public static RepeatedGroup DefaultInstance { get { return defaultInstance; } } @@ -1863,9 +1863,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated int32 repeated_int32 = 31; - private scg::IList repeatedInt32_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedInt32_ = new pbc::PopsicleList(); public scg::IList RepeatedInt32List { - get { return repeatedInt32_; } + get { return repeatedInt32_; } } public int RepeatedInt32Count { get { return repeatedInt32_.Count; } @@ -1875,9 +1875,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated int64 repeated_int64 = 32; - private scg::IList repeatedInt64_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedInt64_ = new pbc::PopsicleList(); public scg::IList RepeatedInt64List { - get { return repeatedInt64_; } + get { return repeatedInt64_; } } public int RepeatedInt64Count { get { return repeatedInt64_.Count; } @@ -1887,9 +1887,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated uint32 repeated_uint32 = 33; - private scg::IList repeatedUint32_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedUint32_ = new pbc::PopsicleList(); public scg::IList RepeatedUint32List { - get { return repeatedUint32_; } + get { return repeatedUint32_; } } public int RepeatedUint32Count { get { return repeatedUint32_.Count; } @@ -1899,9 +1899,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated uint64 repeated_uint64 = 34; - private scg::IList repeatedUint64_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedUint64_ = new pbc::PopsicleList(); public scg::IList RepeatedUint64List { - get { return repeatedUint64_; } + get { return repeatedUint64_; } } public int RepeatedUint64Count { get { return repeatedUint64_.Count; } @@ -1911,9 +1911,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated sint32 repeated_sint32 = 35; - private scg::IList repeatedSint32_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedSint32_ = new pbc::PopsicleList(); public scg::IList RepeatedSint32List { - get { return repeatedSint32_; } + get { return repeatedSint32_; } } public int RepeatedSint32Count { get { return repeatedSint32_.Count; } @@ -1923,9 +1923,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated sint64 repeated_sint64 = 36; - private scg::IList repeatedSint64_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedSint64_ = new pbc::PopsicleList(); public scg::IList RepeatedSint64List { - get { return repeatedSint64_; } + get { return repeatedSint64_; } } public int RepeatedSint64Count { get { return repeatedSint64_.Count; } @@ -1935,9 +1935,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated fixed32 repeated_fixed32 = 37; - private scg::IList repeatedFixed32_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedFixed32_ = new pbc::PopsicleList(); public scg::IList RepeatedFixed32List { - get { return repeatedFixed32_; } + get { return repeatedFixed32_; } } public int RepeatedFixed32Count { get { return repeatedFixed32_.Count; } @@ -1947,9 +1947,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated fixed64 repeated_fixed64 = 38; - private scg::IList repeatedFixed64_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedFixed64_ = new pbc::PopsicleList(); public scg::IList RepeatedFixed64List { - get { return repeatedFixed64_; } + get { return repeatedFixed64_; } } public int RepeatedFixed64Count { get { return repeatedFixed64_.Count; } @@ -1959,9 +1959,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated sfixed32 repeated_sfixed32 = 39; - private scg::IList repeatedSfixed32_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedSfixed32_ = new pbc::PopsicleList(); public scg::IList RepeatedSfixed32List { - get { return repeatedSfixed32_; } + get { return repeatedSfixed32_; } } public int RepeatedSfixed32Count { get { return repeatedSfixed32_.Count; } @@ -1971,9 +1971,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated sfixed64 repeated_sfixed64 = 40; - private scg::IList repeatedSfixed64_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedSfixed64_ = new pbc::PopsicleList(); public scg::IList RepeatedSfixed64List { - get { return repeatedSfixed64_; } + get { return repeatedSfixed64_; } } public int RepeatedSfixed64Count { get { return repeatedSfixed64_.Count; } @@ -1983,9 +1983,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated float repeated_float = 41; - private scg::IList repeatedFloat_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedFloat_ = new pbc::PopsicleList(); public scg::IList RepeatedFloatList { - get { return repeatedFloat_; } + get { return repeatedFloat_; } } public int RepeatedFloatCount { get { return repeatedFloat_.Count; } @@ -1995,9 +1995,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated double repeated_double = 42; - private scg::IList repeatedDouble_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedDouble_ = new pbc::PopsicleList(); public scg::IList RepeatedDoubleList { - get { return repeatedDouble_; } + get { return repeatedDouble_; } } public int RepeatedDoubleCount { get { return repeatedDouble_.Count; } @@ -2007,9 +2007,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated bool repeated_bool = 43; - private scg::IList repeatedBool_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedBool_ = new pbc::PopsicleList(); public scg::IList RepeatedBoolList { - get { return repeatedBool_; } + get { return repeatedBool_; } } public int RepeatedBoolCount { get { return repeatedBool_.Count; } @@ -2019,9 +2019,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated string repeated_string = 44; - private scg::IList repeatedString_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedString_ = new pbc::PopsicleList(); public scg::IList RepeatedStringList { - get { return repeatedString_; } + get { return repeatedString_; } } public int RepeatedStringCount { get { return repeatedString_.Count; } @@ -2031,9 +2031,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated bytes repeated_bytes = 45; - private scg::IList repeatedBytes_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedBytes_ = new pbc::PopsicleList(); public scg::IList RepeatedBytesList { - get { return repeatedBytes_; } + get { return repeatedBytes_; } } public int RepeatedBytesCount { get { return repeatedBytes_.Count; } @@ -2043,7 +2043,7 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated group RepeatedGroup = 46 { - private scg::IList repeatedGroup_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedGroup_ = new pbc::PopsicleList(); public scg::IList RepeatedGroupList { get { return repeatedGroup_; } } @@ -2055,7 +2055,7 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated .protobuf_unittest.TestAllTypes.NestedMessage repeated_nested_message = 48; - private scg::IList repeatedNestedMessage_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedNestedMessage_ = new pbc::PopsicleList(); public scg::IList RepeatedNestedMessageList { get { return repeatedNestedMessage_; } } @@ -2067,7 +2067,7 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated .protobuf_unittest.ForeignMessage repeated_foreign_message = 49; - private scg::IList repeatedForeignMessage_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedForeignMessage_ = new pbc::PopsicleList(); public scg::IList RepeatedForeignMessageList { get { return repeatedForeignMessage_; } } @@ -2079,7 +2079,7 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated .protobuf_unittest_import.ImportMessage repeated_import_message = 50; - private scg::IList repeatedImportMessage_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedImportMessage_ = new pbc::PopsicleList(); public scg::IList RepeatedImportMessageList { get { return repeatedImportMessage_; } } @@ -2127,9 +2127,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; - private scg::IList repeatedStringPiece_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedStringPiece_ = new pbc::PopsicleList(); public scg::IList RepeatedStringPieceList { - get { return repeatedStringPiece_; } + get { return repeatedStringPiece_; } } public int RepeatedStringPieceCount { get { return repeatedStringPiece_.Count; } @@ -2139,9 +2139,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated string repeated_cord = 55 [ctype = CORD]; - private scg::IList repeatedCord_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedCord_ = new pbc::PopsicleList(); public scg::IList RepeatedCordList { - get { return repeatedCord_; } + get { return repeatedCord_; } } public int RepeatedCordCount { get { return repeatedCord_.Count; } @@ -2873,38 +2873,30 @@ namespace Google.ProtocolBuffers.TestProtos { } public override global::Google.ProtocolBuffers.TestProtos.TestAllTypes BuildPartial() { - result.repeatedInt32_ = pbc::Lists.AsReadOnly(result.repeatedInt32_); - result.repeatedInt64_ = pbc::Lists.AsReadOnly(result.repeatedInt64_); - result.repeatedUint32_ = pbc::Lists.AsReadOnly(result.repeatedUint32_); - result.repeatedUint64_ = pbc::Lists.AsReadOnly(result.repeatedUint64_); - result.repeatedSint32_ = pbc::Lists.AsReadOnly(result.repeatedSint32_); - result.repeatedSint64_ = pbc::Lists.AsReadOnly(result.repeatedSint64_); - result.repeatedFixed32_ = pbc::Lists.AsReadOnly(result.repeatedFixed32_); - result.repeatedFixed64_ = pbc::Lists.AsReadOnly(result.repeatedFixed64_); - result.repeatedSfixed32_ = pbc::Lists.AsReadOnly(result.repeatedSfixed32_); - result.repeatedSfixed64_ = pbc::Lists.AsReadOnly(result.repeatedSfixed64_); - result.repeatedFloat_ = pbc::Lists.AsReadOnly(result.repeatedFloat_); - result.repeatedDouble_ = pbc::Lists.AsReadOnly(result.repeatedDouble_); - result.repeatedBool_ = pbc::Lists.AsReadOnly(result.repeatedBool_); - result.repeatedString_ = pbc::Lists.AsReadOnly(result.repeatedString_); - result.repeatedBytes_ = pbc::Lists.AsReadOnly(result.repeatedBytes_); - if (result.repeatedGroup_ != pbc::Lists.Empty) { - result.repeatedGroup_ = pbc::Lists.AsReadOnly(result.repeatedGroup_); - } - if (result.repeatedNestedMessage_ != pbc::Lists.Empty) { - result.repeatedNestedMessage_ = pbc::Lists.AsReadOnly(result.repeatedNestedMessage_); - } - if (result.repeatedForeignMessage_ != pbc::Lists.Empty) { - result.repeatedForeignMessage_ = pbc::Lists.AsReadOnly(result.repeatedForeignMessage_); - } - if (result.repeatedImportMessage_ != pbc::Lists.Empty) { - result.repeatedImportMessage_ = pbc::Lists.AsReadOnly(result.repeatedImportMessage_); - } + result.repeatedInt32_.MakeReadOnly(); + result.repeatedInt64_.MakeReadOnly(); + result.repeatedUint32_.MakeReadOnly(); + result.repeatedUint64_.MakeReadOnly(); + result.repeatedSint32_.MakeReadOnly(); + result.repeatedSint64_.MakeReadOnly(); + result.repeatedFixed32_.MakeReadOnly(); + result.repeatedFixed64_.MakeReadOnly(); + result.repeatedSfixed32_.MakeReadOnly(); + result.repeatedSfixed64_.MakeReadOnly(); + result.repeatedFloat_.MakeReadOnly(); + result.repeatedDouble_.MakeReadOnly(); + result.repeatedBool_.MakeReadOnly(); + result.repeatedString_.MakeReadOnly(); + result.repeatedBytes_.MakeReadOnly(); + result.repeatedGroup_.MakeReadOnly(); + result.repeatedNestedMessage_.MakeReadOnly(); + result.repeatedForeignMessage_.MakeReadOnly(); + result.repeatedImportMessage_.MakeReadOnly(); result.repeatedNestedEnum_ = pbc::Lists.AsReadOnly(result.repeatedNestedEnum_); result.repeatedForeignEnum_ = pbc::Lists.AsReadOnly(result.repeatedForeignEnum_); result.repeatedImportEnum_ = pbc::Lists.AsReadOnly(result.repeatedImportEnum_); - result.repeatedStringPiece_ = pbc::Lists.AsReadOnly(result.repeatedStringPiece_); - result.repeatedCord_ = pbc::Lists.AsReadOnly(result.repeatedCord_); + result.repeatedStringPiece_.MakeReadOnly(); + result.repeatedCord_.MakeReadOnly(); global::Google.ProtocolBuffers.TestProtos.TestAllTypes returnMe = result; result = null; return returnMe; @@ -2994,117 +2986,60 @@ namespace Google.ProtocolBuffers.TestProtos { OptionalCord = other.OptionalCord; } if (other.repeatedInt32_.Count != 0) { - if (result.repeatedInt32_.Count == 0) { - result.repeatedInt32_ = new scg::List(); - } base.AddRange(other.repeatedInt32_, result.repeatedInt32_); } if (other.repeatedInt64_.Count != 0) { - if (result.repeatedInt64_.Count == 0) { - result.repeatedInt64_ = new scg::List(); - } base.AddRange(other.repeatedInt64_, result.repeatedInt64_); } if (other.repeatedUint32_.Count != 0) { - if (result.repeatedUint32_.Count == 0) { - result.repeatedUint32_ = new scg::List(); - } base.AddRange(other.repeatedUint32_, result.repeatedUint32_); } if (other.repeatedUint64_.Count != 0) { - if (result.repeatedUint64_.Count == 0) { - result.repeatedUint64_ = new scg::List(); - } base.AddRange(other.repeatedUint64_, result.repeatedUint64_); } if (other.repeatedSint32_.Count != 0) { - if (result.repeatedSint32_.Count == 0) { - result.repeatedSint32_ = new scg::List(); - } base.AddRange(other.repeatedSint32_, result.repeatedSint32_); } if (other.repeatedSint64_.Count != 0) { - if (result.repeatedSint64_.Count == 0) { - result.repeatedSint64_ = new scg::List(); - } base.AddRange(other.repeatedSint64_, result.repeatedSint64_); } if (other.repeatedFixed32_.Count != 0) { - if (result.repeatedFixed32_.Count == 0) { - result.repeatedFixed32_ = new scg::List(); - } base.AddRange(other.repeatedFixed32_, result.repeatedFixed32_); } if (other.repeatedFixed64_.Count != 0) { - if (result.repeatedFixed64_.Count == 0) { - result.repeatedFixed64_ = new scg::List(); - } base.AddRange(other.repeatedFixed64_, result.repeatedFixed64_); } if (other.repeatedSfixed32_.Count != 0) { - if (result.repeatedSfixed32_.Count == 0) { - result.repeatedSfixed32_ = new scg::List(); - } base.AddRange(other.repeatedSfixed32_, result.repeatedSfixed32_); } if (other.repeatedSfixed64_.Count != 0) { - if (result.repeatedSfixed64_.Count == 0) { - result.repeatedSfixed64_ = new scg::List(); - } base.AddRange(other.repeatedSfixed64_, result.repeatedSfixed64_); } if (other.repeatedFloat_.Count != 0) { - if (result.repeatedFloat_.Count == 0) { - result.repeatedFloat_ = new scg::List(); - } base.AddRange(other.repeatedFloat_, result.repeatedFloat_); } if (other.repeatedDouble_.Count != 0) { - if (result.repeatedDouble_.Count == 0) { - result.repeatedDouble_ = new scg::List(); - } base.AddRange(other.repeatedDouble_, result.repeatedDouble_); } if (other.repeatedBool_.Count != 0) { - if (result.repeatedBool_.Count == 0) { - result.repeatedBool_ = new scg::List(); - } base.AddRange(other.repeatedBool_, result.repeatedBool_); } if (other.repeatedString_.Count != 0) { - if (result.repeatedString_.Count == 0) { - result.repeatedString_ = new scg::List(); - } base.AddRange(other.repeatedString_, result.repeatedString_); } if (other.repeatedBytes_.Count != 0) { - if (result.repeatedBytes_.Count == 0) { - result.repeatedBytes_ = new scg::List(); - } base.AddRange(other.repeatedBytes_, result.repeatedBytes_); } if (other.repeatedGroup_.Count != 0) { - if (result.repeatedGroup_.Count == 0) { - result.repeatedGroup_ = new scg::List(); - } base.AddRange(other.repeatedGroup_, result.repeatedGroup_); } if (other.repeatedNestedMessage_.Count != 0) { - if (result.repeatedNestedMessage_.Count == 0) { - result.repeatedNestedMessage_ = new scg::List(); - } base.AddRange(other.repeatedNestedMessage_, result.repeatedNestedMessage_); } if (other.repeatedForeignMessage_.Count != 0) { - if (result.repeatedForeignMessage_.Count == 0) { - result.repeatedForeignMessage_ = new scg::List(); - } base.AddRange(other.repeatedForeignMessage_, result.repeatedForeignMessage_); } if (other.repeatedImportMessage_.Count != 0) { - if (result.repeatedImportMessage_.Count == 0) { - result.repeatedImportMessage_ = new scg::List(); - } base.AddRange(other.repeatedImportMessage_, result.repeatedImportMessage_); } if (other.repeatedNestedEnum_.Count != 0) { @@ -3126,15 +3061,9 @@ namespace Google.ProtocolBuffers.TestProtos { base.AddRange(other.repeatedImportEnum_, result.repeatedImportEnum_); } if (other.repeatedStringPiece_.Count != 0) { - if (result.repeatedStringPiece_.Count == 0) { - result.repeatedStringPiece_ = new scg::List(); - } base.AddRange(other.repeatedStringPiece_, result.repeatedStringPiece_); } if (other.repeatedCord_.Count != 0) { - if (result.repeatedCord_.Count == 0) { - result.repeatedCord_ = new scg::List(); - } base.AddRange(other.repeatedCord_, result.repeatedCord_); } if (other.HasDefaultInt32) { @@ -4097,7 +4026,7 @@ namespace Google.ProtocolBuffers.TestProtos { // repeated int32 repeated_int32 = 31; public scg::IList RepeatedInt32List { - get { return pbc::Lists.AsReadOnly(result.repeatedInt32_); } + get { return result.repeatedInt32_; } } public int RepeatedInt32Count { get { return result.RepeatedInt32Count; } @@ -4110,27 +4039,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedInt32(int value) { - if (result.repeatedInt32_.Count == 0) { - result.repeatedInt32_ = new scg::List(); - } result.repeatedInt32_.Add(value); return this; } public Builder AddRangeRepeatedInt32(scg::IEnumerable values) { - if (result.repeatedInt32_.Count == 0) { - result.repeatedInt32_ = new scg::List(); - } base.AddRange(values, result.repeatedInt32_); return this; } public Builder ClearRepeatedInt32() { - result.repeatedInt32_ = pbc::Lists.Empty; + result.repeatedInt32_.Clear(); return this; } // repeated int64 repeated_int64 = 32; public scg::IList RepeatedInt64List { - get { return pbc::Lists.AsReadOnly(result.repeatedInt64_); } + get { return result.repeatedInt64_; } } public int RepeatedInt64Count { get { return result.RepeatedInt64Count; } @@ -4143,27 +4066,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedInt64(long value) { - if (result.repeatedInt64_.Count == 0) { - result.repeatedInt64_ = new scg::List(); - } result.repeatedInt64_.Add(value); return this; } public Builder AddRangeRepeatedInt64(scg::IEnumerable values) { - if (result.repeatedInt64_.Count == 0) { - result.repeatedInt64_ = new scg::List(); - } base.AddRange(values, result.repeatedInt64_); return this; } public Builder ClearRepeatedInt64() { - result.repeatedInt64_ = pbc::Lists.Empty; + result.repeatedInt64_.Clear(); return this; } // repeated uint32 repeated_uint32 = 33; public scg::IList RepeatedUint32List { - get { return pbc::Lists.AsReadOnly(result.repeatedUint32_); } + get { return result.repeatedUint32_; } } public int RepeatedUint32Count { get { return result.RepeatedUint32Count; } @@ -4176,27 +4093,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedUint32(uint value) { - if (result.repeatedUint32_.Count == 0) { - result.repeatedUint32_ = new scg::List(); - } result.repeatedUint32_.Add(value); return this; } public Builder AddRangeRepeatedUint32(scg::IEnumerable values) { - if (result.repeatedUint32_.Count == 0) { - result.repeatedUint32_ = new scg::List(); - } base.AddRange(values, result.repeatedUint32_); return this; } public Builder ClearRepeatedUint32() { - result.repeatedUint32_ = pbc::Lists.Empty; + result.repeatedUint32_.Clear(); return this; } // repeated uint64 repeated_uint64 = 34; public scg::IList RepeatedUint64List { - get { return pbc::Lists.AsReadOnly(result.repeatedUint64_); } + get { return result.repeatedUint64_; } } public int RepeatedUint64Count { get { return result.RepeatedUint64Count; } @@ -4209,27 +4120,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedUint64(ulong value) { - if (result.repeatedUint64_.Count == 0) { - result.repeatedUint64_ = new scg::List(); - } result.repeatedUint64_.Add(value); return this; } public Builder AddRangeRepeatedUint64(scg::IEnumerable values) { - if (result.repeatedUint64_.Count == 0) { - result.repeatedUint64_ = new scg::List(); - } base.AddRange(values, result.repeatedUint64_); return this; } public Builder ClearRepeatedUint64() { - result.repeatedUint64_ = pbc::Lists.Empty; + result.repeatedUint64_.Clear(); return this; } // repeated sint32 repeated_sint32 = 35; public scg::IList RepeatedSint32List { - get { return pbc::Lists.AsReadOnly(result.repeatedSint32_); } + get { return result.repeatedSint32_; } } public int RepeatedSint32Count { get { return result.RepeatedSint32Count; } @@ -4242,27 +4147,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedSint32(int value) { - if (result.repeatedSint32_.Count == 0) { - result.repeatedSint32_ = new scg::List(); - } result.repeatedSint32_.Add(value); return this; } public Builder AddRangeRepeatedSint32(scg::IEnumerable values) { - if (result.repeatedSint32_.Count == 0) { - result.repeatedSint32_ = new scg::List(); - } base.AddRange(values, result.repeatedSint32_); return this; } public Builder ClearRepeatedSint32() { - result.repeatedSint32_ = pbc::Lists.Empty; + result.repeatedSint32_.Clear(); return this; } // repeated sint64 repeated_sint64 = 36; public scg::IList RepeatedSint64List { - get { return pbc::Lists.AsReadOnly(result.repeatedSint64_); } + get { return result.repeatedSint64_; } } public int RepeatedSint64Count { get { return result.RepeatedSint64Count; } @@ -4275,27 +4174,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedSint64(long value) { - if (result.repeatedSint64_.Count == 0) { - result.repeatedSint64_ = new scg::List(); - } result.repeatedSint64_.Add(value); return this; } public Builder AddRangeRepeatedSint64(scg::IEnumerable values) { - if (result.repeatedSint64_.Count == 0) { - result.repeatedSint64_ = new scg::List(); - } base.AddRange(values, result.repeatedSint64_); return this; } public Builder ClearRepeatedSint64() { - result.repeatedSint64_ = pbc::Lists.Empty; + result.repeatedSint64_.Clear(); return this; } // repeated fixed32 repeated_fixed32 = 37; public scg::IList RepeatedFixed32List { - get { return pbc::Lists.AsReadOnly(result.repeatedFixed32_); } + get { return result.repeatedFixed32_; } } public int RepeatedFixed32Count { get { return result.RepeatedFixed32Count; } @@ -4308,27 +4201,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedFixed32(uint value) { - if (result.repeatedFixed32_.Count == 0) { - result.repeatedFixed32_ = new scg::List(); - } result.repeatedFixed32_.Add(value); return this; } public Builder AddRangeRepeatedFixed32(scg::IEnumerable values) { - if (result.repeatedFixed32_.Count == 0) { - result.repeatedFixed32_ = new scg::List(); - } base.AddRange(values, result.repeatedFixed32_); return this; } public Builder ClearRepeatedFixed32() { - result.repeatedFixed32_ = pbc::Lists.Empty; + result.repeatedFixed32_.Clear(); return this; } // repeated fixed64 repeated_fixed64 = 38; public scg::IList RepeatedFixed64List { - get { return pbc::Lists.AsReadOnly(result.repeatedFixed64_); } + get { return result.repeatedFixed64_; } } public int RepeatedFixed64Count { get { return result.RepeatedFixed64Count; } @@ -4341,27 +4228,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedFixed64(ulong value) { - if (result.repeatedFixed64_.Count == 0) { - result.repeatedFixed64_ = new scg::List(); - } result.repeatedFixed64_.Add(value); return this; } public Builder AddRangeRepeatedFixed64(scg::IEnumerable values) { - if (result.repeatedFixed64_.Count == 0) { - result.repeatedFixed64_ = new scg::List(); - } base.AddRange(values, result.repeatedFixed64_); return this; } public Builder ClearRepeatedFixed64() { - result.repeatedFixed64_ = pbc::Lists.Empty; + result.repeatedFixed64_.Clear(); return this; } // repeated sfixed32 repeated_sfixed32 = 39; public scg::IList RepeatedSfixed32List { - get { return pbc::Lists.AsReadOnly(result.repeatedSfixed32_); } + get { return result.repeatedSfixed32_; } } public int RepeatedSfixed32Count { get { return result.RepeatedSfixed32Count; } @@ -4374,27 +4255,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedSfixed32(int value) { - if (result.repeatedSfixed32_.Count == 0) { - result.repeatedSfixed32_ = new scg::List(); - } result.repeatedSfixed32_.Add(value); return this; } public Builder AddRangeRepeatedSfixed32(scg::IEnumerable values) { - if (result.repeatedSfixed32_.Count == 0) { - result.repeatedSfixed32_ = new scg::List(); - } base.AddRange(values, result.repeatedSfixed32_); return this; } public Builder ClearRepeatedSfixed32() { - result.repeatedSfixed32_ = pbc::Lists.Empty; + result.repeatedSfixed32_.Clear(); return this; } // repeated sfixed64 repeated_sfixed64 = 40; public scg::IList RepeatedSfixed64List { - get { return pbc::Lists.AsReadOnly(result.repeatedSfixed64_); } + get { return result.repeatedSfixed64_; } } public int RepeatedSfixed64Count { get { return result.RepeatedSfixed64Count; } @@ -4407,27 +4282,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedSfixed64(long value) { - if (result.repeatedSfixed64_.Count == 0) { - result.repeatedSfixed64_ = new scg::List(); - } result.repeatedSfixed64_.Add(value); return this; } public Builder AddRangeRepeatedSfixed64(scg::IEnumerable values) { - if (result.repeatedSfixed64_.Count == 0) { - result.repeatedSfixed64_ = new scg::List(); - } base.AddRange(values, result.repeatedSfixed64_); return this; } public Builder ClearRepeatedSfixed64() { - result.repeatedSfixed64_ = pbc::Lists.Empty; + result.repeatedSfixed64_.Clear(); return this; } // repeated float repeated_float = 41; public scg::IList RepeatedFloatList { - get { return pbc::Lists.AsReadOnly(result.repeatedFloat_); } + get { return result.repeatedFloat_; } } public int RepeatedFloatCount { get { return result.RepeatedFloatCount; } @@ -4440,27 +4309,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedFloat(float value) { - if (result.repeatedFloat_.Count == 0) { - result.repeatedFloat_ = new scg::List(); - } result.repeatedFloat_.Add(value); return this; } public Builder AddRangeRepeatedFloat(scg::IEnumerable values) { - if (result.repeatedFloat_.Count == 0) { - result.repeatedFloat_ = new scg::List(); - } base.AddRange(values, result.repeatedFloat_); return this; } public Builder ClearRepeatedFloat() { - result.repeatedFloat_ = pbc::Lists.Empty; + result.repeatedFloat_.Clear(); return this; } // repeated double repeated_double = 42; public scg::IList RepeatedDoubleList { - get { return pbc::Lists.AsReadOnly(result.repeatedDouble_); } + get { return result.repeatedDouble_; } } public int RepeatedDoubleCount { get { return result.RepeatedDoubleCount; } @@ -4473,27 +4336,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedDouble(double value) { - if (result.repeatedDouble_.Count == 0) { - result.repeatedDouble_ = new scg::List(); - } result.repeatedDouble_.Add(value); return this; } public Builder AddRangeRepeatedDouble(scg::IEnumerable values) { - if (result.repeatedDouble_.Count == 0) { - result.repeatedDouble_ = new scg::List(); - } base.AddRange(values, result.repeatedDouble_); return this; } public Builder ClearRepeatedDouble() { - result.repeatedDouble_ = pbc::Lists.Empty; + result.repeatedDouble_.Clear(); return this; } // repeated bool repeated_bool = 43; public scg::IList RepeatedBoolList { - get { return pbc::Lists.AsReadOnly(result.repeatedBool_); } + get { return result.repeatedBool_; } } public int RepeatedBoolCount { get { return result.RepeatedBoolCount; } @@ -4506,27 +4363,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedBool(bool value) { - if (result.repeatedBool_.Count == 0) { - result.repeatedBool_ = new scg::List(); - } result.repeatedBool_.Add(value); return this; } public Builder AddRangeRepeatedBool(scg::IEnumerable values) { - if (result.repeatedBool_.Count == 0) { - result.repeatedBool_ = new scg::List(); - } base.AddRange(values, result.repeatedBool_); return this; } public Builder ClearRepeatedBool() { - result.repeatedBool_ = pbc::Lists.Empty; + result.repeatedBool_.Clear(); return this; } // repeated string repeated_string = 44; public scg::IList RepeatedStringList { - get { return pbc::Lists.AsReadOnly(result.repeatedString_); } + get { return result.repeatedString_; } } public int RepeatedStringCount { get { return result.RepeatedStringCount; } @@ -4539,27 +4390,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedString(string value) { - if (result.repeatedString_.Count == 0) { - result.repeatedString_ = new scg::List(); - } result.repeatedString_.Add(value); return this; } public Builder AddRangeRepeatedString(scg::IEnumerable values) { - if (result.repeatedString_.Count == 0) { - result.repeatedString_ = new scg::List(); - } base.AddRange(values, result.repeatedString_); return this; } public Builder ClearRepeatedString() { - result.repeatedString_ = pbc::Lists.Empty; + result.repeatedString_.Clear(); return this; } // repeated bytes repeated_bytes = 45; public scg::IList RepeatedBytesList { - get { return pbc::Lists.AsReadOnly(result.repeatedBytes_); } + get { return result.repeatedBytes_; } } public int RepeatedBytesCount { get { return result.RepeatedBytesCount; } @@ -4572,27 +4417,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedBytes(pb::ByteString value) { - if (result.repeatedBytes_.Count == 0) { - result.repeatedBytes_ = new scg::List(); - } result.repeatedBytes_.Add(value); return this; } public Builder AddRangeRepeatedBytes(scg::IEnumerable values) { - if (result.repeatedBytes_.Count == 0) { - result.repeatedBytes_ = new scg::List(); - } base.AddRange(values, result.repeatedBytes_); return this; } public Builder ClearRepeatedBytes() { - result.repeatedBytes_ = pbc::Lists.Empty; + result.repeatedBytes_.Clear(); return this; } // repeated group RepeatedGroup = 46 { public scg::IList RepeatedGroupList { - get { return pbc::Lists.AsReadOnly(result.repeatedGroup_); } + get { return result.repeatedGroup_; } } public int RepeatedGroupCount { get { return result.RepeatedGroupCount; } @@ -4609,34 +4448,25 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup value) { - if (result.repeatedGroup_ == pbc::Lists.Empty) { - result.repeatedGroup_ = new scg::List(); - } result.repeatedGroup_.Add(value); return this; } public Builder AddRepeatedGroup(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.RepeatedGroup.Builder builderForValue) { - if (result.repeatedGroup_ == pbc::Lists.Empty) { - result.repeatedGroup_ = new scg::List(); - } result.repeatedGroup_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedGroup(scg::IEnumerable values) { - if (result.repeatedGroup_ == pbc::Lists.Empty) { - result.repeatedGroup_ = new scg::List(); - } base.AddRange(values, result.repeatedGroup_); return this; } public Builder ClearRepeatedGroup() { - result.repeatedGroup_ = pbc::Lists.Empty; + result.repeatedGroup_.Clear(); return this; } // repeated .protobuf_unittest.TestAllTypes.NestedMessage repeated_nested_message = 48; public scg::IList RepeatedNestedMessageList { - get { return pbc::Lists.AsReadOnly(result.repeatedNestedMessage_); } + get { return result.repeatedNestedMessage_; } } public int RepeatedNestedMessageCount { get { return result.RepeatedNestedMessageCount; } @@ -4653,34 +4483,25 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage value) { - if (result.repeatedNestedMessage_ == pbc::Lists.Empty) { - result.repeatedNestedMessage_ = new scg::List(); - } result.repeatedNestedMessage_.Add(value); return this; } public Builder AddRepeatedNestedMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage.Builder builderForValue) { - if (result.repeatedNestedMessage_ == pbc::Lists.Empty) { - result.repeatedNestedMessage_ = new scg::List(); - } result.repeatedNestedMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedNestedMessage(scg::IEnumerable values) { - if (result.repeatedNestedMessage_ == pbc::Lists.Empty) { - result.repeatedNestedMessage_ = new scg::List(); - } base.AddRange(values, result.repeatedNestedMessage_); return this; } public Builder ClearRepeatedNestedMessage() { - result.repeatedNestedMessage_ = pbc::Lists.Empty; + result.repeatedNestedMessage_.Clear(); return this; } // repeated .protobuf_unittest.ForeignMessage repeated_foreign_message = 49; public scg::IList RepeatedForeignMessageList { - get { return pbc::Lists.AsReadOnly(result.repeatedForeignMessage_); } + get { return result.repeatedForeignMessage_; } } public int RepeatedForeignMessageCount { get { return result.RepeatedForeignMessageCount; } @@ -4697,34 +4518,25 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { - if (result.repeatedForeignMessage_ == pbc::Lists.Empty) { - result.repeatedForeignMessage_ = new scg::List(); - } result.repeatedForeignMessage_.Add(value); return this; } public Builder AddRepeatedForeignMessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { - if (result.repeatedForeignMessage_ == pbc::Lists.Empty) { - result.repeatedForeignMessage_ = new scg::List(); - } result.repeatedForeignMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedForeignMessage(scg::IEnumerable values) { - if (result.repeatedForeignMessage_ == pbc::Lists.Empty) { - result.repeatedForeignMessage_ = new scg::List(); - } base.AddRange(values, result.repeatedForeignMessage_); return this; } public Builder ClearRepeatedForeignMessage() { - result.repeatedForeignMessage_ = pbc::Lists.Empty; + result.repeatedForeignMessage_.Clear(); return this; } // repeated .protobuf_unittest_import.ImportMessage repeated_import_message = 50; public scg::IList RepeatedImportMessageList { - get { return pbc::Lists.AsReadOnly(result.repeatedImportMessage_); } + get { return result.repeatedImportMessage_; } } public int RepeatedImportMessageCount { get { return result.RepeatedImportMessageCount; } @@ -4741,28 +4553,19 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage value) { - if (result.repeatedImportMessage_ == pbc::Lists.Empty) { - result.repeatedImportMessage_ = new scg::List(); - } result.repeatedImportMessage_.Add(value); return this; } public Builder AddRepeatedImportMessage(global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder builderForValue) { - if (result.repeatedImportMessage_ == pbc::Lists.Empty) { - result.repeatedImportMessage_ = new scg::List(); - } result.repeatedImportMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedImportMessage(scg::IEnumerable values) { - if (result.repeatedImportMessage_ == pbc::Lists.Empty) { - result.repeatedImportMessage_ = new scg::List(); - } base.AddRange(values, result.repeatedImportMessage_); return this; } public Builder ClearRepeatedImportMessage() { - result.repeatedImportMessage_ = pbc::Lists.Empty; + result.repeatedImportMessage_.Clear(); return this; } @@ -4867,7 +4670,7 @@ namespace Google.ProtocolBuffers.TestProtos { // repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; public scg::IList RepeatedStringPieceList { - get { return pbc::Lists.AsReadOnly(result.repeatedStringPiece_); } + get { return result.repeatedStringPiece_; } } public int RepeatedStringPieceCount { get { return result.RepeatedStringPieceCount; } @@ -4880,27 +4683,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedStringPiece(string value) { - if (result.repeatedStringPiece_.Count == 0) { - result.repeatedStringPiece_ = new scg::List(); - } result.repeatedStringPiece_.Add(value); return this; } public Builder AddRangeRepeatedStringPiece(scg::IEnumerable values) { - if (result.repeatedStringPiece_.Count == 0) { - result.repeatedStringPiece_ = new scg::List(); - } base.AddRange(values, result.repeatedStringPiece_); return this; } public Builder ClearRepeatedStringPiece() { - result.repeatedStringPiece_ = pbc::Lists.Empty; + result.repeatedStringPiece_.Clear(); return this; } // repeated string repeated_cord = 55 [ctype = CORD]; public scg::IList RepeatedCordList { - get { return pbc::Lists.AsReadOnly(result.repeatedCord_); } + get { return result.repeatedCord_; } } public int RepeatedCordCount { get { return result.RepeatedCordCount; } @@ -4913,21 +4710,15 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedCord(string value) { - if (result.repeatedCord_.Count == 0) { - result.repeatedCord_ = new scg::List(); - } result.repeatedCord_.Add(value); return this; } public Builder AddRangeRepeatedCord(scg::IEnumerable values) { - if (result.repeatedCord_.Count == 0) { - result.repeatedCord_ = new scg::List(); - } base.AddRange(values, result.repeatedCord_); return this; } public Builder ClearRepeatedCord() { - result.repeatedCord_ = pbc::Lists.Empty; + result.repeatedCord_.Clear(); return this; } @@ -5314,7 +5105,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class ForeignMessage : pb::GeneratedMessage { - private static readonly ForeignMessage defaultInstance = new ForeignMessage(); + private static readonly ForeignMessage defaultInstance = new Builder().BuildPartial(); public static ForeignMessage DefaultInstance { get { return defaultInstance; } } @@ -5521,7 +5312,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestAllExtensions : pb::ExtendableMessage { - private static readonly TestAllExtensions defaultInstance = new TestAllExtensions(); + private static readonly TestAllExtensions defaultInstance = new Builder().BuildPartial(); public static TestAllExtensions DefaultInstance { get { return defaultInstance; } } @@ -5690,7 +5481,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class OptionalGroup_extension : pb::GeneratedMessage { - private static readonly OptionalGroup_extension defaultInstance = new OptionalGroup_extension(); + private static readonly OptionalGroup_extension defaultInstance = new Builder().BuildPartial(); public static OptionalGroup_extension DefaultInstance { get { return defaultInstance; } } @@ -5897,7 +5688,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class RepeatedGroup_extension : pb::GeneratedMessage { - private static readonly RepeatedGroup_extension defaultInstance = new RepeatedGroup_extension(); + private static readonly RepeatedGroup_extension defaultInstance = new Builder().BuildPartial(); public static RepeatedGroup_extension DefaultInstance { get { return defaultInstance; } } @@ -6104,7 +5895,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestRequired : pb::GeneratedMessage { - private static readonly TestRequired defaultInstance = new TestRequired(); + private static readonly TestRequired defaultInstance = new Builder().BuildPartial(); public static TestRequired DefaultInstance { get { return defaultInstance; } } @@ -7668,7 +7459,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestRequiredForeign : pb::GeneratedMessage { - private static readonly TestRequiredForeign defaultInstance = new TestRequiredForeign(); + private static readonly TestRequiredForeign defaultInstance = new Builder().BuildPartial(); public static TestRequiredForeign DefaultInstance { get { return defaultInstance; } } @@ -7700,7 +7491,7 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated .protobuf_unittest.TestRequired repeated_message = 2; - private scg::IList repeatedMessage_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedMessage_ = new pbc::PopsicleList(); public scg::IList RepeatedMessageList { get { return repeatedMessage_; } } @@ -7840,9 +7631,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public override global::Google.ProtocolBuffers.TestProtos.TestRequiredForeign BuildPartial() { - if (result.repeatedMessage_ != pbc::Lists.Empty) { - result.repeatedMessage_ = pbc::Lists.AsReadOnly(result.repeatedMessage_); - } + result.repeatedMessage_.MakeReadOnly(); global::Google.ProtocolBuffers.TestProtos.TestRequiredForeign returnMe = result; result = null; return returnMe; @@ -7863,9 +7652,6 @@ namespace Google.ProtocolBuffers.TestProtos { MergeOptionalMessage(other.OptionalMessage); } if (other.repeatedMessage_.Count != 0) { - if (result.repeatedMessage_.Count == 0) { - result.repeatedMessage_ = new scg::List(); - } base.AddRange(other.repeatedMessage_, result.repeatedMessage_); } if (other.HasDummy) { @@ -7957,7 +7743,7 @@ namespace Google.ProtocolBuffers.TestProtos { // repeated .protobuf_unittest.TestRequired repeated_message = 2; public scg::IList RepeatedMessageList { - get { return pbc::Lists.AsReadOnly(result.repeatedMessage_); } + get { return result.repeatedMessage_; } } public int RepeatedMessageCount { get { return result.RepeatedMessageCount; } @@ -7974,28 +7760,19 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired value) { - if (result.repeatedMessage_ == pbc::Lists.Empty) { - result.repeatedMessage_ = new scg::List(); - } result.repeatedMessage_.Add(value); return this; } public Builder AddRepeatedMessage(global::Google.ProtocolBuffers.TestProtos.TestRequired.Builder builderForValue) { - if (result.repeatedMessage_ == pbc::Lists.Empty) { - result.repeatedMessage_ = new scg::List(); - } result.repeatedMessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedMessage(scg::IEnumerable values) { - if (result.repeatedMessage_ == pbc::Lists.Empty) { - result.repeatedMessage_ = new scg::List(); - } base.AddRange(values, result.repeatedMessage_); return this; } public Builder ClearRepeatedMessage() { - result.repeatedMessage_ = pbc::Lists.Empty; + result.repeatedMessage_.Clear(); return this; } @@ -8021,7 +7798,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestForeignNested : pb::GeneratedMessage { - private static readonly TestForeignNested defaultInstance = new TestForeignNested(); + private static readonly TestForeignNested defaultInstance = new Builder().BuildPartial(); public static TestForeignNested DefaultInstance { get { return defaultInstance; } } @@ -8249,7 +8026,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestEmptyMessage : pb::GeneratedMessage { - private static readonly TestEmptyMessage defaultInstance = new TestEmptyMessage(); + private static readonly TestEmptyMessage defaultInstance = new Builder().BuildPartial(); public static TestEmptyMessage DefaultInstance { get { return defaultInstance; } } @@ -8414,7 +8191,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestEmptyMessageWithExtensions : pb::ExtendableMessage { - private static readonly TestEmptyMessageWithExtensions defaultInstance = new TestEmptyMessageWithExtensions(); + private static readonly TestEmptyMessageWithExtensions defaultInstance = new Builder().BuildPartial(); public static TestEmptyMessageWithExtensions DefaultInstance { get { return defaultInstance; } } @@ -8583,7 +8360,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestReallyLargeTagNumber : pb::GeneratedMessage { - private static readonly TestReallyLargeTagNumber defaultInstance = new TestReallyLargeTagNumber(); + private static readonly TestReallyLargeTagNumber defaultInstance = new Builder().BuildPartial(); public static TestReallyLargeTagNumber DefaultInstance { get { return defaultInstance; } } @@ -8832,7 +8609,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestRecursiveMessage : pb::GeneratedMessage { - private static readonly TestRecursiveMessage defaultInstance = new TestRecursiveMessage(); + private static readonly TestRecursiveMessage defaultInstance = new Builder().BuildPartial(); public static TestRecursiveMessage DefaultInstance { get { return defaultInstance; } } @@ -9102,7 +8879,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestMutualRecursionA : pb::GeneratedMessage { - private static readonly TestMutualRecursionA defaultInstance = new TestMutualRecursionA(); + private static readonly TestMutualRecursionA defaultInstance = new Builder().BuildPartial(); public static TestMutualRecursionA DefaultInstance { get { return defaultInstance; } } @@ -9330,7 +9107,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestMutualRecursionB : pb::GeneratedMessage { - private static readonly TestMutualRecursionB defaultInstance = new TestMutualRecursionB(); + private static readonly TestMutualRecursionB defaultInstance = new Builder().BuildPartial(); public static TestMutualRecursionB DefaultInstance { get { return defaultInstance; } } @@ -9600,7 +9377,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestDupFieldNumber : pb::GeneratedMessage { - private static readonly TestDupFieldNumber defaultInstance = new TestDupFieldNumber(); + private static readonly TestDupFieldNumber defaultInstance = new Builder().BuildPartial(); public static TestDupFieldNumber DefaultInstance { get { return defaultInstance; } } @@ -9624,7 +9401,7 @@ namespace Google.ProtocolBuffers.TestProtos { #region Nested types public static class Types { public sealed partial class Foo : pb::GeneratedMessage { - private static readonly Foo defaultInstance = new Foo(); + private static readonly Foo defaultInstance = new Builder().BuildPartial(); public static Foo DefaultInstance { get { return defaultInstance; } } @@ -9831,7 +9608,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class Bar : pb::GeneratedMessage { - private static readonly Bar defaultInstance = new Bar(); + private static readonly Bar defaultInstance = new Builder().BuildPartial(); public static Bar DefaultInstance { get { return defaultInstance; } } @@ -10352,7 +10129,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestNestedMessageHasBits : pb::GeneratedMessage { - private static readonly TestNestedMessageHasBits defaultInstance = new TestNestedMessageHasBits(); + private static readonly TestNestedMessageHasBits defaultInstance = new Builder().BuildPartial(); public static TestNestedMessageHasBits DefaultInstance { get { return defaultInstance; } } @@ -10376,7 +10153,7 @@ namespace Google.ProtocolBuffers.TestProtos { #region Nested types public static class Types { public sealed partial class NestedMessage : pb::GeneratedMessage { - private static readonly NestedMessage defaultInstance = new NestedMessage(); + private static readonly NestedMessage defaultInstance = new Builder().BuildPartial(); public static NestedMessage DefaultInstance { get { return defaultInstance; } } @@ -10398,9 +10175,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated int32 nestedmessage_repeated_int32 = 1; - private scg::IList nestedmessageRepeatedInt32_ = pbc::Lists.Empty; + private pbc::PopsicleList nestedmessageRepeatedInt32_ = new pbc::PopsicleList(); public scg::IList NestedmessageRepeatedInt32List { - get { return nestedmessageRepeatedInt32_; } + get { return nestedmessageRepeatedInt32_; } } public int NestedmessageRepeatedInt32Count { get { return nestedmessageRepeatedInt32_.Count; } @@ -10410,7 +10187,7 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated .protobuf_unittest.ForeignMessage nestedmessage_repeated_foreignmessage = 2; - private scg::IList nestedmessageRepeatedForeignmessage_ = pbc::Lists.Empty; + private pbc::PopsicleList nestedmessageRepeatedForeignmessage_ = new pbc::PopsicleList(); public scg::IList NestedmessageRepeatedForeignmessageList { get { return nestedmessageRepeatedForeignmessage_; } } @@ -10529,10 +10306,8 @@ namespace Google.ProtocolBuffers.TestProtos { } public override global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage BuildPartial() { - result.nestedmessageRepeatedInt32_ = pbc::Lists.AsReadOnly(result.nestedmessageRepeatedInt32_); - if (result.nestedmessageRepeatedForeignmessage_ != pbc::Lists.Empty) { - result.nestedmessageRepeatedForeignmessage_ = pbc::Lists.AsReadOnly(result.nestedmessageRepeatedForeignmessage_); - } + result.nestedmessageRepeatedInt32_.MakeReadOnly(); + result.nestedmessageRepeatedForeignmessage_.MakeReadOnly(); global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage returnMe = result; result = null; return returnMe; @@ -10550,15 +10325,9 @@ namespace Google.ProtocolBuffers.TestProtos { public override Builder MergeFrom(global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage other) { if (other == global::Google.ProtocolBuffers.TestProtos.TestNestedMessageHasBits.Types.NestedMessage.DefaultInstance) return this; if (other.nestedmessageRepeatedInt32_.Count != 0) { - if (result.nestedmessageRepeatedInt32_.Count == 0) { - result.nestedmessageRepeatedInt32_ = new scg::List(); - } base.AddRange(other.nestedmessageRepeatedInt32_, result.nestedmessageRepeatedInt32_); } if (other.nestedmessageRepeatedForeignmessage_.Count != 0) { - if (result.nestedmessageRepeatedForeignmessage_.Count == 0) { - result.nestedmessageRepeatedForeignmessage_ = new scg::List(); - } base.AddRange(other.nestedmessageRepeatedForeignmessage_, result.nestedmessageRepeatedForeignmessage_); } this.MergeUnknownFields(other.UnknownFields); @@ -10603,7 +10372,7 @@ namespace Google.ProtocolBuffers.TestProtos { // repeated int32 nestedmessage_repeated_int32 = 1; public scg::IList NestedmessageRepeatedInt32List { - get { return pbc::Lists.AsReadOnly(result.nestedmessageRepeatedInt32_); } + get { return result.nestedmessageRepeatedInt32_; } } public int NestedmessageRepeatedInt32Count { get { return result.NestedmessageRepeatedInt32Count; } @@ -10616,27 +10385,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddNestedmessageRepeatedInt32(int value) { - if (result.nestedmessageRepeatedInt32_.Count == 0) { - result.nestedmessageRepeatedInt32_ = new scg::List(); - } result.nestedmessageRepeatedInt32_.Add(value); return this; } public Builder AddRangeNestedmessageRepeatedInt32(scg::IEnumerable values) { - if (result.nestedmessageRepeatedInt32_.Count == 0) { - result.nestedmessageRepeatedInt32_ = new scg::List(); - } base.AddRange(values, result.nestedmessageRepeatedInt32_); return this; } public Builder ClearNestedmessageRepeatedInt32() { - result.nestedmessageRepeatedInt32_ = pbc::Lists.Empty; + result.nestedmessageRepeatedInt32_.Clear(); return this; } // repeated .protobuf_unittest.ForeignMessage nestedmessage_repeated_foreignmessage = 2; public scg::IList NestedmessageRepeatedForeignmessageList { - get { return pbc::Lists.AsReadOnly(result.nestedmessageRepeatedForeignmessage_); } + get { return result.nestedmessageRepeatedForeignmessage_; } } public int NestedmessageRepeatedForeignmessageCount { get { return result.NestedmessageRepeatedForeignmessageCount; } @@ -10653,28 +10416,19 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddNestedmessageRepeatedForeignmessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { - if (result.nestedmessageRepeatedForeignmessage_ == pbc::Lists.Empty) { - result.nestedmessageRepeatedForeignmessage_ = new scg::List(); - } result.nestedmessageRepeatedForeignmessage_.Add(value); return this; } public Builder AddNestedmessageRepeatedForeignmessage(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { - if (result.nestedmessageRepeatedForeignmessage_ == pbc::Lists.Empty) { - result.nestedmessageRepeatedForeignmessage_ = new scg::List(); - } result.nestedmessageRepeatedForeignmessage_.Add(builderForValue.Build()); return this; } public Builder AddRangeNestedmessageRepeatedForeignmessage(scg::IEnumerable values) { - if (result.nestedmessageRepeatedForeignmessage_ == pbc::Lists.Empty) { - result.nestedmessageRepeatedForeignmessage_ = new scg::List(); - } base.AddRange(values, result.nestedmessageRepeatedForeignmessage_); return this; } public Builder ClearNestedmessageRepeatedForeignmessage() { - result.nestedmessageRepeatedForeignmessage_ = pbc::Lists.Empty; + result.nestedmessageRepeatedForeignmessage_.Clear(); return this; } } @@ -10890,7 +10644,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestCamelCaseFieldNames : pb::GeneratedMessage { - private static readonly TestCamelCaseFieldNames defaultInstance = new TestCamelCaseFieldNames(); + private static readonly TestCamelCaseFieldNames defaultInstance = new Builder().BuildPartial(); public static TestCamelCaseFieldNames DefaultInstance { get { return defaultInstance; } } @@ -10970,9 +10724,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated int32 RepeatedPrimitiveField = 7; - private scg::IList repeatedPrimitiveField_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedPrimitiveField_ = new pbc::PopsicleList(); public scg::IList RepeatedPrimitiveFieldList { - get { return repeatedPrimitiveField_; } + get { return repeatedPrimitiveField_; } } public int RepeatedPrimitiveFieldCount { get { return repeatedPrimitiveField_.Count; } @@ -10982,9 +10736,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated string RepeatedStringField = 8; - private scg::IList repeatedStringField_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedStringField_ = new pbc::PopsicleList(); public scg::IList RepeatedStringFieldList { - get { return repeatedStringField_; } + get { return repeatedStringField_; } } public int RepeatedStringFieldCount { get { return repeatedStringField_.Count; } @@ -11006,7 +10760,7 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated .protobuf_unittest.ForeignMessage RepeatedMessageField = 10; - private scg::IList repeatedMessageField_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedMessageField_ = new pbc::PopsicleList(); public scg::IList RepeatedMessageFieldList { get { return repeatedMessageField_; } } @@ -11018,9 +10772,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated string RepeatedStringPieceField = 11 [ctype = STRING_PIECE]; - private scg::IList repeatedStringPieceField_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedStringPieceField_ = new pbc::PopsicleList(); public scg::IList RepeatedStringPieceFieldList { - get { return repeatedStringPieceField_; } + get { return repeatedStringPieceField_; } } public int RepeatedStringPieceFieldCount { get { return repeatedStringPieceField_.Count; } @@ -11030,9 +10784,9 @@ namespace Google.ProtocolBuffers.TestProtos { } // repeated string RepeatedCordField = 12 [ctype = CORD]; - private scg::IList repeatedCordField_ = pbc::Lists.Empty; + private pbc::PopsicleList repeatedCordField_ = new pbc::PopsicleList(); public scg::IList RepeatedCordFieldList { - get { return repeatedCordField_; } + get { return repeatedCordField_; } } public int RepeatedCordFieldCount { get { return repeatedCordField_.Count; } @@ -11214,14 +10968,12 @@ namespace Google.ProtocolBuffers.TestProtos { } public override global::Google.ProtocolBuffers.TestProtos.TestCamelCaseFieldNames BuildPartial() { - result.repeatedPrimitiveField_ = pbc::Lists.AsReadOnly(result.repeatedPrimitiveField_); - result.repeatedStringField_ = pbc::Lists.AsReadOnly(result.repeatedStringField_); + result.repeatedPrimitiveField_.MakeReadOnly(); + result.repeatedStringField_.MakeReadOnly(); result.repeatedEnumField_ = pbc::Lists.AsReadOnly(result.repeatedEnumField_); - if (result.repeatedMessageField_ != pbc::Lists.Empty) { - result.repeatedMessageField_ = pbc::Lists.AsReadOnly(result.repeatedMessageField_); - } - result.repeatedStringPieceField_ = pbc::Lists.AsReadOnly(result.repeatedStringPieceField_); - result.repeatedCordField_ = pbc::Lists.AsReadOnly(result.repeatedCordField_); + result.repeatedMessageField_.MakeReadOnly(); + result.repeatedStringPieceField_.MakeReadOnly(); + result.repeatedCordField_.MakeReadOnly(); global::Google.ProtocolBuffers.TestProtos.TestCamelCaseFieldNames returnMe = result; result = null; return returnMe; @@ -11257,15 +11009,9 @@ namespace Google.ProtocolBuffers.TestProtos { CordField = other.CordField; } if (other.repeatedPrimitiveField_.Count != 0) { - if (result.repeatedPrimitiveField_.Count == 0) { - result.repeatedPrimitiveField_ = new scg::List(); - } base.AddRange(other.repeatedPrimitiveField_, result.repeatedPrimitiveField_); } if (other.repeatedStringField_.Count != 0) { - if (result.repeatedStringField_.Count == 0) { - result.repeatedStringField_ = new scg::List(); - } base.AddRange(other.repeatedStringField_, result.repeatedStringField_); } if (other.repeatedEnumField_.Count != 0) { @@ -11275,21 +11021,12 @@ namespace Google.ProtocolBuffers.TestProtos { base.AddRange(other.repeatedEnumField_, result.repeatedEnumField_); } if (other.repeatedMessageField_.Count != 0) { - if (result.repeatedMessageField_.Count == 0) { - result.repeatedMessageField_ = new scg::List(); - } base.AddRange(other.repeatedMessageField_, result.repeatedMessageField_); } if (other.repeatedStringPieceField_.Count != 0) { - if (result.repeatedStringPieceField_.Count == 0) { - result.repeatedStringPieceField_ = new scg::List(); - } base.AddRange(other.repeatedStringPieceField_, result.repeatedStringPieceField_); } if (other.repeatedCordField_.Count != 0) { - if (result.repeatedCordField_.Count == 0) { - result.repeatedCordField_ = new scg::List(); - } base.AddRange(other.repeatedCordField_, result.repeatedCordField_); } this.MergeUnknownFields(other.UnknownFields); @@ -11520,7 +11257,7 @@ namespace Google.ProtocolBuffers.TestProtos { // repeated int32 RepeatedPrimitiveField = 7; public scg::IList RepeatedPrimitiveFieldList { - get { return pbc::Lists.AsReadOnly(result.repeatedPrimitiveField_); } + get { return result.repeatedPrimitiveField_; } } public int RepeatedPrimitiveFieldCount { get { return result.RepeatedPrimitiveFieldCount; } @@ -11533,27 +11270,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedPrimitiveField(int value) { - if (result.repeatedPrimitiveField_.Count == 0) { - result.repeatedPrimitiveField_ = new scg::List(); - } result.repeatedPrimitiveField_.Add(value); return this; } public Builder AddRangeRepeatedPrimitiveField(scg::IEnumerable values) { - if (result.repeatedPrimitiveField_.Count == 0) { - result.repeatedPrimitiveField_ = new scg::List(); - } base.AddRange(values, result.repeatedPrimitiveField_); return this; } public Builder ClearRepeatedPrimitiveField() { - result.repeatedPrimitiveField_ = pbc::Lists.Empty; + result.repeatedPrimitiveField_.Clear(); return this; } // repeated string RepeatedStringField = 8; public scg::IList RepeatedStringFieldList { - get { return pbc::Lists.AsReadOnly(result.repeatedStringField_); } + get { return result.repeatedStringField_; } } public int RepeatedStringFieldCount { get { return result.RepeatedStringFieldCount; } @@ -11566,21 +11297,15 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedStringField(string value) { - if (result.repeatedStringField_.Count == 0) { - result.repeatedStringField_ = new scg::List(); - } result.repeatedStringField_.Add(value); return this; } public Builder AddRangeRepeatedStringField(scg::IEnumerable values) { - if (result.repeatedStringField_.Count == 0) { - result.repeatedStringField_ = new scg::List(); - } base.AddRange(values, result.repeatedStringField_); return this; } public Builder ClearRepeatedStringField() { - result.repeatedStringField_ = pbc::Lists.Empty; + result.repeatedStringField_.Clear(); return this; } @@ -11619,7 +11344,7 @@ namespace Google.ProtocolBuffers.TestProtos { // repeated .protobuf_unittest.ForeignMessage RepeatedMessageField = 10; public scg::IList RepeatedMessageFieldList { - get { return pbc::Lists.AsReadOnly(result.repeatedMessageField_); } + get { return result.repeatedMessageField_; } } public int RepeatedMessageFieldCount { get { return result.RepeatedMessageFieldCount; } @@ -11636,34 +11361,25 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) { - if (result.repeatedMessageField_ == pbc::Lists.Empty) { - result.repeatedMessageField_ = new scg::List(); - } result.repeatedMessageField_.Add(value); return this; } public Builder AddRepeatedMessageField(global::Google.ProtocolBuffers.TestProtos.ForeignMessage.Builder builderForValue) { - if (result.repeatedMessageField_ == pbc::Lists.Empty) { - result.repeatedMessageField_ = new scg::List(); - } result.repeatedMessageField_.Add(builderForValue.Build()); return this; } public Builder AddRangeRepeatedMessageField(scg::IEnumerable values) { - if (result.repeatedMessageField_ == pbc::Lists.Empty) { - result.repeatedMessageField_ = new scg::List(); - } base.AddRange(values, result.repeatedMessageField_); return this; } public Builder ClearRepeatedMessageField() { - result.repeatedMessageField_ = pbc::Lists.Empty; + result.repeatedMessageField_.Clear(); return this; } // repeated string RepeatedStringPieceField = 11 [ctype = STRING_PIECE]; public scg::IList RepeatedStringPieceFieldList { - get { return pbc::Lists.AsReadOnly(result.repeatedStringPieceField_); } + get { return result.repeatedStringPieceField_; } } public int RepeatedStringPieceFieldCount { get { return result.RepeatedStringPieceFieldCount; } @@ -11676,27 +11392,21 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedStringPieceField(string value) { - if (result.repeatedStringPieceField_.Count == 0) { - result.repeatedStringPieceField_ = new scg::List(); - } result.repeatedStringPieceField_.Add(value); return this; } public Builder AddRangeRepeatedStringPieceField(scg::IEnumerable values) { - if (result.repeatedStringPieceField_.Count == 0) { - result.repeatedStringPieceField_ = new scg::List(); - } base.AddRange(values, result.repeatedStringPieceField_); return this; } public Builder ClearRepeatedStringPieceField() { - result.repeatedStringPieceField_ = pbc::Lists.Empty; + result.repeatedStringPieceField_.Clear(); return this; } // repeated string RepeatedCordField = 12 [ctype = CORD]; public scg::IList RepeatedCordFieldList { - get { return pbc::Lists.AsReadOnly(result.repeatedCordField_); } + get { return result.repeatedCordField_; } } public int RepeatedCordFieldCount { get { return result.RepeatedCordFieldCount; } @@ -11709,28 +11419,22 @@ namespace Google.ProtocolBuffers.TestProtos { return this; } public Builder AddRepeatedCordField(string value) { - if (result.repeatedCordField_.Count == 0) { - result.repeatedCordField_ = new scg::List(); - } result.repeatedCordField_.Add(value); return this; } public Builder AddRangeRepeatedCordField(scg::IEnumerable values) { - if (result.repeatedCordField_.Count == 0) { - result.repeatedCordField_ = new scg::List(); - } base.AddRange(values, result.repeatedCordField_); return this; } public Builder ClearRepeatedCordField() { - result.repeatedCordField_ = pbc::Lists.Empty; + result.repeatedCordField_.Clear(); return this; } } } public sealed partial class TestFieldOrderings : pb::ExtendableMessage { - private static readonly TestFieldOrderings defaultInstance = new TestFieldOrderings(); + private static readonly TestFieldOrderings defaultInstance = new Builder().BuildPartial(); public static TestFieldOrderings DefaultInstance { get { return defaultInstance; } } @@ -12026,7 +11730,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class TestExtremeDefaultValues : pb::GeneratedMessage { - private static readonly TestExtremeDefaultValues defaultInstance = new TestExtremeDefaultValues(); + private static readonly TestExtremeDefaultValues defaultInstance = new Builder().BuildPartial(); public static TestExtremeDefaultValues DefaultInstance { get { return defaultInstance; } } @@ -12443,7 +12147,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class FooRequest : pb::GeneratedMessage { - private static readonly FooRequest defaultInstance = new FooRequest(); + private static readonly FooRequest defaultInstance = new Builder().BuildPartial(); public static FooRequest DefaultInstance { get { return defaultInstance; } } @@ -12608,7 +12312,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class FooResponse : pb::GeneratedMessage { - private static readonly FooResponse defaultInstance = new FooResponse(); + private static readonly FooResponse defaultInstance = new Builder().BuildPartial(); public static FooResponse DefaultInstance { get { return defaultInstance; } } @@ -12773,7 +12477,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class BarRequest : pb::GeneratedMessage { - private static readonly BarRequest defaultInstance = new BarRequest(); + private static readonly BarRequest defaultInstance = new Builder().BuildPartial(); public static BarRequest DefaultInstance { get { return defaultInstance; } } @@ -12938,7 +12642,7 @@ namespace Google.ProtocolBuffers.TestProtos { } public sealed partial class BarResponse : pb::GeneratedMessage { - private static readonly BarResponse defaultInstance = new BarResponse(); + private static readonly BarResponse defaultInstance = new Builder().BuildPartial(); public static BarResponse DefaultInstance { get { return defaultInstance; } } diff --git a/csharp/ProtocolBuffers/Collections/PopsicleList.cs b/csharp/ProtocolBuffers/Collections/PopsicleList.cs new file mode 100644 index 00000000..4efe13d0 --- /dev/null +++ b/csharp/ProtocolBuffers/Collections/PopsicleList.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Collections; + +namespace Google.ProtocolBuffers.Collections { + /// + /// Proxies calls to a , but allows the list + /// to be made read-only (with the method), + /// after which any modifying methods throw . + /// + public sealed class PopsicleList : IList { + + private readonly List items = new List(); + private bool readOnly = false; + + /// + /// Makes this list read-only ("freezes the popsicle"). From this + /// point on, mutating methods (Clear, Add etc) will throw a + /// NotSupportedException. There is no way of "defrosting" the list afterwards. + /// + public void MakeReadOnly() { + readOnly = true; + } + + public int IndexOf(T item) { + return items.IndexOf(item); + } + + public void Insert(int index, T item) { + ValidateModification(); + items.Insert(index, item); + } + + public void RemoveAt(int index) { + ValidateModification(); + items.RemoveAt(index); + } + + public T this[int index] { + get { + return items[index]; + } + set { + ValidateModification(); + items[index] = value; + } + } + + public void Add(T item) { + ValidateModification(); + items.Add(item); + } + + public void Clear() { + ValidateModification(); + items.Clear(); + } + + public bool Contains(T item) { + return items.Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) { + items.CopyTo(array, arrayIndex); + } + + public int Count { + get { return items.Count; } + } + + public bool IsReadOnly { + get { return readOnly; } + } + + public bool Remove(T item) { + ValidateModification(); + return items.Remove(item); + } + + public IEnumerator GetEnumerator() { + return items.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() { + return GetEnumerator(); + } + + private void ValidateModification() { + if (readOnly) { + throw new NotSupportedException("List is read-only"); + } + } + } +} diff --git a/csharp/ProtocolBuffers/Delegates.cs b/csharp/ProtocolBuffers/Delegates.cs index 2aa440b1..08774019 100644 --- a/csharp/ProtocolBuffers/Delegates.cs +++ b/csharp/ProtocolBuffers/Delegates.cs @@ -1,8 +1,32 @@ -using System.IO; -namespace Google.ProtocolBuffers { +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. +// http://code.google.com/p/protobuf/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using System.IO; +namespace Google.ProtocolBuffers { /// /// Delegate to return a stream when asked, used by MessageStreamIterator. /// public delegate Stream StreamProvider(); + + // These delegate declarations mirror the ones in .NET 3.5 for the sake of familiarity. + internal delegate TResult Func(); + internal delegate TResult Func(T arg); + internal delegate TResult Func(T1 arg1, T2 arg2); + internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); + internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4); + internal delegate void Action(); + internal delegate void Action(T1 arg1, T2 arg2); } diff --git a/csharp/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs b/csharp/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs index e42c36f3..488b0c60 100644 --- a/csharp/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs +++ b/csharp/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs @@ -255,7 +255,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { #region Messages public sealed partial class FileDescriptorSet : pb::GeneratedMessage { - private static readonly FileDescriptorSet defaultInstance = new FileDescriptorSet(); + private static readonly FileDescriptorSet defaultInstance = new Builder().BuildPartial(); public static FileDescriptorSet DefaultInstance { get { return defaultInstance; } } @@ -277,7 +277,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.FileDescriptorProto file = 1; - private scg::IList file_ = pbc::Lists.Empty; + private pbc::PopsicleList file_ = new pbc::PopsicleList(); public scg::IList FileList { get { return file_; } } @@ -389,9 +389,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorSet BuildPartial() { - if (result.file_ != pbc::Lists.Empty) { - result.file_ = pbc::Lists.AsReadOnly(result.file_); - } + result.file_.MakeReadOnly(); global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorSet returnMe = result; result = null; return returnMe; @@ -409,9 +407,6 @@ namespace Google.ProtocolBuffers.DescriptorProtos { public override Builder MergeFrom(global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorSet other) { if (other == global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorSet.DefaultInstance) return this; if (other.file_.Count != 0) { - if (result.file_.Count == 0) { - result.file_ = new scg::List(); - } base.AddRange(other.file_, result.file_); } this.MergeUnknownFields(other.UnknownFields); @@ -452,7 +447,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { // repeated .google.protobuf.FileDescriptorProto file = 1; public scg::IList FileList { - get { return pbc::Lists.AsReadOnly(result.file_); } + get { return result.file_; } } public int FileCount { get { return result.FileCount; } @@ -469,35 +464,26 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddFile(global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto value) { - if (result.file_ == pbc::Lists.Empty) { - result.file_ = new scg::List(); - } result.file_.Add(value); return this; } public Builder AddFile(global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto.Builder builderForValue) { - if (result.file_ == pbc::Lists.Empty) { - result.file_ = new scg::List(); - } result.file_.Add(builderForValue.Build()); return this; } public Builder AddRangeFile(scg::IEnumerable values) { - if (result.file_ == pbc::Lists.Empty) { - result.file_ = new scg::List(); - } base.AddRange(values, result.file_); return this; } public Builder ClearFile() { - result.file_ = pbc::Lists.Empty; + result.file_.Clear(); return this; } } } public sealed partial class FileDescriptorProto : pb::GeneratedMessage { - private static readonly FileDescriptorProto defaultInstance = new FileDescriptorProto(); + private static readonly FileDescriptorProto defaultInstance = new Builder().BuildPartial(); public static FileDescriptorProto DefaultInstance { get { return defaultInstance; } } @@ -539,9 +525,9 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated string dependency = 3; - private scg::IList dependency_ = pbc::Lists.Empty; + private pbc::PopsicleList dependency_ = new pbc::PopsicleList(); public scg::IList DependencyList { - get { return dependency_; } + get { return dependency_; } } public int DependencyCount { get { return dependency_.Count; } @@ -551,7 +537,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.DescriptorProto message_type = 4; - private scg::IList messageType_ = pbc::Lists.Empty; + private pbc::PopsicleList messageType_ = new pbc::PopsicleList(); public scg::IList MessageTypeList { get { return messageType_; } } @@ -563,7 +549,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; - private scg::IList enumType_ = pbc::Lists.Empty; + private pbc::PopsicleList enumType_ = new pbc::PopsicleList(); public scg::IList EnumTypeList { get { return enumType_; } } @@ -575,7 +561,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.ServiceDescriptorProto service = 6; - private scg::IList service_ = pbc::Lists.Empty; + private pbc::PopsicleList service_ = new pbc::PopsicleList(); public scg::IList ServiceList { get { return service_; } } @@ -587,7 +573,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.FieldDescriptorProto extension = 7; - private scg::IList extension_ = pbc::Lists.Empty; + private pbc::PopsicleList extension_ = new pbc::PopsicleList(); public scg::IList ExtensionList { get { return extension_; } } @@ -752,19 +738,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto BuildPartial() { - result.dependency_ = pbc::Lists.AsReadOnly(result.dependency_); - if (result.messageType_ != pbc::Lists.Empty) { - result.messageType_ = pbc::Lists.AsReadOnly(result.messageType_); - } - if (result.enumType_ != pbc::Lists.Empty) { - result.enumType_ = pbc::Lists.AsReadOnly(result.enumType_); - } - if (result.service_ != pbc::Lists.Empty) { - result.service_ = pbc::Lists.AsReadOnly(result.service_); - } - if (result.extension_ != pbc::Lists.Empty) { - result.extension_ = pbc::Lists.AsReadOnly(result.extension_); - } + result.dependency_.MakeReadOnly(); + result.messageType_.MakeReadOnly(); + result.enumType_.MakeReadOnly(); + result.service_.MakeReadOnly(); + result.extension_.MakeReadOnly(); global::Google.ProtocolBuffers.DescriptorProtos.FileDescriptorProto returnMe = result; result = null; return returnMe; @@ -788,33 +766,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos { Package = other.Package; } if (other.dependency_.Count != 0) { - if (result.dependency_.Count == 0) { - result.dependency_ = new scg::List(); - } base.AddRange(other.dependency_, result.dependency_); } if (other.messageType_.Count != 0) { - if (result.messageType_.Count == 0) { - result.messageType_ = new scg::List(); - } base.AddRange(other.messageType_, result.messageType_); } if (other.enumType_.Count != 0) { - if (result.enumType_.Count == 0) { - result.enumType_ = new scg::List(); - } base.AddRange(other.enumType_, result.enumType_); } if (other.service_.Count != 0) { - if (result.service_.Count == 0) { - result.service_ = new scg::List(); - } base.AddRange(other.service_, result.service_); } if (other.extension_.Count != 0) { - if (result.extension_.Count == 0) { - result.extension_ = new scg::List(); - } base.AddRange(other.extension_, result.extension_); } if (other.HasOptions) { @@ -935,7 +898,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { // repeated string dependency = 3; public scg::IList DependencyList { - get { return pbc::Lists.AsReadOnly(result.dependency_); } + get { return result.dependency_; } } public int DependencyCount { get { return result.DependencyCount; } @@ -948,27 +911,21 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddDependency(string value) { - if (result.dependency_.Count == 0) { - result.dependency_ = new scg::List(); - } result.dependency_.Add(value); return this; } public Builder AddRangeDependency(scg::IEnumerable values) { - if (result.dependency_.Count == 0) { - result.dependency_ = new scg::List(); - } base.AddRange(values, result.dependency_); return this; } public Builder ClearDependency() { - result.dependency_ = pbc::Lists.Empty; + result.dependency_.Clear(); return this; } // repeated .google.protobuf.DescriptorProto message_type = 4; public scg::IList MessageTypeList { - get { return pbc::Lists.AsReadOnly(result.messageType_); } + get { return result.messageType_; } } public int MessageTypeCount { get { return result.MessageTypeCount; } @@ -985,34 +942,25 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddMessageType(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto value) { - if (result.messageType_ == pbc::Lists.Empty) { - result.messageType_ = new scg::List(); - } result.messageType_.Add(value); return this; } public Builder AddMessageType(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Builder builderForValue) { - if (result.messageType_ == pbc::Lists.Empty) { - result.messageType_ = new scg::List(); - } result.messageType_.Add(builderForValue.Build()); return this; } public Builder AddRangeMessageType(scg::IEnumerable values) { - if (result.messageType_ == pbc::Lists.Empty) { - result.messageType_ = new scg::List(); - } base.AddRange(values, result.messageType_); return this; } public Builder ClearMessageType() { - result.messageType_ = pbc::Lists.Empty; + result.messageType_.Clear(); return this; } // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; public scg::IList EnumTypeList { - get { return pbc::Lists.AsReadOnly(result.enumType_); } + get { return result.enumType_; } } public int EnumTypeCount { get { return result.EnumTypeCount; } @@ -1029,34 +977,25 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddEnumType(global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto value) { - if (result.enumType_ == pbc::Lists.Empty) { - result.enumType_ = new scg::List(); - } result.enumType_.Add(value); return this; } public Builder AddEnumType(global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) { - if (result.enumType_ == pbc::Lists.Empty) { - result.enumType_ = new scg::List(); - } result.enumType_.Add(builderForValue.Build()); return this; } public Builder AddRangeEnumType(scg::IEnumerable values) { - if (result.enumType_ == pbc::Lists.Empty) { - result.enumType_ = new scg::List(); - } base.AddRange(values, result.enumType_); return this; } public Builder ClearEnumType() { - result.enumType_ = pbc::Lists.Empty; + result.enumType_.Clear(); return this; } // repeated .google.protobuf.ServiceDescriptorProto service = 6; public scg::IList ServiceList { - get { return pbc::Lists.AsReadOnly(result.service_); } + get { return result.service_; } } public int ServiceCount { get { return result.ServiceCount; } @@ -1073,34 +1012,25 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddService(global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto value) { - if (result.service_ == pbc::Lists.Empty) { - result.service_ = new scg::List(); - } result.service_.Add(value); return this; } public Builder AddService(global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto.Builder builderForValue) { - if (result.service_ == pbc::Lists.Empty) { - result.service_ = new scg::List(); - } result.service_.Add(builderForValue.Build()); return this; } public Builder AddRangeService(scg::IEnumerable values) { - if (result.service_ == pbc::Lists.Empty) { - result.service_ = new scg::List(); - } base.AddRange(values, result.service_); return this; } public Builder ClearService() { - result.service_ = pbc::Lists.Empty; + result.service_.Clear(); return this; } // repeated .google.protobuf.FieldDescriptorProto extension = 7; public scg::IList ExtensionList { - get { return pbc::Lists.AsReadOnly(result.extension_); } + get { return result.extension_; } } public int ExtensionCount { get { return result.ExtensionCount; } @@ -1117,28 +1047,19 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddExtension(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto value) { - if (result.extension_ == pbc::Lists.Empty) { - result.extension_ = new scg::List(); - } result.extension_.Add(value); return this; } public Builder AddExtension(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) { - if (result.extension_ == pbc::Lists.Empty) { - result.extension_ = new scg::List(); - } result.extension_.Add(builderForValue.Build()); return this; } public Builder AddRangeExtension(scg::IEnumerable values) { - if (result.extension_ == pbc::Lists.Empty) { - result.extension_ = new scg::List(); - } base.AddRange(values, result.extension_); return this; } public Builder ClearExtension() { - result.extension_ = pbc::Lists.Empty; + result.extension_.Clear(); return this; } @@ -1180,7 +1101,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class DescriptorProto : pb::GeneratedMessage { - private static readonly DescriptorProto defaultInstance = new DescriptorProto(); + private static readonly DescriptorProto defaultInstance = new Builder().BuildPartial(); public static DescriptorProto DefaultInstance { get { return defaultInstance; } } @@ -1204,7 +1125,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { #region Nested types public static class Types { public sealed partial class ExtensionRange : pb::GeneratedMessage { - private static readonly ExtensionRange defaultInstance = new ExtensionRange(); + private static readonly ExtensionRange defaultInstance = new Builder().BuildPartial(); public static ExtensionRange DefaultInstance { get { return defaultInstance; } } @@ -1466,7 +1387,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.FieldDescriptorProto field = 2; - private scg::IList field_ = pbc::Lists.Empty; + private pbc::PopsicleList field_ = new pbc::PopsicleList(); public scg::IList FieldList { get { return field_; } } @@ -1478,7 +1399,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.FieldDescriptorProto extension = 6; - private scg::IList extension_ = pbc::Lists.Empty; + private pbc::PopsicleList extension_ = new pbc::PopsicleList(); public scg::IList ExtensionList { get { return extension_; } } @@ -1490,7 +1411,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.DescriptorProto nested_type = 3; - private scg::IList nestedType_ = pbc::Lists.Empty; + private pbc::PopsicleList nestedType_ = new pbc::PopsicleList(); public scg::IList NestedTypeList { get { return nestedType_; } } @@ -1502,7 +1423,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; - private scg::IList enumType_ = pbc::Lists.Empty; + private pbc::PopsicleList enumType_ = new pbc::PopsicleList(); public scg::IList EnumTypeList { get { return enumType_; } } @@ -1514,7 +1435,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; - private scg::IList extensionRange_ = pbc::Lists.Empty; + private pbc::PopsicleList extensionRange_ = new pbc::PopsicleList(); public scg::IList ExtensionRangeList { get { return extensionRange_; } } @@ -1672,21 +1593,11 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto BuildPartial() { - if (result.field_ != pbc::Lists.Empty) { - result.field_ = pbc::Lists.AsReadOnly(result.field_); - } - if (result.extension_ != pbc::Lists.Empty) { - result.extension_ = pbc::Lists.AsReadOnly(result.extension_); - } - if (result.nestedType_ != pbc::Lists.Empty) { - result.nestedType_ = pbc::Lists.AsReadOnly(result.nestedType_); - } - if (result.enumType_ != pbc::Lists.Empty) { - result.enumType_ = pbc::Lists.AsReadOnly(result.enumType_); - } - if (result.extensionRange_ != pbc::Lists.Empty) { - result.extensionRange_ = pbc::Lists.AsReadOnly(result.extensionRange_); - } + result.field_.MakeReadOnly(); + result.extension_.MakeReadOnly(); + result.nestedType_.MakeReadOnly(); + result.enumType_.MakeReadOnly(); + result.extensionRange_.MakeReadOnly(); global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto returnMe = result; result = null; return returnMe; @@ -1707,33 +1618,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos { Name = other.Name; } if (other.field_.Count != 0) { - if (result.field_.Count == 0) { - result.field_ = new scg::List(); - } base.AddRange(other.field_, result.field_); } if (other.extension_.Count != 0) { - if (result.extension_.Count == 0) { - result.extension_ = new scg::List(); - } base.AddRange(other.extension_, result.extension_); } if (other.nestedType_.Count != 0) { - if (result.nestedType_.Count == 0) { - result.nestedType_ = new scg::List(); - } base.AddRange(other.nestedType_, result.nestedType_); } if (other.enumType_.Count != 0) { - if (result.enumType_.Count == 0) { - result.enumType_ = new scg::List(); - } base.AddRange(other.enumType_, result.enumType_); } if (other.extensionRange_.Count != 0) { - if (result.extensionRange_.Count == 0) { - result.extensionRange_ = new scg::List(); - } base.AddRange(other.extensionRange_, result.extensionRange_); } if (other.HasOptions) { @@ -1833,7 +1729,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { // repeated .google.protobuf.FieldDescriptorProto field = 2; public scg::IList FieldList { - get { return pbc::Lists.AsReadOnly(result.field_); } + get { return result.field_; } } public int FieldCount { get { return result.FieldCount; } @@ -1850,34 +1746,25 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddField(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto value) { - if (result.field_ == pbc::Lists.Empty) { - result.field_ = new scg::List(); - } result.field_.Add(value); return this; } public Builder AddField(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) { - if (result.field_ == pbc::Lists.Empty) { - result.field_ = new scg::List(); - } result.field_.Add(builderForValue.Build()); return this; } public Builder AddRangeField(scg::IEnumerable values) { - if (result.field_ == pbc::Lists.Empty) { - result.field_ = new scg::List(); - } base.AddRange(values, result.field_); return this; } public Builder ClearField() { - result.field_ = pbc::Lists.Empty; + result.field_.Clear(); return this; } // repeated .google.protobuf.FieldDescriptorProto extension = 6; public scg::IList ExtensionList { - get { return pbc::Lists.AsReadOnly(result.extension_); } + get { return result.extension_; } } public int ExtensionCount { get { return result.ExtensionCount; } @@ -1894,34 +1781,25 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddExtension(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto value) { - if (result.extension_ == pbc::Lists.Empty) { - result.extension_ = new scg::List(); - } result.extension_.Add(value); return this; } public Builder AddExtension(global::Google.ProtocolBuffers.DescriptorProtos.FieldDescriptorProto.Builder builderForValue) { - if (result.extension_ == pbc::Lists.Empty) { - result.extension_ = new scg::List(); - } result.extension_.Add(builderForValue.Build()); return this; } public Builder AddRangeExtension(scg::IEnumerable values) { - if (result.extension_ == pbc::Lists.Empty) { - result.extension_ = new scg::List(); - } base.AddRange(values, result.extension_); return this; } public Builder ClearExtension() { - result.extension_ = pbc::Lists.Empty; + result.extension_.Clear(); return this; } // repeated .google.protobuf.DescriptorProto nested_type = 3; public scg::IList NestedTypeList { - get { return pbc::Lists.AsReadOnly(result.nestedType_); } + get { return result.nestedType_; } } public int NestedTypeCount { get { return result.NestedTypeCount; } @@ -1938,34 +1816,25 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddNestedType(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto value) { - if (result.nestedType_ == pbc::Lists.Empty) { - result.nestedType_ = new scg::List(); - } result.nestedType_.Add(value); return this; } public Builder AddNestedType(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Builder builderForValue) { - if (result.nestedType_ == pbc::Lists.Empty) { - result.nestedType_ = new scg::List(); - } result.nestedType_.Add(builderForValue.Build()); return this; } public Builder AddRangeNestedType(scg::IEnumerable values) { - if (result.nestedType_ == pbc::Lists.Empty) { - result.nestedType_ = new scg::List(); - } base.AddRange(values, result.nestedType_); return this; } public Builder ClearNestedType() { - result.nestedType_ = pbc::Lists.Empty; + result.nestedType_.Clear(); return this; } // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; public scg::IList EnumTypeList { - get { return pbc::Lists.AsReadOnly(result.enumType_); } + get { return result.enumType_; } } public int EnumTypeCount { get { return result.EnumTypeCount; } @@ -1982,34 +1851,25 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddEnumType(global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto value) { - if (result.enumType_ == pbc::Lists.Empty) { - result.enumType_ = new scg::List(); - } result.enumType_.Add(value); return this; } public Builder AddEnumType(global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto.Builder builderForValue) { - if (result.enumType_ == pbc::Lists.Empty) { - result.enumType_ = new scg::List(); - } result.enumType_.Add(builderForValue.Build()); return this; } public Builder AddRangeEnumType(scg::IEnumerable values) { - if (result.enumType_ == pbc::Lists.Empty) { - result.enumType_ = new scg::List(); - } base.AddRange(values, result.enumType_); return this; } public Builder ClearEnumType() { - result.enumType_ = pbc::Lists.Empty; + result.enumType_.Clear(); return this; } // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; public scg::IList ExtensionRangeList { - get { return pbc::Lists.AsReadOnly(result.extensionRange_); } + get { return result.extensionRange_; } } public int ExtensionRangeCount { get { return result.ExtensionRangeCount; } @@ -2026,28 +1886,19 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddExtensionRange(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange value) { - if (result.extensionRange_ == pbc::Lists.Empty) { - result.extensionRange_ = new scg::List(); - } result.extensionRange_.Add(value); return this; } public Builder AddExtensionRange(global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProto.Types.ExtensionRange.Builder builderForValue) { - if (result.extensionRange_ == pbc::Lists.Empty) { - result.extensionRange_ = new scg::List(); - } result.extensionRange_.Add(builderForValue.Build()); return this; } public Builder AddRangeExtensionRange(scg::IEnumerable values) { - if (result.extensionRange_ == pbc::Lists.Empty) { - result.extensionRange_ = new scg::List(); - } base.AddRange(values, result.extensionRange_); return this; } public Builder ClearExtensionRange() { - result.extensionRange_ = pbc::Lists.Empty; + result.extensionRange_.Clear(); return this; } @@ -2089,7 +1940,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class FieldDescriptorProto : pb::GeneratedMessage { - private static readonly FieldDescriptorProto defaultInstance = new FieldDescriptorProto(); + private static readonly FieldDescriptorProto defaultInstance = new Builder().BuildPartial(); public static FieldDescriptorProto DefaultInstance { get { return defaultInstance; } } @@ -2651,7 +2502,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class EnumDescriptorProto : pb::GeneratedMessage { - private static readonly EnumDescriptorProto defaultInstance = new EnumDescriptorProto(); + private static readonly EnumDescriptorProto defaultInstance = new Builder().BuildPartial(); public static EnumDescriptorProto DefaultInstance { get { return defaultInstance; } } @@ -2683,7 +2534,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.EnumValueDescriptorProto value = 2; - private scg::IList value_ = pbc::Lists.Empty; + private pbc::PopsicleList value_ = new pbc::PopsicleList(); public scg::IList ValueList { get { return value_; } } @@ -2817,9 +2668,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto BuildPartial() { - if (result.value_ != pbc::Lists.Empty) { - result.value_ = pbc::Lists.AsReadOnly(result.value_); - } + result.value_.MakeReadOnly(); global::Google.ProtocolBuffers.DescriptorProtos.EnumDescriptorProto returnMe = result; result = null; return returnMe; @@ -2840,9 +2689,6 @@ namespace Google.ProtocolBuffers.DescriptorProtos { Name = other.Name; } if (other.value_.Count != 0) { - if (result.value_.Count == 0) { - result.value_ = new scg::List(); - } base.AddRange(other.value_, result.value_); } if (other.HasOptions) { @@ -2918,7 +2764,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { // repeated .google.protobuf.EnumValueDescriptorProto value = 2; public scg::IList ValueList { - get { return pbc::Lists.AsReadOnly(result.value_); } + get { return result.value_; } } public int ValueCount { get { return result.ValueCount; } @@ -2935,28 +2781,19 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddValue(global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto value) { - if (result.value_ == pbc::Lists.Empty) { - result.value_ = new scg::List(); - } result.value_.Add(value); return this; } public Builder AddValue(global::Google.ProtocolBuffers.DescriptorProtos.EnumValueDescriptorProto.Builder builderForValue) { - if (result.value_ == pbc::Lists.Empty) { - result.value_ = new scg::List(); - } result.value_.Add(builderForValue.Build()); return this; } public Builder AddRangeValue(scg::IEnumerable values) { - if (result.value_ == pbc::Lists.Empty) { - result.value_ = new scg::List(); - } base.AddRange(values, result.value_); return this; } public Builder ClearValue() { - result.value_ = pbc::Lists.Empty; + result.value_.Clear(); return this; } @@ -2998,7 +2835,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class EnumValueDescriptorProto : pb::GeneratedMessage { - private static readonly EnumValueDescriptorProto defaultInstance = new EnumValueDescriptorProto(); + private static readonly EnumValueDescriptorProto defaultInstance = new Builder().BuildPartial(); public static EnumValueDescriptorProto DefaultInstance { get { return defaultInstance; } } @@ -3310,7 +3147,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class ServiceDescriptorProto : pb::GeneratedMessage { - private static readonly ServiceDescriptorProto defaultInstance = new ServiceDescriptorProto(); + private static readonly ServiceDescriptorProto defaultInstance = new Builder().BuildPartial(); public static ServiceDescriptorProto DefaultInstance { get { return defaultInstance; } } @@ -3342,7 +3179,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } // repeated .google.protobuf.MethodDescriptorProto method = 2; - private scg::IList method_ = pbc::Lists.Empty; + private pbc::PopsicleList method_ = new pbc::PopsicleList(); public scg::IList MethodList { get { return method_; } } @@ -3476,9 +3313,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public override global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto BuildPartial() { - if (result.method_ != pbc::Lists.Empty) { - result.method_ = pbc::Lists.AsReadOnly(result.method_); - } + result.method_.MakeReadOnly(); global::Google.ProtocolBuffers.DescriptorProtos.ServiceDescriptorProto returnMe = result; result = null; return returnMe; @@ -3499,9 +3334,6 @@ namespace Google.ProtocolBuffers.DescriptorProtos { Name = other.Name; } if (other.method_.Count != 0) { - if (result.method_.Count == 0) { - result.method_ = new scg::List(); - } base.AddRange(other.method_, result.method_); } if (other.HasOptions) { @@ -3577,7 +3409,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { // repeated .google.protobuf.MethodDescriptorProto method = 2; public scg::IList MethodList { - get { return pbc::Lists.AsReadOnly(result.method_); } + get { return result.method_; } } public int MethodCount { get { return result.MethodCount; } @@ -3594,28 +3426,19 @@ namespace Google.ProtocolBuffers.DescriptorProtos { return this; } public Builder AddMethod(global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto value) { - if (result.method_ == pbc::Lists.Empty) { - result.method_ = new scg::List(); - } result.method_.Add(value); return this; } public Builder AddMethod(global::Google.ProtocolBuffers.DescriptorProtos.MethodDescriptorProto.Builder builderForValue) { - if (result.method_ == pbc::Lists.Empty) { - result.method_ = new scg::List(); - } result.method_.Add(builderForValue.Build()); return this; } public Builder AddRangeMethod(scg::IEnumerable values) { - if (result.method_ == pbc::Lists.Empty) { - result.method_ = new scg::List(); - } base.AddRange(values, result.method_); return this; } public Builder ClearMethod() { - result.method_ = pbc::Lists.Empty; + result.method_.Clear(); return this; } @@ -3657,7 +3480,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class MethodDescriptorProto : pb::GeneratedMessage { - private static readonly MethodDescriptorProto defaultInstance = new MethodDescriptorProto(); + private static readonly MethodDescriptorProto defaultInstance = new Builder().BuildPartial(); public static MethodDescriptorProto DefaultInstance { get { return defaultInstance; } } @@ -4011,7 +3834,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class FileOptions : pb::GeneratedMessage { - private static readonly FileOptions defaultInstance = new FileOptions(); + private static readonly FileOptions defaultInstance = new Builder().BuildPartial(); public static FileOptions DefaultInstance { get { return defaultInstance; } } @@ -4568,7 +4391,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class MessageOptions : pb::GeneratedMessage { - private static readonly MessageOptions defaultInstance = new MessageOptions(); + private static readonly MessageOptions defaultInstance = new Builder().BuildPartial(); public static MessageOptions DefaultInstance { get { return defaultInstance; } } @@ -4775,7 +4598,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class FieldOptions : pb::GeneratedMessage { - private static readonly FieldOptions defaultInstance = new FieldOptions(); + private static readonly FieldOptions defaultInstance = new Builder().BuildPartial(); public static FieldOptions DefaultInstance { get { return defaultInstance; } } @@ -5038,7 +4861,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class EnumOptions : pb::GeneratedMessage { - private static readonly EnumOptions defaultInstance = new EnumOptions(); + private static readonly EnumOptions defaultInstance = new Builder().BuildPartial(); public static EnumOptions DefaultInstance { get { return defaultInstance; } } @@ -5203,7 +5026,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class EnumValueOptions : pb::GeneratedMessage { - private static readonly EnumValueOptions defaultInstance = new EnumValueOptions(); + private static readonly EnumValueOptions defaultInstance = new Builder().BuildPartial(); public static EnumValueOptions DefaultInstance { get { return defaultInstance; } } @@ -5368,7 +5191,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class ServiceOptions : pb::GeneratedMessage { - private static readonly ServiceOptions defaultInstance = new ServiceOptions(); + private static readonly ServiceOptions defaultInstance = new Builder().BuildPartial(); public static ServiceOptions DefaultInstance { get { return defaultInstance; } } @@ -5533,7 +5356,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos { } public sealed partial class MethodOptions : pb::GeneratedMessage { - private static readonly MethodOptions defaultInstance = new MethodOptions(); + private static readonly MethodOptions defaultInstance = new Builder().BuildPartial(); public static MethodOptions DefaultInstance { get { return defaultInstance; } } diff --git a/csharp/ProtocolBuffers/FieldAccess/Delegates.cs b/csharp/ProtocolBuffers/FieldAccess/Delegates.cs deleted file mode 100644 index 972961c6..00000000 --- a/csharp/ProtocolBuffers/FieldAccess/Delegates.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. -// http://code.google.com/p/protobuf/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace Google.ProtocolBuffers.FieldAccess { - - // These delegate declarations mirror the ones in .NET 3.5 for the sake of familiarity. - internal delegate TResult Func(); - internal delegate TResult Func(T arg); - internal delegate TResult Func(T1 arg1, T2 arg2); - internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); - internal delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4); - internal delegate void Action(T1 arg1, T2 arg2); -} diff --git a/csharp/ProtocolBuffers/MessageStreamIterator.cs b/csharp/ProtocolBuffers/MessageStreamIterator.cs index 4944e5ce..61dbf840 100644 --- a/csharp/ProtocolBuffers/MessageStreamIterator.cs +++ b/csharp/ProtocolBuffers/MessageStreamIterator.cs @@ -8,25 +8,67 @@ using System.Reflection; namespace Google.ProtocolBuffers { /// - /// Helper class to create MessageStreamIterators without explicitly specifying - /// the builder type. The concrete builder type is determined by reflection, based - /// on the message type. The reflection step looks for a CreateBuilder method - /// in the message type which is public and static, and uses the return type of that - /// method as the builder type. This will work for all generated messages, whether - /// optimised for size or speed. It won't work for dynamic messages. - /// - /// TODO(jonskeet): This also won't work for non-public protos :( - /// Pass in delegate to create a builder? + /// Iterates over data created using a . + /// Unlike MessageStreamWriter, this class is not usually constructed directly with + /// a stream; instead it is provided with a way of opening a stream when iteration + /// is started. The stream is closed when the iteration is completed or the enumerator + /// is disposed. (This occurs naturally when using foreach.) /// - public static class MessageStreamIterator { + public class MessageStreamIterator : IEnumerable + where TMessage : IMessage { + + private readonly StreamProvider streamProvider; + private readonly ExtensionRegistry extensionRegistry; + + /// + /// Delegate created via reflection trickery (once per type) to create a builder + /// and read a message from a CodedInputStream with it. Note that unlike in Java, + /// there's one static field per constructed type. + /// + private static readonly Func messageReader = BuildMessageReader(); + + /// + /// Any exception (within reason) thrown within messageReader is caught and rethrown in the constructor. + /// This makes life a lot simpler for the caller. + /// + private static Exception typeInitializationException; + + /// + /// Creates the delegate later used to read messages. This is only called once per type, but to + /// avoid exceptions occurring at confusing times, if this fails it will set typeInitializationException + /// to the appropriate error and return null. + /// + private static Func BuildMessageReader() { + try { + Type builderType = FindBuilderType(); + + // Yes, it's redundant to find this again, but it's only the once... + MethodInfo createBuilderMethod = typeof(TMessage).GetMethod("CreateBuilder", Type.EmptyTypes); + Delegate builderBuilder = Delegate.CreateDelegate( + typeof(Func<>).MakeGenericType(builderType), null, createBuilderMethod); - public static IEnumerable FromFile(string file) - where TMessage : IMessage { - return FromStreamProvider(() => File.OpenRead(file)); + MethodInfo buildMethod = typeof(MessageStreamIterator) + .GetMethod("BuildImpl", BindingFlags.Static | BindingFlags.NonPublic) + .MakeGenericMethod(typeof(TMessage), builderType); + + return (Func)Delegate.CreateDelegate( + typeof(Func), builderBuilder, buildMethod); + } catch (ArgumentException e) { + typeInitializationException = e; + } catch (InvalidOperationException e) { + typeInitializationException = e; + } catch (InvalidCastException e) { + // Can't see why this would happen, but best to know about it. + typeInitializationException = e; + } + return null; } - public static IEnumerable FromStreamProvider(StreamProvider streamProvider) - where TMessage : IMessage { + /// + /// Works out the builder type for TMessage, or throws an ArgumentException to explain why it can't. + /// This will check + /// + private static Type FindBuilderType() { MethodInfo createBuilderMethod = typeof(TMessage).GetMethod("CreateBuilder", Type.EmptyTypes); if (createBuilderMethod == null) { throw new ArgumentException("Message type " + typeof(TMessage).FullName + " has no CreateBuilder method."); @@ -35,68 +77,57 @@ namespace Google.ProtocolBuffers { throw new ArgumentException("CreateBuilder method in " + typeof(TMessage).FullName + " has void return type"); } Type builderType = createBuilderMethod.ReturnType; - if (builderType.GetConstructor(Type.EmptyTypes) == null) { - throw new ArgumentException("Builder type " + builderType.FullName + " has no public parameterless constructor."); - } Type messageInterface = typeof(IMessage<,>).MakeGenericType(typeof(TMessage), builderType); Type builderInterface = typeof(IBuilder<,>).MakeGenericType(typeof(TMessage), builderType); - if (Array.IndexOf(typeof (TMessage).GetInterfaces(), messageInterface) == -1) { + if (Array.IndexOf(typeof(TMessage).GetInterfaces(), messageInterface) == -1) { throw new ArgumentException("Message type " + typeof(TMessage) + " doesn't implement " + messageInterface.FullName); } if (Array.IndexOf(builderType.GetInterfaces(), builderInterface) == -1) { throw new ArgumentException("Builder type " + typeof(TMessage) + " doesn't implement " + builderInterface.FullName); } - Type iteratorType = typeof(MessageStreamIterator<,>).MakeGenericType(typeof(TMessage), builderType); - MethodInfo factoryMethod = iteratorType.GetMethod("FromStreamProvider", new Type[] { typeof(StreamProvider) }); - return (IEnumerable) factoryMethod.Invoke(null, new object[] { streamProvider }); + return builderType; } - } - /// - /// Iterates over data created using a . - /// Unlike MessageStreamWriter, this class is not usually constructed directly with - /// a stream; instead it is provided with a way of opening a stream when iteration - /// is started. The stream is closed when the iteration is completed or the enumerator - /// is disposed. (This occurs naturally when using foreach.) - /// This type is generic in both the message type and the builder type; if only the - /// iteration is required (i.e. just ) then the static - /// generic methods in the nongeneric class are more appropriate. - /// - public sealed class MessageStreamIterator : IEnumerable - where TMessage : IMessage - where TBuilder : IBuilder, new() { - - private readonly StreamProvider streamProvider; - private readonly ExtensionRegistry extensionRegistry; + /// + /// Method we'll use to build messageReader, with the first parameter fixed to TMessage.CreateBuilder. Note that we + /// have to introduce another type parameter (TMessage2) as we can't constrain TMessage for just a single method + /// (and we can't do it at the type level because we don't know TBuilder). However, by constraining TMessage2 + /// to not only implement IMessage appropriately but also to derive from TMessage2, we can avoid doing a cast + /// for every message; the implicit reference conversion will be fine. In practice, TMessage2 and TMessage will + /// be the same type when we construct the generic method by reflection. + /// + private static TMessage BuildImpl(Func builderBuilder, CodedInputStream input, ExtensionRegistry registry) + where TBuilder : IBuilder + where TMessage2 : TMessage, IMessage { + TBuilder builder = builderBuilder(); + input.ReadMessage(builder, registry); + return builder.Build(); + } + private static readonly uint ExpectedTag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited); private MessageStreamIterator(StreamProvider streamProvider, ExtensionRegistry extensionRegistry) { + if (messageReader == null) { + throw typeInitializationException; + } this.streamProvider = streamProvider; this.extensionRegistry = extensionRegistry; } /// - /// Creates an instance which opens the specified file when it begins - /// iterating. No extension registry is used when reading messages. + /// Creates a new instance which uses the same stream provider as this one, + /// but the specified extension registry. /// - public static MessageStreamIterator FromFile(string file) { - return new MessageStreamIterator(() => File.OpenRead(file), ExtensionRegistry.Empty); + public MessageStreamIterator WithExtensionRegistry(ExtensionRegistry newRegistry) { + return new MessageStreamIterator(streamProvider, newRegistry); } - /// - /// Creates an instance which calls the given delegate when it begins - /// iterating. No extension registry is used when reading messages. - /// - public static MessageStreamIterator FromStreamProvider(StreamProvider streamProvider) { - return new MessageStreamIterator(streamProvider, ExtensionRegistry.Empty); + public static MessageStreamIterator FromFile(string file) { + return new MessageStreamIterator(() => File.OpenRead(file), ExtensionRegistry.Empty); } - /// - /// Creates a new instance which uses the same stream provider as this one, - /// but the specified extension registry. - /// - public MessageStreamIterator WithExtensionRegistry(ExtensionRegistry newRegistry) { - return new MessageStreamIterator(streamProvider, newRegistry); + public static MessageStreamIterator FromStreamProvider(StreamProvider streamProvider) { + return new MessageStreamIterator(streamProvider, ExtensionRegistry.Empty); } public IEnumerator GetEnumerator() { @@ -107,16 +138,11 @@ namespace Google.ProtocolBuffers { if (tag != ExpectedTag) { throw InvalidProtocolBufferException.InvalidMessageStreamTag(); } - TBuilder builder = new TBuilder(); - input.ReadMessage(builder, extensionRegistry); - yield return builder.Build(); + yield return messageReader(input, extensionRegistry); } } } - /// - /// Explicit implementation of nongeneric IEnumerable interface. - /// IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } diff --git a/csharp/ProtocolBuffers/ProtocolBuffers.csproj b/csharp/ProtocolBuffers/ProtocolBuffers.csproj index 25f7cdbb..70a4691d 100644 --- a/csharp/ProtocolBuffers/ProtocolBuffers.csproj +++ b/csharp/ProtocolBuffers/ProtocolBuffers.csproj @@ -41,6 +41,7 @@ + @@ -72,7 +73,6 @@ - -- cgit v1.2.3