-Samples!

This commit is contained in:
James Newton-King
2013-01-28 23:20:05 +13:00
parent 849f7a9fa8
commit 1c0e2856c2
208 changed files with 713 additions and 693 deletions
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
{
public class SerializeToBson
{
#region Types
public class Event
{
public string Name { get; set; }
public DateTime StartDate { get; set; }
}
#endregion
public void Example()
{
#region Usage
Event e = new Event
{
Name = "Movie Premiere",
StartDate = new DateTime(2013, 1, 22, 20, 30, 0)
};
MemoryStream ms = new MemoryStream();
using (BsonWriter writer = new BsonWriter(ms))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(writer, e);
}
string data = Convert.ToBase64String(ms.ToArray());
Console.WriteLine(data);
// MQAAAAJOYW1lAA8AAABNb3ZpZSBQcmVtaWVyZQAJU3RhcnREYXRlAMDgKWE8AQAAAA==
#endregion
}
}
}