using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public List<Template> Templates {get;set;}
Templates = new List<Template>();
Links = new List<Template>();
[JsonProperty(ItemIsReference = true)]
public List<Template> Links {get;set;}
public static void Test()
var jsonString = GetJson();
JsonSerializer ser = new JsonSerializer()
TypeNameHandling = TypeNameHandling.Objects,
ReferenceLoopHandling = ReferenceLoopHandling.Error,
PreserveReferencesHandling = PreserveReferencesHandling.All,
NullValueHandling = NullValueHandling.Ignore
var test = ser.Deserialize<Test>(new JsonTextReader(new StringReader(jsonString)));
var sb = new StringBuilder();
ser.Serialize(new JsonTextWriter(new StringWriter(sb)) { Formatting = Formatting.Indented }, test);
""Id"": ""b5665562-a1e3-419c-b637-fe1ef3c49140"",
""Color"": ""#00FFFFFF"",
""Color"": ""#00FFFFFF"",
""Color"": ""#00FFFFFF"",
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");