aboutsummaryrefslogtreecommitdiff
path: root/src/AddressBook/SampleUsage.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-05-20 15:15:34 -0500
committerrogerk <devnull@localhost>2011-05-20 15:15:34 -0500
commit71f662c33e9938951eec3da97140aed25aa815d7 (patch)
treec322e13686cad5c8bff9e54d7585fc8e4adf6537 /src/AddressBook/SampleUsage.cs
parentd965c666ecf405f4e997ab251e72551508a14678 (diff)
downloadprotobuf-71f662c33e9938951eec3da97140aed25aa815d7.tar.gz
protobuf-71f662c33e9938951eec3da97140aed25aa815d7.tar.bz2
protobuf-71f662c33e9938951eec3da97140aed25aa815d7.zip
reformatted all code to .NET standard formatting
Diffstat (limited to 'src/AddressBook/SampleUsage.cs')
-rw-r--r--src/AddressBook/SampleUsage.cs70
1 files changed, 35 insertions, 35 deletions
diff --git a/src/AddressBook/SampleUsage.cs b/src/AddressBook/SampleUsage.cs
index ae7b6802..084b1655 100644
--- a/src/AddressBook/SampleUsage.cs
+++ b/src/AddressBook/SampleUsage.cs
@@ -3,42 +3,42 @@ using System.IO;
namespace Google.ProtocolBuffers.Examples.AddressBook
{
- class SampleUsage
-{
- static void Main()
+ internal class SampleUsage
{
- 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;
- using(MemoryStream stream = new MemoryStream())
+ private static void Main()
{
- //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();
+ 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;
+ using (MemoryStream stream = new MemoryStream())
+ {
+ //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();
- //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]))
- throw new ApplicationException("There is a bad person in here!");
+ //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]))
+ throw new ApplicationException("There is a bad person in here!");
+ }
}
-}
-}
+} \ No newline at end of file