Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
4cf9e3c6
Commit
4cf9e3c6
authored
Nov 24, 2008
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix property special-casing
parent
1d131c98
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
128 additions
and
130 deletions
+128
-130
csharp_options.proto
protos/google/protobuf/csharp_options.proto
+3
-4
EnumFieldGenerator.cs
src/ProtoGen/EnumFieldGenerator.cs
+13
-13
FieldGeneratorBase.cs
src/ProtoGen/FieldGeneratorBase.cs
+0
-4
MessageFieldGenerator.cs
src/ProtoGen/MessageFieldGenerator.cs
+27
-27
MessageGenerator.cs
src/ProtoGen/MessageGenerator.cs
+2
-2
PrimitiveFieldGenerator.cs
src/ProtoGen/PrimitiveFieldGenerator.cs
+13
-13
RepeatedEnumFieldGenerator.cs
src/ProtoGen/RepeatedEnumFieldGenerator.cs
+15
-15
RepeatedMessageFieldGenerator.cs
src/ProtoGen/RepeatedMessageFieldGenerator.cs
+17
-17
RepeatedPrimitiveFieldGenerator.cs
src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs
+15
-15
DescriptorProtoFile.cs
src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
+15
-15
FieldAccessorTable.cs
src/ProtocolBuffers/FieldAccess/FieldAccessorTable.cs
+5
-0
SinglePrimitiveAccessor.cs
src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
+3
-5
No files found.
protos/google/protobuf/csharp_options.proto
View file @
4cf9e3c6
...
@@ -22,9 +22,8 @@ extend FieldOptions {
...
@@ -22,9 +22,8 @@ extend FieldOptions {
message
CSharpFieldOptions
{
message
CSharpFieldOptions
{
// Provides the ability to override the name of the property
// Provides the ability to override the name of the property
// generated for this field. This does not currently work with
// generated for this field. This is applied to all properties
// messages optimised for reflection, and is only applied to the
// and methods to do with this field, including HasFoo, FooCount,
// actual property rather than associated methods. (Careful
// FooList etc.
// consideration needed here...)
optional
string
property_name
=
1
;
optional
string
property_name
=
1
;
}
}
src/ProtoGen/EnumFieldGenerator.cs
View file @
4cf9e3c6
...
@@ -10,10 +10,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -10,10 +10,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
public
void
GenerateMembers
(
TextGenerator
writer
)
{
public
void
GenerateMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"private bool has{0};"
,
Capitalized
Name
);
writer
.
WriteLine
(
"private bool has{0};"
,
Property
Name
);
writer
.
WriteLine
(
"private {0} {1}_ = {2};"
,
TypeName
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
"private {0} {1}_ = {2};"
,
TypeName
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return has{0}; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return has{0}; }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
PropertyName
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
PropertyName
);
writer
.
WriteLine
(
" get {{ return {0}_; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return {0}_; }}"
,
Name
);
...
@@ -21,27 +21,27 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -21,27 +21,27 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.Has{0}; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return result.Has{0}; }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
PropertyName
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
PropertyName
);
writer
.
WriteLine
(
" get {{ return result.{0}; }}"
,
PropertyName
);
writer
.
WriteLine
(
" get {{ return result.{0}; }}"
,
PropertyName
);
writer
.
WriteLine
(
" set {{ Set{0}(value); }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" set {{ Set{0}(value); }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Set{0}({1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Set{0}({1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Capitalized
Name
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_ = value;"
,
Name
);
writer
.
WriteLine
(
" result.{0}_ = value;"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Property
Name
);
writer
.
WriteLine
(
" result.has{0} = false;"
,
Capitalized
Name
);
writer
.
WriteLine
(
" result.has{0} = false;"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_ = {1};"
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
" result.{0}_ = {1};"
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateMergingCode
(
TextGenerator
writer
)
{
public
void
GenerateMergingCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"if (other.Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (other.Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" {0} = other.{0};"
,
PropertyName
);
writer
.
WriteLine
(
" {0} = other.{0};"
,
PropertyName
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
...
@@ -61,13 +61,13 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -61,13 +61,13 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" output.WriteEnum({0}, (int) {1});"
,
Number
,
PropertyName
);
writer
.
WriteLine
(
" output.WriteEnum({0}, (int) {1});"
,
Number
,
PropertyName
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.ComputeEnumSize({0}, (int) {1});"
,
Number
,
PropertyName
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.ComputeEnumSize({0}, (int) {1});"
,
Number
,
PropertyName
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
...
...
src/ProtoGen/FieldGeneratorBase.cs
View file @
4cf9e3c6
...
@@ -79,10 +79,6 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -79,10 +79,6 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
}
}
protected
string
CapitalizedName
{
get
{
return
NameHelpers
.
UnderscoresToPascalCase
(
GetFieldName
(
Descriptor
));
}
}
protected
string
Name
{
protected
string
Name
{
get
{
return
NameHelpers
.
UnderscoresToCamelCase
(
GetFieldName
(
Descriptor
));
}
get
{
return
NameHelpers
.
UnderscoresToCamelCase
(
GetFieldName
(
Descriptor
));
}
}
}
...
...
src/ProtoGen/MessageFieldGenerator.cs
View file @
4cf9e3c6
...
@@ -8,54 +8,54 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -8,54 +8,54 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
public
void
GenerateMembers
(
TextGenerator
writer
)
{
public
void
GenerateMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"private bool has{0};"
,
Capitalized
Name
);
writer
.
WriteLine
(
"private bool has{0};"
,
Property
Name
);
writer
.
WriteLine
(
"private {0} {1}_ = {2};"
,
TypeName
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
"private {0} {1}_ = {2};"
,
TypeName
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return has{0}; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return has{0}; }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return {0}_; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return {0}_; }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.Has{0}; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return result.Has{0}; }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}; }}"
,
Property
Name
);
writer
.
WriteLine
(
" set {{ Set{0}(value); }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" set {{ Set{0}(value); }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Set{0}({1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Set{0}({1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Capitalized
Name
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_ = value;"
,
Name
);
writer
.
WriteLine
(
" result.{0}_ = value;"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Set{0}({1}.Builder builderForValue) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Set{0}({1}.Builder builderForValue) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Capitalized
Name
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_ = builderForValue.Build();"
,
Name
);
writer
.
WriteLine
(
" result.{0}_ = builderForValue.Build();"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Merge{0}({1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Merge{0}({1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" if (result.Has{0} &&"
,
Capitalized
Name
);
writer
.
WriteLine
(
" if (result.Has{0} &&"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_ != {1}) {{"
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
" result.{0}_ != {1}) {{"
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
" result.{0}_ = {1}.CreateBuilder(result.{0}_).MergeFrom(value).BuildPartial();"
,
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_ = {1}.CreateBuilder(result.{0}_).MergeFrom(value).BuildPartial();"
,
Name
,
TypeName
);
writer
.
WriteLine
(
" } else {"
);
writer
.
WriteLine
(
" } else {"
);
writer
.
WriteLine
(
" result.{0}_ = value;"
,
Name
);
writer
.
WriteLine
(
" result.{0}_ = value;"
,
Name
);
writer
.
WriteLine
(
" }"
);
writer
.
WriteLine
(
" }"
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Capitalized
Name
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Property
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Property
Name
);
writer
.
WriteLine
(
" result.has{0} = false;"
,
Capitalized
Name
);
writer
.
WriteLine
(
" result.has{0} = false;"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_ = {1};"
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
" result.{0}_ = {1};"
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateMergingCode
(
TextGenerator
writer
)
{
public
void
GenerateMergingCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"if (other.Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (other.Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" Merge{0}(other.{0});"
,
Capitalized
Name
);
writer
.
WriteLine
(
" Merge{0}(other.{0});"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
...
@@ -65,27 +65,27 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -65,27 +65,27 @@ namespace Google.ProtocolBuffers.ProtoGen {
public
void
GenerateParsingCode
(
TextGenerator
writer
)
{
public
void
GenerateParsingCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"{0}.Builder subBuilder = {0}.CreateBuilder();"
,
TypeName
);
writer
.
WriteLine
(
"{0}.Builder subBuilder = {0}.CreateBuilder();"
,
TypeName
);
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" subBuilder.MergeFrom({0});"
,
Capitalized
Name
);
writer
.
WriteLine
(
" subBuilder.MergeFrom({0});"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
if
(
Descriptor
.
FieldType
==
FieldType
.
Group
)
{
if
(
Descriptor
.
FieldType
==
FieldType
.
Group
)
{
writer
.
WriteLine
(
"input.ReadGroup({0}, subBuilder, extensionRegistry);"
,
Number
);
writer
.
WriteLine
(
"input.ReadGroup({0}, subBuilder, extensionRegistry);"
,
Number
);
}
else
{
}
else
{
writer
.
WriteLine
(
"input.ReadMessage(subBuilder, extensionRegistry);"
);
writer
.
WriteLine
(
"input.ReadMessage(subBuilder, extensionRegistry);"
);
}
}
writer
.
WriteLine
(
"{0} = subBuilder.BuildPartial();"
,
Capitalized
Name
);
writer
.
WriteLine
(
"{0} = subBuilder.BuildPartial();"
,
Property
Name
);
}
}
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" output.Write{0}({1}, {2});"
,
MessageOrGroup
,
Number
,
Capitalized
Name
);
writer
.
WriteLine
(
" output.Write{0}({1}, {2});"
,
MessageOrGroup
,
Number
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.Compute{0}Size({1}, {2});"
,
writer
.
WriteLine
(
" size += pb::CodedOutputStream.Compute{0}Size({1}, {2});"
,
MessageOrGroup
,
Number
,
Capitalized
Name
);
MessageOrGroup
,
Number
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
}
}
...
...
src/ProtoGen/MessageGenerator.cs
View file @
4cf9e3c6
...
@@ -51,7 +51,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -51,7 +51,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
FullClassName
,
identifier
);
FullClassName
,
identifier
);
writer
.
Print
(
" new string[] { "
);
writer
.
Print
(
" new string[] { "
);
foreach
(
FieldDescriptor
field
in
Descriptor
.
Fields
)
{
foreach
(
FieldDescriptor
field
in
Descriptor
.
Fields
)
{
writer
.
Write
(
"\"{0}\", "
,
NameHelpers
.
UnderscoresToPascalCase
(
GetFieldName
(
field
))
);
writer
.
Write
(
"\"{0}\", "
,
field
.
CSharpOptions
.
PropertyName
);
}
}
writer
.
WriteLine
(
"});"
);
writer
.
WriteLine
(
"});"
);
...
@@ -415,7 +415,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -415,7 +415,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
// "has" fields into a single bitfield.
// "has" fields into a single bitfield.
foreach
(
FieldDescriptor
field
in
Descriptor
.
Fields
)
{
foreach
(
FieldDescriptor
field
in
Descriptor
.
Fields
)
{
if
(
field
.
IsRequired
)
{
if
(
field
.
IsRequired
)
{
writer
.
WriteLine
(
"if (!has{0}) return false;"
,
NameHelpers
.
UnderscoresToPascalCase
(
field
.
Name
)
);
writer
.
WriteLine
(
"if (!has{0}) return false;"
,
field
.
CSharpOptions
.
PropertyName
);
}
}
}
}
...
...
src/ProtoGen/PrimitiveFieldGenerator.cs
View file @
4cf9e3c6
...
@@ -10,10 +10,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -10,10 +10,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
public
void
GenerateMembers
(
TextGenerator
writer
)
{
public
void
GenerateMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"private bool has{0};"
,
Capitalized
Name
);
writer
.
WriteLine
(
"private bool has{0};"
,
Property
Name
);
writer
.
WriteLine
(
"private {0} {1}_ = {2};"
,
TypeName
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
"private {0} {1}_ = {2};"
,
TypeName
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return has{0}; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return has{0}; }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
PropertyName
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
PropertyName
);
writer
.
WriteLine
(
" get {{ return {0}_; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return {0}_; }}"
,
Name
);
...
@@ -21,27 +21,27 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -21,27 +21,27 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public bool Has{0} {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.Has{0}; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return result.Has{0}; }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
PropertyName
);
writer
.
WriteLine
(
"public {0} {1} {{"
,
TypeName
,
PropertyName
);
writer
.
WriteLine
(
" get {{ return result.{0}; }}"
,
PropertyName
);
writer
.
WriteLine
(
" get {{ return result.{0}; }}"
,
PropertyName
);
writer
.
WriteLine
(
" set {{ Set{0}(value); }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" set {{ Set{0}(value); }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Set{0}({1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Set{0}({1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Capitalized
Name
);
writer
.
WriteLine
(
" result.has{0} = true;"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_ = value;"
,
Name
);
writer
.
WriteLine
(
" result.{0}_ = value;"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Property
Name
);
writer
.
WriteLine
(
" result.has{0} = false;"
,
Capitalized
Name
);
writer
.
WriteLine
(
" result.has{0} = false;"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_ = {1};"
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
" result.{0}_ = {1};"
,
Name
,
DefaultValue
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateMergingCode
(
TextGenerator
writer
)
{
public
void
GenerateMergingCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"if (other.Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (other.Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" {0} = other.{0};"
,
PropertyName
);
writer
.
WriteLine
(
" {0} = other.{0};"
,
PropertyName
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
...
@@ -55,13 +55,13 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -55,13 +55,13 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" output.Write{0}({1}, {2});"
,
CapitalizedTypeName
,
Number
,
PropertyName
);
writer
.
WriteLine
(
" output.Write{0}({1}, {2});"
,
CapitalizedTypeName
,
Number
,
PropertyName
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"if (Has{0}) {{"
,
Property
Name
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.Compute{0}Size({1}, {2});"
,
writer
.
WriteLine
(
" size += pb::CodedOutputStream.Compute{0}Size({1}, {2});"
,
CapitalizedTypeName
,
Number
,
PropertyName
);
CapitalizedTypeName
,
Number
,
PropertyName
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
...
...
src/ProtoGen/RepeatedEnumFieldGenerator.cs
View file @
4cf9e3c6
...
@@ -12,44 +12,44 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -12,44 +12,44 @@ namespace Google.ProtocolBuffers.ProtoGen {
public
void
GenerateMembers
(
TextGenerator
writer
)
{
public
void
GenerateMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();"
,
TypeName
,
Name
);
writer
.
WriteLine
(
"private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();"
,
TypeName
,
Name
);
writer
.
WriteLine
(
"public scg::IList<{0}> {1}List {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public scg::IList<{0}> {1}List {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return pbc::Lists.AsReadOnly({0}_); }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return pbc::Lists.AsReadOnly({0}_); }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
writer
.
WriteLine
(
"public int {0}Count {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public int {0}Count {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return {0}_.Count; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return {0}_.Count; }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" return {0}_[index];"
,
Name
);
writer
.
WriteLine
(
" return {0}_[index];"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
// Note: We can return the original list here, because we make it unmodifiable when we build
// 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
,
Capitalized
Name
);
writer
.
WriteLine
(
"public scg::IList<{0}> {1}List {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}_; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}_; }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public int {0}Count {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public int {0}Count {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}Count; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}Count; }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" return result.Get{0}(index);"
,
Capitalized
Name
);
writer
.
WriteLine
(
" return result.Get{0}(index);"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Set{0}(int index, {1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Set{0}(int index, {1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_[index] = value;"
,
Name
);
writer
.
WriteLine
(
" result.{0}_[index] = value;"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Add{0}({1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Add{0}({1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_.Add(value);"
,
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_.Add(value);"
,
Name
,
TypeName
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" base.AddRange(values, result.{0}_);"
,
Name
);
writer
.
WriteLine
(
" base.AddRange(values, result.{0}_);"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_.Clear();"
,
Name
);
writer
.
WriteLine
(
" result.{0}_.Clear();"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
...
@@ -71,18 +71,18 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -71,18 +71,18 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer
.
WriteLine
(
"if (!global::System.Enum.IsDefined(typeof({0}), rawValue)) {{"
,
TypeName
);
writer
.
WriteLine
(
"if (!global::System.Enum.IsDefined(typeof({0}), rawValue)) {{"
,
TypeName
);
writer
.
WriteLine
(
" unknownFields.MergeVarintField({0}, (ulong) rawValue);"
,
Number
);
writer
.
WriteLine
(
" unknownFields.MergeVarintField({0}, (ulong) rawValue);"
,
Number
);
writer
.
WriteLine
(
"} else {"
);
writer
.
WriteLine
(
"} else {"
);
writer
.
WriteLine
(
" Add{0}(({1}) rawValue);"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
" Add{0}(({1}) rawValue);"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" output.WriteEnum({0}, (int) element);"
,
Number
);
writer
.
WriteLine
(
" output.WriteEnum({0}, (int) element);"
,
Number
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.ComputeEnumSize({0}, (int) element);"
,
Number
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.ComputeEnumSize({0}, (int) element);"
,
Number
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
...
...
src/ProtoGen/RepeatedMessageFieldGenerator.cs
View file @
4cf9e3c6
...
@@ -12,54 +12,54 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -12,54 +12,54 @@ namespace Google.ProtocolBuffers.ProtoGen {
public
void
GenerateMembers
(
TextGenerator
writer
)
{
public
void
GenerateMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();"
,
TypeName
,
Name
);
writer
.
WriteLine
(
"private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();"
,
TypeName
,
Name
);
writer
.
WriteLine
(
"public scg::IList<{0}> {1}List {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public scg::IList<{0}> {1}List {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return {0}_; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return {0}_; }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
writer
.
WriteLine
(
"public int {0}Count {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public int {0}Count {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return {0}_.Count; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return {0}_.Count; }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" return {0}_[index];"
,
Name
);
writer
.
WriteLine
(
" return {0}_[index];"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
// Note: We can return the original list here, because we make it unmodifiable when we build
// 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
,
Capitalized
Name
);
writer
.
WriteLine
(
"public scg::IList<{0}> {1}List {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}_; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}_; }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public int {0}Count {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public int {0}Count {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}Count; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}Count; }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" return result.Get{0}(index);"
,
Capitalized
Name
);
writer
.
WriteLine
(
" return result.Get{0}(index);"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Set{0}(int index, {1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Set{0}(int index, {1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_[index] = value;"
,
Name
);
writer
.
WriteLine
(
" result.{0}_[index] = value;"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
// Extra overload for builder (just on messages)
// Extra overload for builder (just on messages)
writer
.
WriteLine
(
"public Builder Set{0}(int index, {1}.Builder builderForValue) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Set{0}(int index, {1}.Builder builderForValue) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_[index] = builderForValue.Build();"
,
Name
);
writer
.
WriteLine
(
" result.{0}_[index] = builderForValue.Build();"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Add{0}({1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Add{0}({1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_.Add(value);"
,
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_.Add(value);"
,
Name
,
TypeName
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
// Extra overload for builder (just on messages)
// Extra overload for builder (just on messages)
writer
.
WriteLine
(
"public Builder Add{0}({1}.Builder builderForValue) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Add{0}({1}.Builder builderForValue) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_.Add(builderForValue.Build());"
,
Name
);
writer
.
WriteLine
(
" result.{0}_.Add(builderForValue.Build());"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" base.AddRange(values, result.{0}_);"
,
Name
);
writer
.
WriteLine
(
" base.AddRange(values, result.{0}_);"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_.Clear();"
,
Name
);
writer
.
WriteLine
(
" result.{0}_.Clear();"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
...
@@ -82,17 +82,17 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -82,17 +82,17 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
else
{
}
else
{
writer
.
WriteLine
(
"input.ReadMessage(subBuilder, extensionRegistry);"
);
writer
.
WriteLine
(
"input.ReadMessage(subBuilder, extensionRegistry);"
);
}
}
writer
.
WriteLine
(
"Add{0}(subBuilder.BuildPartial());"
,
Capitalized
Name
);
writer
.
WriteLine
(
"Add{0}(subBuilder.BuildPartial());"
,
Property
Name
);
}
}
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" output.Write{0}({1}, element);"
,
MessageOrGroup
,
Number
);
writer
.
WriteLine
(
" output.Write{0}({1}, element);"
,
MessageOrGroup
,
Number
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.Compute{0}Size({1}, element);"
,
MessageOrGroup
,
Number
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.Compute{0}Size({1}, element);"
,
MessageOrGroup
,
Number
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
...
...
src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs
View file @
4cf9e3c6
...
@@ -12,44 +12,44 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -12,44 +12,44 @@ namespace Google.ProtocolBuffers.ProtoGen {
public
void
GenerateMembers
(
TextGenerator
writer
)
{
public
void
GenerateMembers
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();"
,
TypeName
,
Name
);
writer
.
WriteLine
(
"private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();"
,
TypeName
,
Name
);
writer
.
WriteLine
(
"public scg::IList<{0}> {1}List {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public scg::IList<{0}> {1}List {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return pbc::Lists.AsReadOnly({0}_); }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return pbc::Lists.AsReadOnly({0}_); }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
// TODO(jonskeet): Redundant API calls? Possibly - include for portability though. Maybe create an option.
writer
.
WriteLine
(
"public int {0}Count {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public int {0}Count {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return {0}_.Count; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return {0}_.Count; }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" return {0}_[index];"
,
Name
);
writer
.
WriteLine
(
" return {0}_[index];"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
public
void
GenerateBuilderMembers
(
TextGenerator
writer
)
{
// Note: We can return the original list here, because we make it unmodifiable when we build
// 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
,
Capitalized
Name
);
writer
.
WriteLine
(
"public scg::IList<{0}> {1}List {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}_; }}"
,
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}_; }}"
,
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public int {0}Count {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public int {0}Count {{"
,
Property
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}Count; }}"
,
Capitalized
Name
);
writer
.
WriteLine
(
" get {{ return result.{0}Count; }}"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"public {0} Get{1}(int index) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" return result.Get{0}(index);"
,
Capitalized
Name
);
writer
.
WriteLine
(
" return result.Get{0}(index);"
,
Property
Name
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Set{0}(int index, {1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Set{0}(int index, {1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_[index] = value;"
,
Name
);
writer
.
WriteLine
(
" result.{0}_[index] = value;"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Add{0}({1} value) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder Add{0}({1} value) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_.Add(value);"
,
Name
,
TypeName
);
writer
.
WriteLine
(
" result.{0}_.Add(value);"
,
Name
,
TypeName
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{"
,
Capitalized
Name
,
TypeName
);
writer
.
WriteLine
(
"public Builder AddRange{0}(scg::IEnumerable<{1}> values) {{"
,
Property
Name
,
TypeName
);
writer
.
WriteLine
(
" base.AddRange(values, result.{0}_);"
,
Name
);
writer
.
WriteLine
(
" base.AddRange(values, result.{0}_);"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Capitalized
Name
);
writer
.
WriteLine
(
"public Builder Clear{0}() {{"
,
Property
Name
);
writer
.
WriteLine
(
" result.{0}_.Clear();"
,
Name
);
writer
.
WriteLine
(
" result.{0}_.Clear();"
,
Name
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
" return this;"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
...
@@ -66,17 +66,17 @@ namespace Google.ProtocolBuffers.ProtoGen {
...
@@ -66,17 +66,17 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
public
void
GenerateParsingCode
(
TextGenerator
writer
)
{
public
void
GenerateParsingCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"Add{0}(input.Read{1}());"
,
Capitalized
Name
,
CapitalizedTypeName
);
writer
.
WriteLine
(
"Add{0}(input.Read{1}());"
,
Property
Name
,
CapitalizedTypeName
);
}
}
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializationCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" output.Write{0}({1}, element);"
,
CapitalizedTypeName
,
Number
);
writer
.
WriteLine
(
" output.Write{0}({1}, element);"
,
CapitalizedTypeName
,
Number
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
public
void
GenerateSerializedSizeCode
(
TextGenerator
writer
)
{
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Capitalized
Name
);
writer
.
WriteLine
(
"foreach ({0} element in {1}List) {{"
,
TypeName
,
Property
Name
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.Compute{0}Size({1}, element);"
,
CapitalizedTypeName
,
Number
);
writer
.
WriteLine
(
" size += pb::CodedOutputStream.Compute{0}Size({1}, element);"
,
CapitalizedTypeName
,
Number
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
}
}
...
...
src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
View file @
4cf9e3c6
...
@@ -185,7 +185,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -185,7 +185,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
=
internal__static_google_protobuf_UninterpretedOption__Descriptor
.
NestedTypes
[
0
];
=
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
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
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
#
endregion
}
}
#
region
Messages
#
region
Messages
...
@@ -5517,10 +5517,10 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -5517,10 +5517,10 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
get
{
return
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
DescriptorProtoFile
.
internal__static_google_protobuf_UninterpretedOption_NamePart__FieldAccessorTable
;
}
get
{
return
global
::
Google
.
ProtocolBuffers
.
DescriptorProtos
.
DescriptorProtoFile
.
internal__static_google_protobuf_UninterpretedOption_NamePart__FieldAccessorTable
;
}
}
}
private
bool
hasNamePart
;
private
bool
hasNamePart
_
;
private
string
namePart_
=
""
;
private
string
namePart_
=
""
;
public
bool
HasNamePart
{
public
bool
HasNamePart
_
{
get
{
return
hasNamePart
;
}
get
{
return
hasNamePart
_
;
}
}
}
public
string
NamePart_
{
public
string
NamePart_
{
get
{
return
namePart_
;
}
get
{
return
namePart_
;
}
...
@@ -5537,14 +5537,14 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -5537,14 +5537,14 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
public
override
bool
IsInitialized
{
public
override
bool
IsInitialized
{
get
{
get
{
if
(!
hasNamePart
)
return
false
;
if
(!
hasNamePart
_
)
return
false
;
if
(!
hasIsExtension
)
return
false
;
if
(!
hasIsExtension
)
return
false
;
return
true
;
return
true
;
}
}
}
}
public
override
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
public
override
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
HasNamePart
)
{
if
(
HasNamePart
_
)
{
output
.
WriteString
(
1
,
NamePart_
);
output
.
WriteString
(
1
,
NamePart_
);
}
}
if
(
HasIsExtension
)
{
if
(
HasIsExtension
)
{
...
@@ -5560,7 +5560,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -5560,7 +5560,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if
(
size
!=
-
1
)
return
size
;
if
(
size
!=
-
1
)
return
size
;
size
=
0
;
size
=
0
;
if
(
HasNamePart
)
{
if
(
HasNamePart
_
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeStringSize
(
1
,
NamePart_
);
size
+=
pb
::
CodedOutputStream
.
ComputeStringSize
(
1
,
NamePart_
);
}
}
if
(
HasIsExtension
)
{
if
(
HasIsExtension
)
{
...
@@ -5648,7 +5648,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -5648,7 +5648,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
public
override
Builder
MergeFrom
(
NamePart
other
)
{
public
override
Builder
MergeFrom
(
NamePart
other
)
{
if
(
other
==
NamePart
.
DefaultInstance
)
return
this
;
if
(
other
==
NamePart
.
DefaultInstance
)
return
this
;
if
(
other
.
HasNamePart
)
{
if
(
other
.
HasNamePart
_
)
{
NamePart_
=
other
.
NamePart_
;
NamePart_
=
other
.
NamePart_
;
}
}
if
(
other
.
HasIsExtension
)
{
if
(
other
.
HasIsExtension
)
{
...
@@ -5691,20 +5691,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
...
@@ -5691,20 +5691,20 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
}
}
public
bool
HasNamePart
{
public
bool
HasNamePart
_
{
get
{
return
result
.
HasNamePart
;
}
get
{
return
result
.
HasNamePart
_
;
}
}
}
public
string
NamePart_
{
public
string
NamePart_
{
get
{
return
result
.
NamePart_
;
}
get
{
return
result
.
NamePart_
;
}
set
{
SetNamePart
(
value
);
}
set
{
SetNamePart
_
(
value
);
}
}
}
public
Builder
SetNamePart
(
string
value
)
{
public
Builder
SetNamePart
_
(
string
value
)
{
result
.
hasNamePart
=
true
;
result
.
hasNamePart
_
=
true
;
result
.
namePart_
=
value
;
result
.
namePart_
=
value
;
return
this
;
return
this
;
}
}
public
Builder
ClearNamePart
()
{
public
Builder
ClearNamePart
_
()
{
result
.
hasNamePart
=
false
;
result
.
hasNamePart
_
=
false
;
result
.
namePart_
=
""
;
result
.
namePart_
=
""
;
return
this
;
return
this
;
}
}
...
...
src/ProtocolBuffers/FieldAccess/FieldAccessorTable.cs
View file @
4cf9e3c6
...
@@ -54,6 +54,11 @@ namespace Google.ProtocolBuffers.FieldAccess {
...
@@ -54,6 +54,11 @@ namespace Google.ProtocolBuffers.FieldAccess {
/// <summary>
/// <summary>
/// Constructs a FieldAccessorTable for a particular message class.
/// Constructs a FieldAccessorTable for a particular message class.
/// Only one FieldAccessorTable should be constructed per 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>
/// </summary>
/// <param name="descriptor">The type's descriptor</param>
/// <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>
/// <param name="propertyNames">The Pascal-case names of all the field-based properties in the message.</param>
...
...
src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
View file @
4cf9e3c6
...
@@ -55,11 +55,9 @@ namespace Google.ProtocolBuffers.FieldAccess {
...
@@ -55,11 +55,9 @@ namespace Google.ProtocolBuffers.FieldAccess {
}
}
internal
SinglePrimitiveAccessor
(
string
name
)
{
internal
SinglePrimitiveAccessor
(
string
name
)
{
PropertyInfo
messageProperty
=
typeof
(
TMessage
).
GetProperty
(
name
);
string
propertyName
=
name
==
typeof
(
TMessage
).
Name
?
name
+
"_"
:
name
;
PropertyInfo
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
);
PropertyInfo
messageProperty
=
typeof
(
TMessage
).
GetProperty
(
propertyName
);
if
(
builderProperty
==
null
)
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
);
PropertyInfo
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
);
// FIXME!
if
(
builderProperty
==
null
)
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
propertyName
);
// FIXME!
PropertyInfo
hasProperty
=
typeof
(
TMessage
).
GetProperty
(
"Has"
+
name
);
PropertyInfo
hasProperty
=
typeof
(
TMessage
).
GetProperty
(
"Has"
+
name
);
MethodInfo
clearMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Clear"
+
name
,
Type
.
EmptyTypes
);
MethodInfo
clearMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Clear"
+
name
,
Type
.
EmptyTypes
);
if
(
messageProperty
==
null
||
builderProperty
==
null
||
hasProperty
==
null
||
clearMethod
==
null
)
{
if
(
messageProperty
==
null
||
builderProperty
==
null
||
hasProperty
==
null
||
clearMethod
==
null
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment