using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
namespace BusinessObjects
public bool NameInitialized { get { return !string.IsNullOrWhiteSpace(Name); }}
public static void Test()
Console.WriteLine("\nInput JSON: ");
string classname = "BusinessObjects.Contact";
Type classtype = Type.GetType(classname);
JObject obj = JObject.Parse(json);
JArray array = (JArray)obj["contacts"];
var listType = typeof(List<>).MakeGenericType(classtype);
var records = array.ToObject(listType);
Console.WriteLine("\nReserialized records: ");
Console.WriteLine(JsonConvert.SerializeObject(records, Formatting.Indented));
{ ""name"": ""Foo"" }, {}, {""Name"": ""Bar""}
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
public static void IsTrue(bool value, string message)
throw new AssertionFailedException(message ?? "failed");