aboutsummaryrefslogtreecommitdiff
path: root/src/ProtoGen/RepeatedEnumFieldGenerator.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-09-09 21:05:29 -0500
committerrogerk <devnull@localhost>2011-09-09 21:05:29 -0500
commit1a0764ab27ae7189ae4b2b8a1d9f7a0599568282 (patch)
tree413ef5d6826ce9ba6568a1696a9ada8aaad1f17f /src/ProtoGen/RepeatedEnumFieldGenerator.cs
parent8f0dcf3df1548a1eff0bed54a9b992f55b8f72d5 (diff)
downloadprotobuf-1a0764ab27ae7189ae4b2b8a1d9f7a0599568282.tar.gz
protobuf-1a0764ab27ae7189ae4b2b8a1d9f7a0599568282.tar.bz2
protobuf-1a0764ab27ae7189ae4b2b8a1d9f7a0599568282.zip
First pass at implementation and testing of reusable builders.
Diffstat (limited to 'src/ProtoGen/RepeatedEnumFieldGenerator.cs')
-rw-r--r--src/ProtoGen/RepeatedEnumFieldGenerator.cs6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/ProtoGen/RepeatedEnumFieldGenerator.cs b/src/ProtoGen/RepeatedEnumFieldGenerator.cs
index 5880390b..ae1ed240 100644
--- a/src/ProtoGen/RepeatedEnumFieldGenerator.cs
+++ b/src/ProtoGen/RepeatedEnumFieldGenerator.cs
@@ -71,7 +71,7 @@ namespace Google.ProtocolBuffers.ProtoGen
// Note: We can return the original list here, because we make it unmodifiable when we build
// We return it via IPopsicleList so that collection initializers work more pleasantly.
writer.WriteLine("public pbc::IPopsicleList<{0}> {1}List {{", TypeName, PropertyName);
- writer.WriteLine(" get {{ return result.{0}_; }}", Name);
+ writer.WriteLine(" get {{ return PrepareBuilder().{0}_; }}", Name);
writer.WriteLine("}");
writer.WriteLine("public int {0}Count {{", PropertyName);
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
@@ -80,18 +80,22 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine(" return result.Get{0}(index);", PropertyName);
writer.WriteLine("}");
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
+ writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_[index] = value;", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
+ writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
writer.WriteLine(" return this;");
writer.WriteLine("}");
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
+ writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
+ writer.WriteLine(" PrepareBuilder();");
writer.WriteLine(" result.{0}_.Clear();", Name);
writer.WriteLine(" return this;");
writer.WriteLine("}");