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 interface IMyCommand
public class MyCommand1 : IMyCommand
public class MyCommand2 : IMyCommand
public Guid Id { get; set; }
public string CompanyId { get; set; }
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto)]
public List<IMyCommand> Commands { get; set; }
public MyClass(string partitionKey)
CompanyId = partitionKey;
public static void Test()
string partitionKey = "Test";
var myclass = new MyClass(partitionKey)
Commands = new List<IMyCommand>
var settings = new JsonSerializerSettings
var json = JsonConvert.SerializeObject(myclass, settings);
var myclass2 = JsonConvert.DeserializeObject<MyClass>(json, settings);
var json2 = JsonConvert.SerializeObject(myclass2, settings);
Console.WriteLine(json2);
public static void Main()
Console.WriteLine("Environment version: {0} ({1}), {2}", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , Environment.Version, Environment.OSVersion);
Console.WriteLine("{0} version: {1}", typeof(JsonSerializer).Namespace, typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");