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
eb70bd0b
Commit
eb70bd0b
authored
Jun 12, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the AddressBook tutorial to reflect the mutable design.
parent
96ddf01a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
247 additions
and
1013 deletions
+247
-1013
generate_protos.sh
csharp/generate_protos.sh
+3
-41
AddPerson.cs
csharp/src/AddressBook/AddPerson.cs
+10
-9
Addressbook.cs
csharp/src/AddressBook/Addressbook.cs
+209
-934
ListPeople.cs
csharp/src/AddressBook/ListPeople.cs
+4
-4
SampleUsage.cs
csharp/src/AddressBook/SampleUsage.cs
+21
-25
No files found.
csharp/generate_protos.sh
View file @
eb70bd0b
...
...
@@ -42,52 +42,14 @@ $PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffers/DescriptorProtos \
src/google/protobuf/descriptor_proto_file.proto
rm
src/google/protobuf/descriptor_proto_file.proto
# ProtocolBuffers.Test protos
$PROTOC
-Isrc
--csharp_out
=
csharp/src/ProtocolBuffers.Test/TestProtos
\
src/google/protobuf/unittest.proto
\
src/google/protobuf/unittest_custom_options.proto
\
src/google/protobuf/unittest_drop_unknown_fields.proto
\
src/google/protobuf/unittest_enormous_descriptor.proto
\
src/google/protobuf/unittest_import.proto
\
src/google/protobuf/unittest_import_public.proto
\
src/google/protobuf/unittest_mset.proto
\
src/google/protobuf/unittest_optimize_for.proto
\
src/google/protobuf/unittest_no_field_presence.proto
\
src/google/protobuf/unknown_enum_test.proto
src/google/protobuf/unittest_proto3.proto
\
src/google/protobuf/unittest_import_proto3.proto
\
src/google/protobuf/unittest_import_public_proto3.proto
$PROTOC
-Icsharp
/protos/extest
--csharp_out
=
csharp/src/ProtocolBuffers.Test/TestProtos
\
csharp/protos/extest/unittest_extras_xmltest.proto
\
csharp/protos/extest/unittest_issues.proto
$PROTOC
-Ibenchmarks
--csharp_out
=
csharp/src/ProtocolBuffers.Test/TestProtos
\
benchmarks/google_size.proto
\
benchmarks/google_speed.proto
# ProtocolBuffersLite.Test protos
$PROTOC
-Isrc
--csharp_out
=
csharp/src/ProtocolBuffersLite.Test/TestProtos
\
src/google/protobuf/unittest.proto
\
src/google/protobuf/unittest_import.proto
\
src/google/protobuf/unittest_import_lite.proto
\
src/google/protobuf/unittest_import_public.proto
\
src/google/protobuf/unittest_import_public_lite.proto
\
src/google/protobuf/unittest_lite.proto
\
src/google/protobuf/unittest_lite_imports_nonlite.proto
$PROTOC
-Icsharp
/protos/extest
--csharp_out
=
csharp/src/ProtocolBuffersLite.Test/TestProtos
\
csharp/protos/extest/unittest_extras_full.proto
\
csharp/protos/extest/unittest_extras_lite.proto
# TODO(jonskeet): Remove fixup; see issue #307
sed
-i
-e
's/RepeatedFieldsGenerator\.Group/RepeatedFieldsGenerator.Types.Group/g'
\
csharp/src/ProtocolBuffers.Test/TestProtos/Unittest.cs
\
csharp/src/ProtocolBuffersLite.Test/TestProtos/Unittest.cs
\
csharp/src/ProtocolBuffersLite.Test/TestProtos/UnittestLite.cs
# TODO(jonskeet): Remove fixup
sed
-i
-e
's/DescriptorProtos\.Descriptor\./DescriptorProtos.DescriptorProtoFile./g'
\
csharp/src/ProtocolBuffers.Test/TestProtos/UnittestCustomOptions.cs
# AddressBook sample protos
$PROTOC
-Iexamples
--csharp_out
=
csharp/src/AddressBook
\
examples/addressbook.proto
csharp/src/AddressBook/AddPerson.cs
View file @
eb70bd0b
...
...
@@ -36,6 +36,7 @@
using
System
;
using
System.IO
;
using
Google.Protobuf
;
namespace
Google.ProtocolBuffers.Examples.AddressBook
{
...
...
@@ -46,7 +47,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
/// </summary>
private
static
Person
PromptForAddress
(
TextReader
input
,
TextWriter
output
)
{
Person
.
Builder
person
=
Person
.
CreateBuilder
();
Person
person
=
new
Person
();
output
.
Write
(
"Enter person ID: "
);
person
.
Id
=
int
.
Parse
(
input
.
ReadLine
());
...
...
@@ -70,8 +71,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
break
;
}
Person
.
Types
.
PhoneNumber
.
Builder
phoneNumber
=
Person
.
Types
.
PhoneNumber
.
CreateBuilder
().
SetNumber
(
number
);
Person
.
Types
.
PhoneNumber
phoneNumber
=
new
Person
.
Types
.
PhoneNumber
{
Number
=
number
};
output
.
Write
(
"Is this a mobile, home, or work phone? "
);
String
type
=
input
.
ReadLine
();
...
...
@@ -91,9 +91,9 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
break
;
}
person
.
AddPhone
(
phoneNumber
);
person
.
Phone
.
Add
(
phoneNumber
);
}
return
person
.
Build
()
;
return
person
;
}
/// <summary>
...
...
@@ -108,27 +108,28 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
return
-
1
;
}
AddressBook
.
Builder
addressBook
=
AddressBook
.
CreateBuilder
()
;
AddressBook
addressBook
;
if
(
File
.
Exists
(
args
[
0
]))
{
using
(
Stream
file
=
File
.
OpenRead
(
args
[
0
]))
{
addressBook
.
Merg
eFrom
(
file
);
addressBook
=
AddressBook
.
Parser
.
Pars
eFrom
(
file
);
}
}
else
{
Console
.
WriteLine
(
"{0}: File not found. Creating a new file."
,
args
[
0
]);
addressBook
=
new
AddressBook
();
}
// Add an address.
addressBook
.
AddPerson
(
PromptForAddress
(
Console
.
In
,
Console
.
Out
));
addressBook
.
Person
.
Add
(
PromptForAddress
(
Console
.
In
,
Console
.
Out
));
// Write the new address book back to disk.
using
(
Stream
output
=
File
.
OpenWrite
(
args
[
0
]))
{
addressBook
.
Build
().
WriteTo
(
output
);
addressBook
.
WriteTo
(
output
);
}
return
0
;
}
...
...
csharp/src/AddressBook/Addressbook.cs
View file @
eb70bd0b
...
...
@@ -3,26 +3,22 @@
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using
pb
=
global
::
Google
.
Proto
colBuffers
;
using
pbc
=
global
::
Google
.
Proto
colBuffers
.
Collections
;
using
pbd
=
global
::
Google
.
Proto
colBuffers
.
Descriptors
;
using
pb
=
global
::
Google
.
Proto
buf
;
using
pbc
=
global
::
Google
.
Proto
buf
.
Collections
;
using
pbd
=
global
::
Google
.
Proto
buf
.
Descriptors
;
using
scg
=
global
::
System
.
Collections
.
Generic
;
namespace
Google.ProtocolBuffers.Examples.AddressBook
{
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
static
partial
class
Addressbook
{
#
region
Extension
registration
public
static
void
RegisterAllExtensions
(
pb
::
ExtensionRegistry
registry
)
{
}
#
endregion
#
region
Static
variables
internal
static
pbd
::
MessageDescriptor
internal__static_tutorial_Person__Descriptor
;
internal
static
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Builder
>
internal__static_tutorial_Person__FieldAccessorTable
;
internal
static
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>
internal__static_tutorial_Person__FieldAccessorTable
;
internal
static
pbd
::
MessageDescriptor
internal__static_tutorial_Person_PhoneNumber__Descriptor
;
internal
static
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
.
Builder
>
internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable
;
internal
static
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>
internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable
;
internal
static
pbd
::
MessageDescriptor
internal__static_tutorial_AddressBook__Descriptor
;
internal
static
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
AddressBook
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
AddressBook
.
Builder
>
internal__static_tutorial_AddressBook__FieldAccessorTable
;
internal
static
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
AddressBook
>
internal__static_tutorial_AddressBook__FieldAccessorTable
;
#
endregion
#
region
Descriptor
public
static
pbd
::
FileDescriptor
Descriptor
{
...
...
@@ -46,19 +42,16 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
descriptor
=
root
;
internal__static_tutorial_Person__Descriptor
=
Descriptor
.
MessageTypes
[
0
];
internal__static_tutorial_Person__FieldAccessorTable
=
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Builder
>(
internal__static_tutorial_Person__Descriptor
,
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>(
internal__static_tutorial_Person__Descriptor
,
new
string
[]
{
"Name"
,
"Id"
,
"Email"
,
"Phone"
,
});
internal__static_tutorial_Person_PhoneNumber__Descriptor
=
internal__static_tutorial_Person__Descriptor
.
NestedTypes
[
0
];
internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable
=
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
.
Builder
>(
internal__static_tutorial_Person_PhoneNumber__Descriptor
,
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>(
internal__static_tutorial_Person_PhoneNumber__Descriptor
,
new
string
[]
{
"Number"
,
"Type"
,
});
internal__static_tutorial_AddressBook__Descriptor
=
Descriptor
.
MessageTypes
[
1
];
internal__static_tutorial_AddressBook__FieldAccessorTable
=
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
AddressBook
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
AddressBook
.
Builder
>(
internal__static_tutorial_AddressBook__Descriptor
,
new
pb
::
FieldAccess
.
FieldAccessorTable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
AddressBook
>(
internal__static_tutorial_AddressBook__Descriptor
,
new
string
[]
{
"Person"
,
});
pb
::
ExtensionRegistry
registry
=
pb
::
ExtensionRegistry
.
CreateInstance
();
RegisterAllExtensions
(
registry
);
return
registry
;
};
pbd
::
FileDescriptor
.
InternalBuildGeneratedFileFrom
(
descriptorData
,
new
pbd
::
FileDescriptor
[]
{
...
...
@@ -69,1086 +62,368 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
}
#
region
Messages
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
sealed
partial
class
Person
:
pb
::
GeneratedMessage
<
Person
,
Person
.
Builder
>
{
private
Person
()
{
}
private
static
readonly
Person
defaultInstance
=
new
Person
().
MakeReadOnly
();
private
static
readonly
string
[]
_personFieldNames
=
new
string
[]
{
"email"
,
"id"
,
"name"
,
"phone"
};
private
static
readonly
uint
[]
_personFieldTags
=
new
uint
[]
{
26
,
16
,
10
,
34
};
public
static
Person
DefaultInstance
{
get
{
return
defaultInstance
;
}
}
public
override
Person
DefaultInstanceForType
{
get
{
return
DefaultInstance
;
}
}
protected
override
Person
ThisMessage
{
get
{
return
this
;
}
}
public
sealed
partial
class
Person
:
pb
::
IMessage
<
Person
>,
global
::
System
.
IEquatable
<
Person
>
{
private
static
readonly
pb
::
MessageParser
<
Person
>
_parser
=
new
pb
::
MessageParser
<
Person
>(()
=>
new
Person
());
public
static
pb
::
MessageParser
<
Person
>
Parser
{
get
{
return
_parser
;
}
}
private
static
readonly
string
[]
_fieldNames
=
new
string
[]
{
"email"
,
"id"
,
"name"
,
"phone"
};
private
static
readonly
uint
[]
_fieldTags
=
new
uint
[]
{
26
,
16
,
10
,
34
};
public
static
pbd
::
MessageDescriptor
Descriptor
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_Person__Descriptor
;
}
}
p
rotected
override
pb
::
FieldAccess
.
FieldAccessorTable
<
Person
,
Person
.
Builder
>
InternalFieldAccessor
s
{
p
ublic
pb
::
FieldAccess
.
FieldAccessorTable
<
Person
>
Field
s
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_Person__FieldAccessorTable
;
}
}
#
region
Nested
types
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
static
partial
class
Types
{
public
enum
PhoneType
{
MOBILE
=
0
,
HOME
=
1
,
WORK
=
2
,
}
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
sealed
partial
class
PhoneNumber
:
pb
::
GeneratedMessage
<
PhoneNumber
,
PhoneNumber
.
Builder
>
{
private
PhoneNumber
()
{
}
private
static
readonly
PhoneNumber
defaultInstance
=
new
PhoneNumber
().
MakeReadOnly
();
private
static
readonly
string
[]
_phoneNumberFieldNames
=
new
string
[]
{
"number"
,
"type"
};
private
static
readonly
uint
[]
_phoneNumberFieldTags
=
new
uint
[]
{
10
,
16
};
public
static
PhoneNumber
DefaultInstance
{
get
{
return
defaultInstance
;
}
}
public
override
PhoneNumber
DefaultInstanceForType
{
get
{
return
DefaultInstance
;
}
}
protected
override
PhoneNumber
ThisMessage
{
get
{
return
this
;
}
}
public
static
pbd
::
MessageDescriptor
Descriptor
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_Person_PhoneNumber__Descriptor
;
}
}
protected
override
pb
::
FieldAccess
.
FieldAccessorTable
<
PhoneNumber
,
PhoneNumber
.
Builder
>
InternalFieldAccessors
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable
;
}
}
public
const
int
NumberFieldNumber
=
1
;
private
bool
hasNumber
;
private
string
number_
=
""
;
public
bool
HasNumber
{
get
{
return
hasNumber
;
}
}
public
string
Number
{
get
{
return
number_
;
}
}
public
const
int
TypeFieldNumber
=
2
;
private
bool
hasType
;
private
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
type_
=
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
.
HOME
;
public
bool
HasType
{
get
{
return
hasType
;
}
}
public
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
Type
{
get
{
return
type_
;
}
}
public
override
bool
IsInitialized
{
get
{
if
(!
hasNumber
)
return
false
;
return
true
;
}
}
public
override
void
WriteTo
(
pb
::
ICodedOutputStream
output
)
{
CalcSerializedSize
();
string
[]
field_names
=
_phoneNumberFieldNames
;
if
(
hasNumber
)
{
output
.
WriteString
(
1
,
field_names
[
0
],
Number
);
}
if
(
hasType
)
{
output
.
WriteEnum
(
2
,
field_names
[
1
],
(
int
)
Type
,
Type
);
}
UnknownFields
.
WriteTo
(
output
);
}
private
int
memoizedSerializedSize
=
-
1
;
public
override
int
SerializedSize
{
get
{
int
size
=
memoizedSerializedSize
;
if
(
size
!=
-
1
)
return
size
;
return
CalcSerializedSize
();
}
}
private
int
CalcSerializedSize
()
{
int
size
=
memoizedSerializedSize
;
if
(
size
!=
-
1
)
return
size
;
size
=
0
;
if
(
hasNumber
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeStringSize
(
1
,
Number
);
}
if
(
hasType
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeEnumSize
(
2
,
(
int
)
Type
);
}
size
+=
UnknownFields
.
SerializedSize
;
memoizedSerializedSize
=
size
;
return
size
;
}
public
static
PhoneNumber
ParseFrom
(
pb
::
ByteString
data
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
)).
BuildParsed
();
}
public
static
PhoneNumber
ParseFrom
(
pb
::
ByteString
data
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
,
extensionRegistry
)).
BuildParsed
();
}
public
static
PhoneNumber
ParseFrom
(
byte
[]
data
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
)).
BuildParsed
();
}
public
static
PhoneNumber
ParseFrom
(
byte
[]
data
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
,
extensionRegistry
)).
BuildParsed
();
}
public
static
PhoneNumber
ParseFrom
(
global
::
System
.
IO
.
Stream
input
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
)).
BuildParsed
();
}
public
static
PhoneNumber
ParseFrom
(
global
::
System
.
IO
.
Stream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
,
extensionRegistry
)).
BuildParsed
();
}
public
static
PhoneNumber
ParseDelimitedFrom
(
global
::
System
.
IO
.
Stream
input
)
{
return
CreateBuilder
().
MergeDelimitedFrom
(
input
).
BuildParsed
();
}
public
static
PhoneNumber
ParseDelimitedFrom
(
global
::
System
.
IO
.
Stream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
CreateBuilder
().
MergeDelimitedFrom
(
input
,
extensionRegistry
).
BuildParsed
();
}
public
static
PhoneNumber
ParseFrom
(
pb
::
ICodedInputStream
input
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
)).
BuildParsed
();
}
public
static
PhoneNumber
ParseFrom
(
pb
::
ICodedInputStream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
,
extensionRegistry
)).
BuildParsed
();
}
private
PhoneNumber
MakeReadOnly
()
{
return
this
;
}
public
static
Builder
CreateBuilder
()
{
return
new
Builder
();
}
public
override
Builder
ToBuilder
()
{
return
CreateBuilder
(
this
);
}
public
override
Builder
CreateBuilderForType
()
{
return
new
Builder
();
}
public
static
Builder
CreateBuilder
(
PhoneNumber
prototype
)
{
return
new
Builder
(
prototype
);
}
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
sealed
partial
class
Builder
:
pb
::
GeneratedBuilder
<
PhoneNumber
,
Builder
>
{
protected
override
Builder
ThisBuilder
{
get
{
return
this
;
}
}
public
Builder
()
{
result
=
DefaultInstance
;
resultIsReadOnly
=
true
;
}
internal
Builder
(
PhoneNumber
cloneFrom
)
{
result
=
cloneFrom
;
resultIsReadOnly
=
true
;
}
private
bool
resultIsReadOnly
;
private
PhoneNumber
result
;
private
PhoneNumber
PrepareBuilder
()
{
if
(
resultIsReadOnly
)
{
PhoneNumber
original
=
result
;
result
=
new
PhoneNumber
();
resultIsReadOnly
=
false
;
MergeFrom
(
original
);
public
Person
()
{
}
public
Person
(
Person
other
)
{
MergeFrom
(
other
);
}
return
result
;
}
public
override
bool
IsInitialized
{
get
{
return
result
.
IsInitialized
;
}
}
protected
override
PhoneNumber
MessageBeingBuilt
{
get
{
return
PrepareBuilder
();
}
}
public
override
Builder
Clear
()
{
result
=
DefaultInstance
;
resultIsReadOnly
=
true
;
return
this
;
}
public
override
Builder
Clone
()
{
if
(
resultIsReadOnly
)
{
return
new
Builder
(
result
);
}
else
{
return
new
Builder
().
MergeFrom
(
result
);
}
}
public
override
pbd
::
MessageDescriptor
DescriptorForType
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
.
Descriptor
;
}
}
public
override
PhoneNumber
DefaultInstanceForType
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
.
DefaultInstance
;
}
}
public
override
PhoneNumber
BuildPartial
()
{
if
(
resultIsReadOnly
)
{
return
result
;
}
resultIsReadOnly
=
true
;
return
result
.
MakeReadOnly
();
}
public
override
Builder
MergeFrom
(
pb
::
IMessage
other
)
{
if
(
other
is
PhoneNumber
)
{
return
MergeFrom
((
PhoneNumber
)
other
);
}
else
{
base
.
MergeFrom
(
other
);
return
this
;
}
}
public
override
Builder
MergeFrom
(
PhoneNumber
other
)
{
if
(
other
==
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
.
DefaultInstance
)
return
this
;
PrepareBuilder
();
if
(
other
.
HasNumber
)
{
Number
=
other
.
Number
;
}
if
(
other
.
HasType
)
{
Type
=
other
.
Type
;
}
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
}
public
override
Builder
MergeFrom
(
pb
::
ICodedInputStream
input
)
{
return
MergeFrom
(
input
,
pb
::
ExtensionRegistry
.
Empty
);
}
public
override
Builder
MergeFrom
(
pb
::
ICodedInputStream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
PrepareBuilder
();
pb
::
UnknownFieldSet
.
Builder
unknownFields
=
null
;
uint
tag
;
string
field_name
;
while
(
input
.
ReadTag
(
out
tag
,
out
field_name
))
{
if
(
tag
==
0
&&
field_name
!=
null
)
{
int
field_ordinal
=
global
::
System
.
Array
.
BinarySearch
(
_phoneNumberFieldNames
,
field_name
,
global
::
System
.
StringComparer
.
Ordinal
);
if
(
field_ordinal
>=
0
)
tag
=
_phoneNumberFieldTags
[
field_ordinal
];
else
{
if
(
unknownFields
==
null
)
{
unknownFields
=
pb
::
UnknownFieldSet
.
CreateBuilder
(
this
.
UnknownFields
);
}
ParseUnknownField
(
input
,
unknownFields
,
extensionRegistry
,
tag
,
field_name
);
continue
;
}
}
switch
(
tag
)
{
case
0
:
{
throw
pb
::
InvalidProtocolBufferException
.
InvalidTag
();
}
default
:
{
if
(
pb
::
WireFormat
.
IsEndGroupTag
(
tag
))
{
if
(
unknownFields
!=
null
)
{
this
.
UnknownFields
=
unknownFields
.
Build
();
}
return
this
;
}
if
(
unknownFields
==
null
)
{
unknownFields
=
pb
::
UnknownFieldSet
.
CreateBuilder
(
this
.
UnknownFields
);
}
ParseUnknownField
(
input
,
unknownFields
,
extensionRegistry
,
tag
,
field_name
);
break
;
}
case
10
:
{
result
.
hasNumber
=
input
.
ReadString
(
ref
result
.
number_
);
break
;
}
case
16
:
{
object
unknown
;
if
(
input
.
ReadEnum
(
ref
result
.
type_
,
out
unknown
))
{
result
.
hasType
=
true
;
}
else
if
(
unknown
is
int
)
{
if
(
unknownFields
==
null
)
{
unknownFields
=
pb
::
UnknownFieldSet
.
CreateBuilder
(
this
.
UnknownFields
);
}
unknownFields
.
MergeVarintField
(
2
,
(
ulong
)(
int
)
unknown
);
}
break
;
}
}
}
if
(
unknownFields
!=
null
)
{
this
.
UnknownFields
=
unknownFields
.
Build
();
}
return
this
;
}
public
bool
HasNumber
{
get
{
return
result
.
hasNumber
;
}
}
public
string
Number
{
get
{
return
result
.
Number
;
}
set
{
SetNumber
(
value
);
}
}
public
Builder
SetNumber
(
string
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
PrepareBuilder
();
result
.
hasNumber
=
true
;
result
.
number_
=
value
;
return
this
;
}
public
Builder
ClearNumber
()
{
PrepareBuilder
();
result
.
hasNumber
=
false
;
result
.
number_
=
""
;
return
this
;
}
public
bool
HasType
{
get
{
return
result
.
hasType
;
}
}
public
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
Type
{
get
{
return
result
.
Type
;
}
set
{
SetType
(
value
);
}
}
public
Builder
SetType
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
value
)
{
PrepareBuilder
();
result
.
hasType
=
true
;
result
.
type_
=
value
;
return
this
;
}
public
Builder
ClearType
()
{
PrepareBuilder
();
result
.
hasType
=
false
;
result
.
type_
=
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
.
HOME
;
return
this
;
}
}
static
PhoneNumber
()
{
object
.
ReferenceEquals
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
Descriptor
,
null
);
}
}
}
#
endregion
public
const
int
NameFieldNumber
=
1
;
private
bool
hasName
;
private
string
name_
=
""
;
public
bool
HasName
{
get
{
return
hasName
;
}
}
public
string
Name
{
get
{
return
name_
;
}
set
{
name_
=
value
??
""
;
}
}
public
const
int
IdFieldNumber
=
2
;
private
bool
hasId
;
private
int
id_
;
public
bool
HasId
{
get
{
return
hasId
;
}
}
public
int
Id
{
get
{
return
id_
;
}
set
{
id_
=
value
;
}
}
public
const
int
EmailFieldNumber
=
3
;
private
bool
hasEmail
;
private
string
email_
=
""
;
public
bool
HasEmail
{
get
{
return
hasEmail
;
}
}
public
string
Email
{
get
{
return
email_
;
}
set
{
email_
=
value
??
""
;
}
}
public
const
int
PhoneFieldNumber
=
4
;
private
pbc
::
PopsicleList
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>
phone_
=
new
pbc
::
PopsicleList
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>();
public
scg
::
IList
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>
PhoneList
{
private
readonly
pbc
::
RepeatedField
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>
phone_
=
new
pbc
::
RepeatedField
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>();
public
pbc
::
RepeatedField
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>
Phone
{
get
{
return
phone_
;
}
}
public
int
PhoneCount
{
get
{
return
phone_
.
Count
;
}
}
public
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
GetPhone
(
int
index
)
{
return
phone_
[
index
];
public
override
bool
Equals
(
object
other
)
{
return
Equals
(
other
as
Person
);
}
public
override
bool
IsInitialized
{
get
{
if
(!
hasName
)
return
false
;
if
(!
hasId
)
return
false
;
foreach
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
element
in
PhoneList
)
{
if
(!
element
.
IsInitialized
)
return
false
;
public
bool
Equals
(
Person
other
)
{
if
(
ReferenceEquals
(
other
,
null
))
{
return
false
;
}
if
(
ReferenceEquals
(
other
,
this
))
{
return
true
;
}
if
(
Name
!=
other
.
Name
)
return
false
;
if
(
Id
!=
other
.
Id
)
return
false
;
if
(
Email
!=
other
.
Email
)
return
false
;
if
(!
phone_
.
Equals
(
other
.
phone_
))
return
false
;
return
true
;
}
public
override
void
WriteTo
(
pb
::
ICodedOutputStream
output
)
{
CalcSerializedSize
();
string
[]
field_names
=
_personFieldNames
;
if
(
hasName
)
{
output
.
WriteString
(
1
,
field_names
[
2
],
Name
);
public
override
int
GetHashCode
()
{
int
hash
=
0
;
if
(
Name
!=
""
)
hash
^=
Name
.
GetHashCode
();
if
(
Id
!=
0
)
hash
^=
Id
.
GetHashCode
();
if
(
Email
!=
""
)
hash
^=
Email
.
GetHashCode
();
hash
^=
phone_
.
GetHashCode
();
return
hash
;
}
if
(
hasId
)
{
output
.
WriteInt32
(
2
,
field_names
[
1
],
Id
);
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
!=
""
)
{
output
.
WriteString
(
1
,
Name
);
}
if
(
hasEmail
)
{
output
.
Write
String
(
3
,
field_names
[
0
],
Email
);
if
(
Id
!=
0
)
{
output
.
Write
Int32
(
2
,
Id
);
}
if
(
phone_
.
Count
>
0
)
{
output
.
Write
MessageArray
(
4
,
field_names
[
3
],
phone_
);
if
(
Email
!=
""
)
{
output
.
Write
String
(
3
,
Email
);
}
UnknownFields
.
WriteTo
(
output
);
output
.
WriteMessageArray
(
4
,
phone_
);
}
private
int
memoizedSerializedSize
=
-
1
;
public
override
int
SerializedSize
{
get
{
int
size
=
memoizedSerializedSize
;
if
(
size
!=
-
1
)
return
size
;
return
CalcSerializedSize
();
}
}
private
int
CalcSerializedSize
()
{
int
size
=
memoizedSerializedSize
;
if
(
size
!=
-
1
)
return
size
;
size
=
0
;
if
(
hasName
)
{
public
int
CalculateSize
()
{
int
size
=
0
;
if
(
Name
!=
""
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeStringSize
(
1
,
Name
);
}
if
(
hasId
)
{
if
(
Id
!=
0
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeInt32Size
(
2
,
Id
);
}
if
(
hasEmail
)
{
if
(
Email
!=
""
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeStringSize
(
3
,
Email
);
}
foreach
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
element
in
PhoneList
)
{
foreach
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
element
in
phone_
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeMessageSize
(
4
,
element
);
}
size
+=
UnknownFields
.
SerializedSize
;
memoizedSerializedSize
=
size
;
return
size
;
}
public
static
Person
ParseFrom
(
pb
::
ByteString
data
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
)).
BuildParsed
();
}
public
static
Person
ParseFrom
(
pb
::
ByteString
data
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
,
extensionRegistry
)).
BuildParsed
();
}
public
static
Person
ParseFrom
(
byte
[]
data
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
)).
BuildParsed
();
}
public
static
Person
ParseFrom
(
byte
[]
data
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
,
extensionRegistry
)).
BuildParsed
();
}
public
static
Person
ParseFrom
(
global
::
System
.
IO
.
Stream
input
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
)).
BuildParsed
();
}
public
static
Person
ParseFrom
(
global
::
System
.
IO
.
Stream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
,
extensionRegistry
)).
BuildParsed
();
}
public
static
Person
ParseDelimitedFrom
(
global
::
System
.
IO
.
Stream
input
)
{
return
CreateBuilder
().
MergeDelimitedFrom
(
input
).
BuildParsed
();
}
public
static
Person
ParseDelimitedFrom
(
global
::
System
.
IO
.
Stream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
CreateBuilder
().
MergeDelimitedFrom
(
input
,
extensionRegistry
).
BuildParsed
();
}
public
static
Person
ParseFrom
(
pb
::
ICodedInputStream
input
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
)).
BuildParsed
();
}
public
static
Person
ParseFrom
(
pb
::
ICodedInputStream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
,
extensionRegistry
)).
BuildParsed
();
}
private
Person
MakeReadOnly
()
{
phone_
.
MakeReadOnly
();
return
this
;
}
public
static
Builder
CreateBuilder
()
{
return
new
Builder
();
}
public
override
Builder
ToBuilder
()
{
return
CreateBuilder
(
this
);
}
public
override
Builder
CreateBuilderForType
()
{
return
new
Builder
();
}
public
static
Builder
CreateBuilder
(
Person
prototype
)
{
return
new
Builder
(
prototype
);
}
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
sealed
partial
class
Builder
:
pb
::
GeneratedBuilder
<
Person
,
Builder
>
{
protected
override
Builder
ThisBuilder
{
get
{
return
this
;
}
}
public
Builder
()
{
result
=
DefaultInstance
;
resultIsReadOnly
=
true
;
}
internal
Builder
(
Person
cloneFrom
)
{
result
=
cloneFrom
;
resultIsReadOnly
=
true
;
}
private
bool
resultIsReadOnly
;
private
Person
result
;
private
Person
PrepareBuilder
()
{
if
(
resultIsReadOnly
)
{
Person
original
=
result
;
result
=
new
Person
();
resultIsReadOnly
=
false
;
MergeFrom
(
original
);
}
return
result
;
}
public
override
bool
IsInitialized
{
get
{
return
result
.
IsInitialized
;
}
}
protected
override
Person
MessageBeingBuilt
{
get
{
return
PrepareBuilder
();
}
}
public
override
Builder
Clear
()
{
result
=
DefaultInstance
;
resultIsReadOnly
=
true
;
return
this
;
}
public
override
Builder
Clone
()
{
if
(
resultIsReadOnly
)
{
return
new
Builder
(
result
);
}
else
{
return
new
Builder
().
MergeFrom
(
result
);
}
}
public
override
pbd
::
MessageDescriptor
DescriptorForType
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Descriptor
;
}
}
public
override
Person
DefaultInstanceForType
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
DefaultInstance
;
}
}
public
override
Person
BuildPartial
()
{
if
(
resultIsReadOnly
)
{
return
result
;
}
resultIsReadOnly
=
true
;
return
result
.
MakeReadOnly
();
}
public
override
Builder
MergeFrom
(
pb
::
IMessage
other
)
{
if
(
other
is
Person
)
{
return
MergeFrom
((
Person
)
other
);
}
else
{
base
.
MergeFrom
(
other
);
return
this
;
public
void
MergeFrom
(
Person
other
)
{
if
(
other
==
null
)
{
return
;
}
}
public
override
Builder
MergeFrom
(
Person
other
)
{
if
(
other
==
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
DefaultInstance
)
return
this
;
PrepareBuilder
();
if
(
other
.
HasName
)
{
if
(
other
.
Name
!=
""
)
{
Name
=
other
.
Name
;
}
if
(
other
.
HasId
)
{
if
(
other
.
Id
!=
0
)
{
Id
=
other
.
Id
;
}
if
(
other
.
HasEmail
)
{
if
(
other
.
Email
!=
""
)
{
Email
=
other
.
Email
;
}
if
(
other
.
phone_
.
Count
!=
0
)
{
result
.
phone_
.
Add
(
other
.
phone_
);
}
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
}
public
override
Builder
MergeFrom
(
pb
::
ICodedInputStream
input
)
{
return
MergeFrom
(
input
,
pb
::
ExtensionRegistry
.
Empty
);
phone_
.
Add
(
other
.
phone_
);
}
public
override
Builder
MergeFrom
(
pb
::
ICodedInputStream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
PrepareBuilder
();
pb
::
UnknownFieldSet
.
Builder
unknownFields
=
null
;
public
void
MergeFrom
(
pb
::
CodedInputStream
input
)
{
uint
tag
;
string
field_name
;
while
(
input
.
ReadTag
(
out
tag
,
out
field_name
))
{
if
(
tag
==
0
&&
field_name
!=
null
)
{
int
field_ordinal
=
global
::
System
.
Array
.
BinarySearch
(
_personFieldNames
,
field_name
,
global
::
System
.
StringComparer
.
Ordinal
);
if
(
field_ordinal
>=
0
)
tag
=
_personFieldTags
[
field_ordinal
];
else
{
if
(
unknownFields
==
null
)
{
unknownFields
=
pb
::
UnknownFieldSet
.
CreateBuilder
(
this
.
UnknownFields
);
}
ParseUnknownField
(
input
,
unknownFields
,
extensionRegistry
,
tag
,
field_name
);
continue
;
}
}
switch
(
tag
)
{
case
0
:
{
while
(
input
.
ReadTag
(
out
tag
))
{
switch
(
tag
)
{
case
0
:
throw
pb
::
InvalidProtocolBufferException
.
InvalidTag
();
}
default
:
{
default
:
if
(
pb
::
WireFormat
.
IsEndGroupTag
(
tag
))
{
if
(
unknownFields
!=
null
)
{
this
.
UnknownFields
=
unknownFields
.
Build
();
}
return
this
;
}
if
(
unknownFields
==
null
)
{
unknownFields
=
pb
::
UnknownFieldSet
.
CreateBuilder
(
this
.
UnknownFields
);
return
;
}
ParseUnknownField
(
input
,
unknownFields
,
extensionRegistry
,
tag
,
field_name
);
break
;
}
case
10
:
{
result
.
hasName
=
input
.
ReadString
(
ref
result
.
name_
);
name_
=
input
.
ReadString
(
);
break
;
}
case
16
:
{
result
.
hasId
=
input
.
ReadInt32
(
ref
result
.
id_
);
id_
=
input
.
ReadInt32
(
);
break
;
}
case
26
:
{
result
.
hasEmail
=
input
.
ReadString
(
ref
result
.
email_
);
email_
=
input
.
ReadString
(
);
break
;
}
case
34
:
{
input
.
ReadMessageArray
(
tag
,
field_name
,
result
.
phone_
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
.
DefaultInstance
,
extensionRegistry
);
input
.
ReadMessageArray
(
tag
,
phone_
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
.
Parser
);
break
;
}
}
}
if
(
unknownFields
!=
null
)
{
this
.
UnknownFields
=
unknownFields
.
Build
();
}
return
this
;
}
public
bool
HasName
{
get
{
return
result
.
hasName
;
}
}
public
string
Name
{
get
{
return
result
.
Name
;
}
set
{
SetName
(
value
);
}
}
public
Builder
SetName
(
string
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
PrepareBuilder
();
result
.
hasName
=
true
;
result
.
name_
=
value
;
return
this
;
}
public
Builder
ClearName
()
{
PrepareBuilder
();
result
.
hasName
=
false
;
result
.
name_
=
""
;
return
this
;
#
region
Nested
types
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
static
partial
class
Types
{
public
enum
PhoneType
{
MOBILE
=
0
,
HOME
=
1
,
WORK
=
2
,
}
public
bool
HasId
{
get
{
return
result
.
hasId
;
}
}
public
int
Id
{
get
{
return
result
.
Id
;
}
set
{
SetId
(
value
);
}
}
public
Builder
SetId
(
int
value
)
{
PrepareBuilder
();
result
.
hasId
=
true
;
result
.
id_
=
value
;
return
this
;
}
public
Builder
ClearId
()
{
PrepareBuilder
();
result
.
hasId
=
false
;
result
.
id_
=
0
;
return
this
;
}
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
sealed
partial
class
PhoneNumber
:
pb
::
IMessage
<
PhoneNumber
>,
global
::
System
.
IEquatable
<
PhoneNumber
>
{
private
static
readonly
pb
::
MessageParser
<
PhoneNumber
>
_parser
=
new
pb
::
MessageParser
<
PhoneNumber
>(()
=>
new
PhoneNumber
());
public
static
pb
::
MessageParser
<
PhoneNumber
>
Parser
{
get
{
return
_parser
;
}
}
public
bool
HasEmail
{
get
{
return
result
.
hasEmail
;
}
}
public
string
Email
{
get
{
return
result
.
Email
;
}
set
{
SetEmail
(
value
);
}
}
public
Builder
SetEmail
(
string
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
PrepareBuilder
();
result
.
hasEmail
=
true
;
result
.
email_
=
value
;
return
this
;
}
public
Builder
ClearEmail
()
{
PrepareBuilder
();
result
.
hasEmail
=
false
;
result
.
email_
=
""
;
return
this
;
private
static
readonly
string
[]
_fieldNames
=
new
string
[]
{
"number"
,
"type"
};
private
static
readonly
uint
[]
_fieldTags
=
new
uint
[]
{
10
,
16
};
public
static
pbd
::
MessageDescriptor
Descriptor
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_Person_PhoneNumber__Descriptor
;
}
}
public
pbc
::
IPopsicleList
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>
PhoneList
{
get
{
return
PrepareBuilder
().
phone_
;
}
}
public
int
PhoneCount
{
get
{
return
result
.
PhoneCount
;
}
}
public
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
GetPhone
(
int
index
)
{
return
result
.
GetPhone
(
index
);
}
public
Builder
SetPhone
(
int
index
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
PrepareBuilder
();
result
.
phone_
[
index
]
=
value
;
return
this
;
}
public
Builder
SetPhone
(
int
index
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
.
Builder
builderForValue
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
builderForValue
,
"builderForValue"
);
PrepareBuilder
();
result
.
phone_
[
index
]
=
builderForValue
.
Build
();
return
this
;
}
public
Builder
AddPhone
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
PrepareBuilder
();
result
.
phone_
.
Add
(
value
);
return
this
;
}
public
Builder
AddPhone
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
.
Builder
builderForValue
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
builderForValue
,
"builderForValue"
);
PrepareBuilder
();
result
.
phone_
.
Add
(
builderForValue
.
Build
());
return
this
;
}
public
Builder
AddRangePhone
(
scg
::
IEnumerable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneNumber
>
values
)
{
PrepareBuilder
();
result
.
phone_
.
Add
(
values
);
return
this
;
}
public
Builder
ClearPhone
()
{
PrepareBuilder
();
result
.
phone_
.
Clear
();
return
this
;
}
}
static
Person
()
{
object
.
ReferenceEquals
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
Descriptor
,
null
);
}
public
pb
::
FieldAccess
.
FieldAccessorTable
<
PhoneNumber
>
Fields
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable
;
}
}
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
sealed
partial
class
AddressBook
:
pb
::
GeneratedMessage
<
AddressBook
,
AddressBook
.
Builder
>
{
private
AddressBook
()
{
}
private
static
readonly
AddressBook
defaultInstance
=
new
AddressBook
().
MakeReadOnly
();
private
static
readonly
string
[]
_addressBookFieldNames
=
new
string
[]
{
"person"
};
private
static
readonly
uint
[]
_addressBookFieldTags
=
new
uint
[]
{
10
};
public
static
AddressBook
DefaultInstance
{
get
{
return
defaultInstance
;
}
public
PhoneNumber
()
{
}
public
PhoneNumber
(
PhoneNumber
other
)
{
MergeFrom
(
other
);
}
public
override
AddressBook
DefaultInstanceForType
{
get
{
return
DefaultInstance
;
}
public
const
int
NumberFieldNumber
=
1
;
private
string
number_
=
""
;
public
string
Number
{
get
{
return
number_
;
}
set
{
number_
=
value
??
""
;
}
}
protected
override
AddressBook
ThisMessage
{
get
{
return
this
;
}
}
public
static
pbd
::
MessageDescriptor
Descriptor
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_AddressBook__Descriptor
;
}
public
const
int
TypeFieldNumber
=
2
;
private
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
type_
=
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
.
HOME
;
public
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
Type
{
get
{
return
type_
;
}
set
{
type_
=
value
;
}
}
protected
override
pb
::
FieldAccess
.
FieldAccessorTable
<
AddressBook
,
AddressBook
.
Builder
>
InternalFieldAccessors
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_AddressBook__FieldAccessorTable
;
}
}
public
const
int
PersonFieldNumber
=
1
;
private
pbc
::
PopsicleList
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>
person_
=
new
pbc
::
PopsicleList
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>();
public
scg
::
IList
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>
PersonList
{
get
{
return
person_
;
}
}
public
int
PersonCount
{
get
{
return
person_
.
Count
;
}
}
public
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
GetPerson
(
int
index
)
{
return
person_
[
index
];
public
override
bool
Equals
(
object
other
)
{
return
Equals
(
other
as
PhoneNumber
);
}
public
override
bool
IsInitialized
{
get
{
foreach
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
element
in
PersonList
)
{
if
(!
element
.
IsInitialized
)
return
false
;
public
bool
Equals
(
PhoneNumber
other
)
{
if
(
ReferenceEquals
(
other
,
null
))
{
return
false
;
}
if
(
ReferenceEquals
(
other
,
this
))
{
return
true
;
}
if
(
Number
!=
other
.
Number
)
return
false
;
if
(
Type
!=
other
.
Type
)
return
false
;
return
true
;
}
public
override
void
WriteTo
(
pb
::
ICodedOutputStream
output
)
{
CalcSerializedSize
();
string
[]
field_names
=
_addressBookFieldNames
;
if
(
person_
.
Count
>
0
)
{
output
.
WriteMessageArray
(
1
,
field_names
[
0
],
person_
);
}
UnknownFields
.
WriteTo
(
output
);
public
override
int
GetHashCode
()
{
int
hash
=
0
;
if
(
Number
!=
""
)
hash
^=
Number
.
GetHashCode
();
if
(
Type
!=
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
.
HOME
)
hash
^=
Type
.
GetHashCode
();
return
hash
;
}
private
int
memoizedSerializedSize
=
-
1
;
public
override
int
SerializedSize
{
get
{
int
size
=
memoizedSerializedSize
;
if
(
size
!=
-
1
)
return
size
;
return
CalcSerializedSize
(
);
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Number
!=
""
)
{
output
.
WriteString
(
1
,
Number
);
}
if
(
Type
!=
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
.
HOME
)
{
output
.
WriteEnum
(
2
,
(
int
)
Type
);
}
}
private
int
CalcSerializedSize
()
{
int
size
=
memoizedSerializedSize
;
if
(
size
!=
-
1
)
return
size
;
size
=
0
;
foreach
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
element
in
PersonList
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeMessageSize
(
1
,
element
);
public
int
CalculateSize
()
{
int
size
=
0
;
if
(
Number
!=
""
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeStringSize
(
1
,
Number
);
}
size
+=
UnknownFields
.
SerializedSize
;
memoizedSerializedSize
=
size
;
return
size
;
if
(
Type
!=
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
.
HOME
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeEnumSize
(
2
,
(
int
)
Type
);
}
public
static
AddressBook
ParseFrom
(
pb
::
ByteString
data
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
)).
BuildParsed
();
return
size
;
}
public
static
AddressBook
ParseFrom
(
pb
::
ByteString
data
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
,
extensionRegistry
)).
BuildParsed
();
public
void
MergeFrom
(
PhoneNumber
other
)
{
if
(
other
==
null
)
{
return
;
}
public
static
AddressBook
ParseFrom
(
byte
[]
data
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
)).
BuildParsed
()
;
if
(
other
.
Number
!=
""
)
{
Number
=
other
.
Number
;
}
public
static
AddressBook
ParseFrom
(
byte
[]
data
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
data
,
extensionRegistry
)).
BuildParsed
()
;
if
(
other
.
Type
!=
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
.
HOME
)
{
Type
=
other
.
Type
;
}
public
static
AddressBook
ParseFrom
(
global
::
System
.
IO
.
Stream
input
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
)).
BuildParsed
();
}
public
static
AddressBook
ParseFrom
(
global
::
System
.
IO
.
Stream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
,
extensionRegistry
)).
BuildParsed
();
public
void
MergeFrom
(
pb
::
CodedInputStream
input
)
{
uint
tag
;
while
(
input
.
ReadTag
(
out
tag
))
{
switch
(
tag
)
{
case
0
:
throw
pb
::
InvalidProtocolBufferException
.
InvalidTag
();
default
:
if
(
pb
::
WireFormat
.
IsEndGroupTag
(
tag
))
{
return
;
}
public
static
AddressBook
ParseDelimitedFrom
(
global
::
System
.
IO
.
Stream
input
)
{
return
CreateBuilder
().
MergeDelimitedFrom
(
input
).
BuildParsed
();
break
;
case
10
:
{
number_
=
input
.
ReadString
();
break
;
}
public
static
AddressBook
ParseDelimitedFrom
(
global
::
System
.
IO
.
Stream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
CreateBuilder
().
MergeDelimitedFrom
(
input
,
extensionRegistry
).
BuildParsed
();
case
16
:
{
type_
=
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Types
.
PhoneType
)
input
.
ReadEnum
();
break
;
}
public
static
AddressBook
ParseFrom
(
pb
::
ICodedInputStream
input
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
)).
BuildParsed
();
}
public
static
AddressBook
ParseFrom
(
pb
::
ICodedInputStream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
return
((
Builder
)
CreateBuilder
().
MergeFrom
(
input
,
extensionRegistry
)).
BuildParsed
();
}
private
AddressBook
MakeReadOnly
()
{
person_
.
MakeReadOnly
();
return
this
;
}
public
static
Builder
CreateBuilder
()
{
return
new
Builder
();
}
public
override
Builder
ToBuilder
()
{
return
CreateBuilder
(
this
);
}
public
override
Builder
CreateBuilderForType
()
{
return
new
Builder
();
}
public
static
Builder
CreateBuilder
(
AddressBook
prototype
)
{
return
new
Builder
(
prototype
);
}
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
sealed
partial
class
Builder
:
pb
::
GeneratedBuilder
<
AddressBook
,
Builder
>
{
protected
override
Builder
ThisBuilder
{
get
{
return
this
;
}
}
public
Builder
()
{
result
=
DefaultInstance
;
resultIsReadOnly
=
true
;
}
internal
Builder
(
AddressBook
cloneFrom
)
{
result
=
cloneFrom
;
resultIsReadOnly
=
true
;
}
private
bool
resultIsReadOnly
;
private
AddressBook
result
;
#
endregion
private
AddressBook
PrepareBuilder
()
{
if
(
resultIsReadOnly
)
{
AddressBook
original
=
result
;
result
=
new
AddressBook
();
resultIsReadOnly
=
false
;
MergeFrom
(
original
);
}
return
result
;
}
public
override
bool
IsInitialized
{
get
{
return
result
.
IsInitialized
;
}
}
[
global
::
System
.
Diagnostics
.
DebuggerNonUserCodeAttribute
()]
public
sealed
partial
class
AddressBook
:
pb
::
IMessage
<
AddressBook
>,
global
::
System
.
IEquatable
<
AddressBook
>
{
private
static
readonly
pb
::
MessageParser
<
AddressBook
>
_parser
=
new
pb
::
MessageParser
<
AddressBook
>(()
=>
new
AddressBook
());
public
static
pb
::
MessageParser
<
AddressBook
>
Parser
{
get
{
return
_parser
;
}
}
protected
override
AddressBook
MessageBeingBuilt
{
get
{
return
PrepareBuilder
();
}
private
static
readonly
string
[]
_fieldNames
=
new
string
[]
{
"person"
};
private
static
readonly
uint
[]
_fieldTags
=
new
uint
[]
{
10
};
public
static
pbd
::
MessageDescriptor
Descriptor
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_AddressBook__Descriptor
;
}
}
public
override
Builder
Clear
()
{
result
=
DefaultInstance
;
resultIsReadOnly
=
true
;
return
this
;
public
pb
::
FieldAccess
.
FieldAccessorTable
<
AddressBook
>
Fields
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
internal__static_tutorial_AddressBook__FieldAccessorTable
;
}
}
public
override
Builder
Clone
()
{
if
(
resultIsReadOnly
)
{
return
new
Builder
(
result
);
}
else
{
return
new
Builder
().
MergeFrom
(
result
);
public
AddressBook
()
{
}
public
AddressBook
(
AddressBook
other
)
{
MergeFrom
(
other
);
}
public
const
int
PersonFieldNumber
=
1
;
private
readonly
pbc
::
RepeatedField
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>
person_
=
new
pbc
::
RepeatedField
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>();
public
pbc
::
RepeatedField
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>
Person
{
get
{
return
person_
;
}
}
public
override
pbd
::
MessageDescriptor
DescriptorForType
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
AddressBook
.
Descriptor
;
}
public
override
bool
Equals
(
object
other
)
{
return
Equals
(
other
as
AddressBook
);
}
public
override
AddressBook
DefaultInstanceForType
{
get
{
return
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
AddressBook
.
DefaultInstance
;
}
public
bool
Equals
(
AddressBook
other
)
{
if
(
ReferenceEquals
(
other
,
null
))
{
return
false
;
}
public
override
AddressBook
BuildPartial
()
{
if
(
resultIsReadOnly
)
{
return
result
;
if
(
ReferenceEquals
(
other
,
this
))
{
return
true
;
}
resultIsReadOnly
=
tru
e
;
return
result
.
MakeReadOnly
()
;
if
(!
person_
.
Equals
(
other
.
person_
))
return
fals
e
;
return
true
;
}
public
override
Builder
MergeFrom
(
pb
::
IMessage
other
)
{
if
(
other
is
AddressBook
)
{
return
MergeFrom
((
AddressBook
)
other
);
}
else
{
base
.
MergeFrom
(
other
);
return
this
;
public
override
int
GetHashCode
()
{
int
hash
=
0
;
hash
^=
person_
.
GetHashCode
();
return
hash
;
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
output
.
WriteMessageArray
(
1
,
person_
);
}
public
override
Builder
MergeFrom
(
AddressBook
other
)
{
if
(
other
==
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
AddressBook
.
DefaultInstance
)
return
this
;
PrepareBuilder
();
if
(
other
.
person_
.
Count
!=
0
)
{
result
.
person_
.
Add
(
other
.
person_
);
public
int
CalculateSize
()
{
int
size
=
0
;
foreach
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
element
in
person_
)
{
size
+=
pb
::
CodedOutputStream
.
ComputeMessageSize
(
1
,
element
);
}
return
size
;
}
this
.
MergeUnknownFields
(
other
.
UnknownFields
);
return
this
;
public
void
MergeFrom
(
AddressBook
other
)
{
if
(
other
==
null
)
{
return
;
}
public
override
Builder
MergeFrom
(
pb
::
ICodedInputStream
input
)
{
return
MergeFrom
(
input
,
pb
::
ExtensionRegistry
.
Empty
);
person_
.
Add
(
other
.
person_
);
}
public
override
Builder
MergeFrom
(
pb
::
ICodedInputStream
input
,
pb
::
ExtensionRegistry
extensionRegistry
)
{
PrepareBuilder
();
pb
::
UnknownFieldSet
.
Builder
unknownFields
=
null
;
public
void
MergeFrom
(
pb
::
CodedInputStream
input
)
{
uint
tag
;
string
field_name
;
while
(
input
.
ReadTag
(
out
tag
,
out
field_name
))
{
if
(
tag
==
0
&&
field_name
!=
null
)
{
int
field_ordinal
=
global
::
System
.
Array
.
BinarySearch
(
_addressBookFieldNames
,
field_name
,
global
::
System
.
StringComparer
.
Ordinal
);
if
(
field_ordinal
>=
0
)
tag
=
_addressBookFieldTags
[
field_ordinal
];
else
{
if
(
unknownFields
==
null
)
{
unknownFields
=
pb
::
UnknownFieldSet
.
CreateBuilder
(
this
.
UnknownFields
);
}
ParseUnknownField
(
input
,
unknownFields
,
extensionRegistry
,
tag
,
field_name
);
continue
;
}
}
switch
(
tag
)
{
case
0
:
{
while
(
input
.
ReadTag
(
out
tag
))
{
switch
(
tag
)
{
case
0
:
throw
pb
::
InvalidProtocolBufferException
.
InvalidTag
();
}
default
:
{
default
:
if
(
pb
::
WireFormat
.
IsEndGroupTag
(
tag
))
{
if
(
unknownFields
!=
null
)
{
this
.
UnknownFields
=
unknownFields
.
Build
();
}
return
this
;
}
if
(
unknownFields
==
null
)
{
unknownFields
=
pb
::
UnknownFieldSet
.
CreateBuilder
(
this
.
UnknownFields
);
return
;
}
ParseUnknownField
(
input
,
unknownFields
,
extensionRegistry
,
tag
,
field_name
);
break
;
}
case
10
:
{
input
.
ReadMessageArray
(
tag
,
field_name
,
result
.
person_
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
DefaultInstance
,
extensionRegistry
);
input
.
ReadMessageArray
(
tag
,
person_
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Parser
);
break
;
}
}
}
if
(
unknownFields
!=
null
)
{
this
.
UnknownFields
=
unknownFields
.
Build
();
}
return
this
;
}
public
pbc
::
IPopsicleList
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>
PersonList
{
get
{
return
PrepareBuilder
().
person_
;
}
}
public
int
PersonCount
{
get
{
return
result
.
PersonCount
;
}
}
public
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
GetPerson
(
int
index
)
{
return
result
.
GetPerson
(
index
);
}
public
Builder
SetPerson
(
int
index
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
PrepareBuilder
();
result
.
person_
[
index
]
=
value
;
return
this
;
}
public
Builder
SetPerson
(
int
index
,
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Builder
builderForValue
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
builderForValue
,
"builderForValue"
);
PrepareBuilder
();
result
.
person_
[
index
]
=
builderForValue
.
Build
();
return
this
;
}
public
Builder
AddPerson
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
value
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
value
,
"value"
);
PrepareBuilder
();
result
.
person_
.
Add
(
value
);
return
this
;
}
public
Builder
AddPerson
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
.
Builder
builderForValue
)
{
pb
::
ThrowHelper
.
ThrowIfNull
(
builderForValue
,
"builderForValue"
);
PrepareBuilder
();
result
.
person_
.
Add
(
builderForValue
.
Build
());
return
this
;
}
public
Builder
AddRangePerson
(
scg
::
IEnumerable
<
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Person
>
values
)
{
PrepareBuilder
();
result
.
person_
.
Add
(
values
);
return
this
;
}
public
Builder
ClearPerson
()
{
PrepareBuilder
();
result
.
person_
.
Clear
();
return
this
;
}
}
static
AddressBook
()
{
object
.
ReferenceEquals
(
global
::
Google
.
ProtocolBuffers
.
Examples
.
AddressBook
.
Addressbook
.
Descriptor
,
null
);
}
}
#
endregion
...
...
csharp/src/AddressBook/ListPeople.cs
View file @
eb70bd0b
...
...
@@ -46,16 +46,16 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
/// </summary>
private
static
void
Print
(
AddressBook
addressBook
)
{
foreach
(
Person
person
in
addressBook
.
Person
List
)
foreach
(
Person
person
in
addressBook
.
Person
)
{
Console
.
WriteLine
(
"Person ID: {0}"
,
person
.
Id
);
Console
.
WriteLine
(
" Name: {0}"
,
person
.
Name
);
if
(
person
.
HasEmail
)
if
(
person
.
Email
!=
""
)
{
Console
.
WriteLine
(
" E-mail address: {0}"
,
person
.
Email
);
}
foreach
(
Person
.
Types
.
PhoneNumber
phoneNumber
in
person
.
Phone
List
)
foreach
(
Person
.
Types
.
PhoneNumber
phoneNumber
in
person
.
Phone
)
{
switch
(
phoneNumber
.
Type
)
{
...
...
@@ -94,7 +94,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
// Read the existing address book.
using
(
Stream
stream
=
File
.
OpenRead
(
args
[
0
]))
{
AddressBook
addressBook
=
AddressBook
.
ParseFrom
(
stream
);
AddressBook
addressBook
=
AddressBook
.
Parse
r
.
Parse
From
(
stream
);
Print
(
addressBook
);
}
return
0
;
...
...
csharp/src/AddressBook/SampleUsage.cs
View file @
eb70bd0b
using
System
;
using
Google.Protobuf
;
using
System
;
using
System.IO
;
namespace
Google.ProtocolBuffers.Examples.AddressBook
...
...
@@ -8,37 +9,31 @@ namespace Google.ProtocolBuffers.Examples.AddressBook
private
static
void
Main
()
{
byte
[]
bytes
;
//Create a builder to start building a message
Person
.
Builder
newContact
=
Person
.
CreateBuilder
();
//Set the primitive properties
newContact
.
SetId
(
1
)
.
SetName
(
"Foo"
)
.
SetEmail
(
"foo@bar"
);
//Now add an item to a list (repeating) field
newContact
.
AddPhone
(
//Create the child message inline
Person
.
Types
.
PhoneNumber
.
CreateBuilder
().
SetNumber
(
"555-1212"
).
Build
()
);
//Now build the final message:
Person
person
=
newContact
.
Build
();
//The builder is no longer valid (at least not now, scheduled for 2.4):
newContact
=
null
;
// Create a new person
Person
person
=
new
Person
{
Id
=
1
,
Name
=
"Foo"
,
Email
=
"foo@bar"
,
Phone
=
{
new
Person
.
Types
.
PhoneNumber
{
Number
=
"555-1212"
}
}
};
using
(
MemoryStream
stream
=
new
MemoryStream
())
{
//Save the person to a stream
//
Save the person to a stream
person
.
WriteTo
(
stream
);
bytes
=
stream
.
ToArray
();
}
//Create another builder, merge the byte[], and build the message:
Person
copy
=
Person
.
CreateBuilder
().
MergeFrom
(
bytes
).
Build
();
Person
copy
=
Person
.
Parser
.
ParseFrom
(
bytes
);
//A more streamlined approach might look like this:
bytes
=
AddressBook
.
CreateBuilder
().
AddPerson
(
copy
).
Build
().
ToByteArray
();
//And read the address book back again
AddressBook
restored
=
AddressBook
.
CreateBuilder
().
MergeFrom
(
bytes
).
Build
();
//The message performs a deep-comparison on equality:
if
(
restored
.
PersonCount
!=
1
||
!
person
.
Equals
(
restored
.
PersonList
[
0
]))
// A more streamlined approach might look like this:
bytes
=
copy
.
ToByteArray
();
// And read the address book back again
AddressBook
restored
=
AddressBook
.
Parser
.
ParseFrom
(
bytes
);
// The message performs a deep-comparison on equality:
if
(
restored
.
Person
.
Count
!=
1
||
!
person
.
Equals
(
restored
.
Person
[
0
]))
{
throw
new
ApplicationException
(
"There is a bad person in here!"
);
}
}
}
}
\ No newline at end of file
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