using System.Collections.Generic;
using System.Diagnostics;
using System.Collections;
using System.Runtime.Serialization;
using System.ComponentModel;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Bson;
public string Text { get; private set; }
public int Awesomeness { get; private set; }
public Message(string Text, int Awesomeness)
if (Awesomeness < 1 || Awesomeness > 5)
throw new ArgumentOutOfRangeException("awesome");
this.Awesomeness = Awesomeness;
public static void Main()
Console.WriteLine(string.Format("Json.NET version: {0}.\n", typeof(JsonSerializer).Assembly.FullName));
var msg = new Message("This is some text", 2);
var json = JsonConvert.SerializeObject(msg, Formatting.Indented);
Console.WriteLine("Serialized Message:");
var msg2 = JsonConvert.DeserializeObject<Message>(json);
if (msg.Awesomeness != msg2.Awesomeness || msg.Text != msg2.Text)
throw new InvalidOperationException("msg.Awesomeness != msg2.Awesomeness || msg.Text != msg2.Text");
var json2 = JsonConvert.SerializeObject(msg2);
Console.WriteLine("Re-serialized Message:");