-Reorganized examples

This commit is contained in:
James Newton-King
2013-01-25 00:14:14 +13:00
parent 7899af09c9
commit 253a0dae8e
57 changed files with 0 additions and 0 deletions
@@ -0,0 +1,40 @@
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.Examples
{
public class SerializeToBson
{
public class Event
{
public string Name { get; set; }
public DateTime StartDate { get; set; }
}
public void Example()
{
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==
}
}
}