Fix property special-casing
This commit is contained in:
parent
1d131c98f0
commit
4cf9e3c619
@ -22,9 +22,8 @@ extend FieldOptions {
|
||||
|
||||
message CSharpFieldOptions {
|
||||
// Provides the ability to override the name of the property
|
||||
// generated for this field. This does not currently work with
|
||||
// messages optimised for reflection, and is only applied to the
|
||||
// actual property rather than associated methods. (Careful
|
||||
// consideration needed here...)
|
||||
// generated for this field. This is applied to all properties
|
||||
// and methods to do with this field, including HasFoo, FooCount,
|
||||
// FooList etc.
|
||||
optional string property_name = 1;
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
}
|
||||
|
||||
public void GenerateMembers(TextGenerator writer) {
|
||||
writer.WriteLine("private bool has{0};", CapitalizedName);
|
||||
writer.WriteLine("private bool has{0};", PropertyName);
|
||||
writer.WriteLine("private {0} {1}_ = {2};", TypeName, Name, DefaultValue);
|
||||
writer.WriteLine("public bool Has{0} {{", CapitalizedName);
|
||||
writer.WriteLine(" get {{ return has{0}; }}", CapitalizedName);
|
||||
writer.WriteLine("public bool Has{0} {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return has{0}; }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return {0}_; }}", Name);
|
||||
@ -21,27 +21,27 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
}
|
||||
|
||||
public void GenerateBuilderMembers(TextGenerator writer) {
|
||||
writer.WriteLine("public bool Has{0} {{", CapitalizedName);
|
||||
writer.WriteLine(" get {{ return result.Has{0}; }}", CapitalizedName);
|
||||
writer.WriteLine("public bool Has{0} {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return result.Has{0}; }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
|
||||
writer.WriteLine(" set {{ Set{0}(value); }}", CapitalizedName);
|
||||
writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Set{0}({1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine(" result.has{0} = true;", CapitalizedName);
|
||||
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.has{0} = true;", PropertyName);
|
||||
writer.WriteLine(" result.{0}_ = value;", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Clear{0}() {{", CapitalizedName);
|
||||
writer.WriteLine(" result.has{0} = false;", CapitalizedName);
|
||||
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
|
||||
writer.WriteLine(" result.has{0} = false;", PropertyName);
|
||||
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateMergingCode(TextGenerator writer) {
|
||||
writer.WriteLine("if (other.Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine("if (other.Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" {0} = other.{0};", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
@ -61,13 +61,13 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
}
|
||||
|
||||
public void GenerateSerializationCode(TextGenerator writer) {
|
||||
writer.WriteLine("if (Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine("if (Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" output.WriteEnum({0}, (int) {1});", Number, PropertyName);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateSerializedSizeCode(TextGenerator writer) {
|
||||
writer.WriteLine("if (Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine("if (Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" size += pb::CodedOutputStream.ComputeEnumSize({0}, (int) {1});", Number, PropertyName);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
@ -79,10 +79,6 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
}
|
||||
}
|
||||
|
||||
protected string CapitalizedName {
|
||||
get { return NameHelpers.UnderscoresToPascalCase(GetFieldName(Descriptor)); }
|
||||
}
|
||||
|
||||
protected string Name {
|
||||
get { return NameHelpers.UnderscoresToCamelCase(GetFieldName(Descriptor)); }
|
||||
}
|
||||
|
@ -8,54 +8,54 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
}
|
||||
|
||||
public void GenerateMembers(TextGenerator writer) {
|
||||
writer.WriteLine("private bool has{0};", CapitalizedName);
|
||||
writer.WriteLine("private bool has{0};", PropertyName);
|
||||
writer.WriteLine("private {0} {1}_ = {2};", TypeName, Name, DefaultValue);
|
||||
writer.WriteLine("public bool Has{0} {{", CapitalizedName);
|
||||
writer.WriteLine(" get {{ return has{0}; }}", CapitalizedName);
|
||||
writer.WriteLine("public bool Has{0} {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return has{0}; }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public {0} {1} {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return {0}_; }}", Name);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateBuilderMembers(TextGenerator writer) {
|
||||
writer.WriteLine("public bool Has{0} {{", CapitalizedName);
|
||||
writer.WriteLine(" get {{ return result.Has{0}; }}", CapitalizedName);
|
||||
writer.WriteLine("public bool Has{0} {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return result.Has{0}; }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public {0} {1} {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine(" get {{ return result.{0}; }}", CapitalizedName);
|
||||
writer.WriteLine(" set {{ Set{0}(value); }}", CapitalizedName);
|
||||
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
|
||||
writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Set{0}({1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine(" result.has{0} = true;", CapitalizedName);
|
||||
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.has{0} = true;", PropertyName);
|
||||
writer.WriteLine(" result.{0}_ = value;", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Set{0}({1}.Builder builderForValue) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine(" result.has{0} = true;", CapitalizedName);
|
||||
writer.WriteLine("public Builder Set{0}({1}.Builder builderForValue) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.has{0} = true;", PropertyName);
|
||||
writer.WriteLine(" result.{0}_ = builderForValue.Build();", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Merge{0}({1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine(" if (result.Has{0} &&", CapitalizedName);
|
||||
writer.WriteLine("public Builder Merge{0}({1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" if (result.Has{0} &&", PropertyName);
|
||||
writer.WriteLine(" result.{0}_ != {1}) {{", Name, DefaultValue);
|
||||
writer.WriteLine(" result.{0}_ = {1}.CreateBuilder(result.{0}_).MergeFrom(value).BuildPartial();", Name, TypeName);
|
||||
writer.WriteLine(" } else {");
|
||||
writer.WriteLine(" result.{0}_ = value;", Name);
|
||||
writer.WriteLine(" }");
|
||||
writer.WriteLine(" result.has{0} = true;", CapitalizedName);
|
||||
writer.WriteLine(" result.has{0} = true;", PropertyName);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Clear{0}() {{", CapitalizedName);
|
||||
writer.WriteLine(" result.has{0} = false;", CapitalizedName);
|
||||
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
|
||||
writer.WriteLine(" result.has{0} = false;", PropertyName);
|
||||
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateMergingCode(TextGenerator writer) {
|
||||
writer.WriteLine("if (other.Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine(" Merge{0}(other.{0});", CapitalizedName);
|
||||
writer.WriteLine("if (other.Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" Merge{0}(other.{0});", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
@ -65,27 +65,27 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
|
||||
public void GenerateParsingCode(TextGenerator writer) {
|
||||
writer.WriteLine("{0}.Builder subBuilder = {0}.CreateBuilder();", TypeName);
|
||||
writer.WriteLine("if (Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine(" subBuilder.MergeFrom({0});", CapitalizedName);
|
||||
writer.WriteLine("if (Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" subBuilder.MergeFrom({0});", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
if (Descriptor.FieldType == FieldType.Group) {
|
||||
writer.WriteLine("input.ReadGroup({0}, subBuilder, extensionRegistry);", Number);
|
||||
} else {
|
||||
writer.WriteLine("input.ReadMessage(subBuilder, extensionRegistry);");
|
||||
}
|
||||
writer.WriteLine("{0} = subBuilder.BuildPartial();", CapitalizedName);
|
||||
writer.WriteLine("{0} = subBuilder.BuildPartial();", PropertyName);
|
||||
}
|
||||
|
||||
public void GenerateSerializationCode(TextGenerator writer) {
|
||||
writer.WriteLine("if (Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine(" output.Write{0}({1}, {2});", MessageOrGroup, Number, CapitalizedName);
|
||||
writer.WriteLine("if (Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" output.Write{0}({1}, {2});", MessageOrGroup, Number, PropertyName);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateSerializedSizeCode(TextGenerator writer) {
|
||||
writer.WriteLine("if (Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine("if (Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" size += pb::CodedOutputStream.Compute{0}Size({1}, {2});",
|
||||
MessageOrGroup, Number, CapitalizedName);
|
||||
MessageOrGroup, Number, PropertyName);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
FullClassName, identifier);
|
||||
writer.Print(" new string[] { ");
|
||||
foreach (FieldDescriptor field in Descriptor.Fields) {
|
||||
writer.Write("\"{0}\", ", NameHelpers.UnderscoresToPascalCase(GetFieldName(field)));
|
||||
writer.Write("\"{0}\", ", field.CSharpOptions.PropertyName);
|
||||
}
|
||||
writer.WriteLine("});");
|
||||
|
||||
@ -415,7 +415,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
// "has" fields into a single bitfield.
|
||||
foreach (FieldDescriptor field in Descriptor.Fields) {
|
||||
if (field.IsRequired) {
|
||||
writer.WriteLine("if (!has{0}) return false;", NameHelpers.UnderscoresToPascalCase(field.Name));
|
||||
writer.WriteLine("if (!has{0}) return false;", field.CSharpOptions.PropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
}
|
||||
|
||||
public void GenerateMembers(TextGenerator writer) {
|
||||
writer.WriteLine("private bool has{0};", CapitalizedName);
|
||||
writer.WriteLine("private bool has{0};", PropertyName);
|
||||
writer.WriteLine("private {0} {1}_ = {2};", TypeName, Name, DefaultValue);
|
||||
writer.WriteLine("public bool Has{0} {{", CapitalizedName);
|
||||
writer.WriteLine(" get {{ return has{0}; }}", CapitalizedName);
|
||||
writer.WriteLine("public bool Has{0} {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return has{0}; }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return {0}_; }}", Name);
|
||||
@ -21,27 +21,27 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
}
|
||||
|
||||
public void GenerateBuilderMembers(TextGenerator writer) {
|
||||
writer.WriteLine("public bool Has{0} {{", CapitalizedName);
|
||||
writer.WriteLine(" get {{ return result.Has{0}; }}", CapitalizedName);
|
||||
writer.WriteLine("public bool Has{0} {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return result.Has{0}; }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
|
||||
writer.WriteLine(" set {{ Set{0}(value); }}", CapitalizedName);
|
||||
writer.WriteLine(" set {{ Set{0}(value); }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Set{0}({1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine(" result.has{0} = true;", CapitalizedName);
|
||||
writer.WriteLine("public Builder Set{0}({1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.has{0} = true;", PropertyName);
|
||||
writer.WriteLine(" result.{0}_ = value;", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Clear{0}() {{", CapitalizedName);
|
||||
writer.WriteLine(" result.has{0} = false;", CapitalizedName);
|
||||
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
|
||||
writer.WriteLine(" result.has{0} = false;", PropertyName);
|
||||
writer.WriteLine(" result.{0}_ = {1};", Name, DefaultValue);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateMergingCode(TextGenerator writer) {
|
||||
writer.WriteLine("if (other.Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine("if (other.Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" {0} = other.{0};", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
@ -55,13 +55,13 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
}
|
||||
|
||||
public void GenerateSerializationCode(TextGenerator writer) {
|
||||
writer.WriteLine("if (Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine("if (Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" output.Write{0}({1}, {2});", CapitalizedTypeName, Number, PropertyName);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateSerializedSizeCode(TextGenerator writer) {
|
||||
writer.WriteLine("if (Has{0}) {{", CapitalizedName);
|
||||
writer.WriteLine("if (Has{0}) {{", PropertyName);
|
||||
writer.WriteLine(" size += pb::CodedOutputStream.Compute{0}Size({1}, {2});",
|
||||
CapitalizedTypeName, Number, PropertyName);
|
||||
writer.WriteLine("}");
|
||||
|
@ -12,44 +12,44 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
|
||||
public void GenerateMembers(TextGenerator writer) {
|
||||
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return pbc::Lists.AsReadOnly({0}_); }}", Name);
|
||||
writer.WriteLine("}");
|
||||
|
||||
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
|
||||
writer.WriteLine("public int {0}Count {{", CapitalizedName);
|
||||
writer.WriteLine("public int {0}Count {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return {0}_.Count; }}", Name);
|
||||
writer.WriteLine("}");
|
||||
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" return {0}_[index];", Name);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateBuilderMembers(TextGenerator writer) {
|
||||
// Note: We can return the original list here, because we make it unmodifiable when we build
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return result.{0}_; }}", Name);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public int {0}Count {{", CapitalizedName);
|
||||
writer.WriteLine(" get {{ return result.{0}Count; }}", CapitalizedName);
|
||||
writer.WriteLine("public int {0}Count {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine(" return result.Get{0}(index);", CapitalizedName);
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" return result.Get{0}(index);", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.{0}_[index] = value;", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Add{0}({1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Clear{0}() {{", CapitalizedName);
|
||||
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
|
||||
writer.WriteLine(" result.{0}_.Clear();", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
@ -71,18 +71,18 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
writer.WriteLine("if (!global::System.Enum.IsDefined(typeof({0}), rawValue)) {{", TypeName);
|
||||
writer.WriteLine(" unknownFields.MergeVarintField({0}, (ulong) rawValue);", Number);
|
||||
writer.WriteLine("} else {");
|
||||
writer.WriteLine(" Add{0}(({1}) rawValue);", CapitalizedName, TypeName);
|
||||
writer.WriteLine(" Add{0}(({1}) rawValue);", PropertyName, TypeName);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateSerializationCode(TextGenerator writer) {
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" output.WriteEnum({0}, (int) element);", Number);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateSerializedSizeCode(TextGenerator writer) {
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" size += pb::CodedOutputStream.ComputeEnumSize({0}, (int) element);", Number);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
@ -12,54 +12,54 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
|
||||
public void GenerateMembers(TextGenerator writer) {
|
||||
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return {0}_; }}", Name);
|
||||
writer.WriteLine("}");
|
||||
|
||||
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
|
||||
writer.WriteLine("public int {0}Count {{", CapitalizedName);
|
||||
writer.WriteLine("public int {0}Count {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return {0}_.Count; }}", Name);
|
||||
writer.WriteLine("}");
|
||||
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" return {0}_[index];", Name);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateBuilderMembers(TextGenerator writer) {
|
||||
// Note: We can return the original list here, because we make it unmodifiable when we build
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return result.{0}_; }}", Name);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public int {0}Count {{", CapitalizedName);
|
||||
writer.WriteLine(" get {{ return result.{0}Count; }}", CapitalizedName);
|
||||
writer.WriteLine("public int {0}Count {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine(" return result.Get{0}(index);", CapitalizedName);
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" return result.Get{0}(index);", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.{0}_[index] = value;", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
// Extra overload for builder (just on messages)
|
||||
writer.WriteLine("public Builder Set{0}(int index, {1}.Builder builderForValue) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder Set{0}(int index, {1}.Builder builderForValue) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.{0}_[index] = builderForValue.Build();", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Add{0}({1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
// Extra overload for builder (just on messages)
|
||||
writer.WriteLine("public Builder Add{0}({1}.Builder builderForValue) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder Add{0}({1}.Builder builderForValue) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.{0}_.Add(builderForValue.Build());", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Clear{0}() {{", CapitalizedName);
|
||||
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
|
||||
writer.WriteLine(" result.{0}_.Clear();", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
@ -82,17 +82,17 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
} else {
|
||||
writer.WriteLine("input.ReadMessage(subBuilder, extensionRegistry);");
|
||||
}
|
||||
writer.WriteLine("Add{0}(subBuilder.BuildPartial());", CapitalizedName);
|
||||
writer.WriteLine("Add{0}(subBuilder.BuildPartial());", PropertyName);
|
||||
}
|
||||
|
||||
public void GenerateSerializationCode(TextGenerator writer) {
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" output.Write{0}({1}, element);", MessageOrGroup, Number);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateSerializedSizeCode(TextGenerator writer) {
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" size += pb::CodedOutputStream.Compute{0}Size({1}, element);", MessageOrGroup, Number);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
@ -12,44 +12,44 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
|
||||
public void GenerateMembers(TextGenerator writer) {
|
||||
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return pbc::Lists.AsReadOnly({0}_); }}", Name);
|
||||
writer.WriteLine("}");
|
||||
|
||||
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
|
||||
writer.WriteLine("public int {0}Count {{", CapitalizedName);
|
||||
writer.WriteLine("public int {0}Count {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return {0}_.Count; }}", Name);
|
||||
writer.WriteLine("}");
|
||||
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" return {0}_[index];", Name);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateBuilderMembers(TextGenerator writer) {
|
||||
// Note: We can return the original list here, because we make it unmodifiable when we build
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("public scg::IList<{0}> {1}List {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" get {{ return result.{0}_; }}", Name);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public int {0}Count {{", CapitalizedName);
|
||||
writer.WriteLine(" get {{ return result.{0}Count; }}", CapitalizedName);
|
||||
writer.WriteLine("public int {0}Count {{", PropertyName);
|
||||
writer.WriteLine(" get {{ return result.{0}Count; }}", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine(" return result.Get{0}(index);", CapitalizedName);
|
||||
writer.WriteLine("public {0} Get{1}(int index) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" return result.Get{0}(index);", PropertyName);
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder Set{0}(int index, {1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.{0}_[index] = value;", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Add{0}({1} value) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder Add{0}({1} value) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" result.{0}_.Add(value);", Name, TypeName);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", CapitalizedName, TypeName);
|
||||
writer.WriteLine("public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{", PropertyName, TypeName);
|
||||
writer.WriteLine(" base.AddRange(values, result.{0}_);", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
writer.WriteLine("public Builder Clear{0}() {{", CapitalizedName);
|
||||
writer.WriteLine("public Builder Clear{0}() {{", PropertyName);
|
||||
writer.WriteLine(" result.{0}_.Clear();", Name);
|
||||
writer.WriteLine(" return this;");
|
||||
writer.WriteLine("}");
|
||||
@ -66,17 +66,17 @@ namespace Google.ProtocolBuffers.ProtoGen {
|
||||
}
|
||||
|
||||
public void GenerateParsingCode(TextGenerator writer) {
|
||||
writer.WriteLine("Add{0}(input.Read{1}());", CapitalizedName, CapitalizedTypeName);
|
||||
writer.WriteLine("Add{0}(input.Read{1}());", PropertyName, CapitalizedTypeName);
|
||||
}
|
||||
|
||||
public void GenerateSerializationCode(TextGenerator writer) {
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" output.Write{0}({1}, element);", CapitalizedTypeName, Number);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
||||
public void GenerateSerializedSizeCode(TextGenerator writer) {
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, CapitalizedName);
|
||||
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, PropertyName);
|
||||
writer.WriteLine(" size += pb::CodedOutputStream.Compute{0}Size({1}, element);", CapitalizedTypeName, Number);
|
||||
writer.WriteLine("}");
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
|
||||
= internal__static_google_protobuf_UninterpretedOption__Descriptor.NestedTypes[0];
|
||||
internal static pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart.Builder> internal__static_google_protobuf_UninterpretedOption_NamePart__FieldAccessorTable
|
||||
= new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart, global::Google.ProtocolBuffers.DescriptorProtos.UninterpretedOption.Types.NamePart.Builder>(internal__static_google_protobuf_UninterpretedOption_NamePart__Descriptor,
|
||||
new string[] { "NamePart", "IsExtension", });
|
||||
new string[] { "NamePart_", "IsExtension", });
|
||||
#endregion
|
||||
}
|
||||
#region Messages
|
||||
@ -5517,10 +5517,10 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
|
||||
get { return global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProtoFile.internal__static_google_protobuf_UninterpretedOption_NamePart__FieldAccessorTable; }
|
||||
}
|
||||
|
||||
private bool hasNamePart;
|
||||
private bool hasNamePart_;
|
||||
private string namePart_ = "";
|
||||
public bool HasNamePart {
|
||||
get { return hasNamePart; }
|
||||
public bool HasNamePart_ {
|
||||
get { return hasNamePart_; }
|
||||
}
|
||||
public string NamePart_ {
|
||||
get { return namePart_; }
|
||||
@ -5537,14 +5537,14 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
|
||||
|
||||
public override bool IsInitialized {
|
||||
get {
|
||||
if (!hasNamePart) return false;
|
||||
if (!hasNamePart_) return false;
|
||||
if (!hasIsExtension) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteTo(pb::CodedOutputStream output) {
|
||||
if (HasNamePart) {
|
||||
if (HasNamePart_) {
|
||||
output.WriteString(1, NamePart_);
|
||||
}
|
||||
if (HasIsExtension) {
|
||||
@ -5560,7 +5560,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (HasNamePart) {
|
||||
if (HasNamePart_) {
|
||||
size += pb::CodedOutputStream.ComputeStringSize(1, NamePart_);
|
||||
}
|
||||
if (HasIsExtension) {
|
||||
@ -5648,7 +5648,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
|
||||
|
||||
public override Builder MergeFrom(NamePart other) {
|
||||
if (other == NamePart.DefaultInstance) return this;
|
||||
if (other.HasNamePart) {
|
||||
if (other.HasNamePart_) {
|
||||
NamePart_ = other.NamePart_;
|
||||
}
|
||||
if (other.HasIsExtension) {
|
||||
@ -5691,20 +5691,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
|
||||
}
|
||||
|
||||
|
||||
public bool HasNamePart {
|
||||
get { return result.HasNamePart; }
|
||||
public bool HasNamePart_ {
|
||||
get { return result.HasNamePart_; }
|
||||
}
|
||||
public string NamePart_ {
|
||||
get { return result.NamePart_; }
|
||||
set { SetNamePart(value); }
|
||||
set { SetNamePart_(value); }
|
||||
}
|
||||
public Builder SetNamePart(string value) {
|
||||
result.hasNamePart = true;
|
||||
public Builder SetNamePart_(string value) {
|
||||
result.hasNamePart_ = true;
|
||||
result.namePart_ = value;
|
||||
return this;
|
||||
}
|
||||
public Builder ClearNamePart() {
|
||||
result.hasNamePart = false;
|
||||
public Builder ClearNamePart_() {
|
||||
result.hasNamePart_ = false;
|
||||
result.namePart_ = "";
|
||||
return this;
|
||||
}
|
||||
|
@ -54,6 +54,11 @@ namespace Google.ProtocolBuffers.FieldAccess {
|
||||
/// <summary>
|
||||
/// Constructs a FieldAccessorTable for a particular message class.
|
||||
/// Only one FieldAccessorTable should be constructed per class.
|
||||
/// The property names should all actually correspond with the field descriptor's
|
||||
/// CSharpOptions.PropertyName property, but bootstrapping issues currently
|
||||
/// prevent us from using that. This may be addressed at a future time, in which case
|
||||
/// we can keep this constructor for backwards compatibility, just ignoring the parameter.
|
||||
/// TODO(jonskeet): Make it so.
|
||||
/// </summary>
|
||||
/// <param name="descriptor">The type's descriptor</param>
|
||||
/// <param name="propertyNames">The Pascal-case names of all the field-based properties in the message.</param>
|
||||
|
@ -55,11 +55,9 @@ namespace Google.ProtocolBuffers.FieldAccess {
|
||||
}
|
||||
|
||||
internal SinglePrimitiveAccessor(string name) {
|
||||
|
||||
string propertyName = name == typeof(TMessage).Name ? name + "_" : name;
|
||||
PropertyInfo messageProperty = typeof(TMessage).GetProperty(propertyName);
|
||||
PropertyInfo builderProperty = typeof(TBuilder).GetProperty(name); // FIXME!
|
||||
if (builderProperty == null) builderProperty = typeof(TBuilder).GetProperty(propertyName); // FIXME!
|
||||
PropertyInfo messageProperty = typeof(TMessage).GetProperty(name);
|
||||
PropertyInfo builderProperty = typeof(TBuilder).GetProperty(name);
|
||||
if (builderProperty == null) builderProperty = typeof(TBuilder).GetProperty(name);
|
||||
PropertyInfo hasProperty = typeof(TMessage).GetProperty("Has" + name);
|
||||
MethodInfo clearMethod = typeof(TBuilder).GetMethod("Clear" + name, Type.EmptyTypes);
|
||||
if (messageProperty == null || builderProperty == null || hasProperty == null || clearMethod == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user