public enum StructType: byte {
public struct StructBase {
public StructType type = StructType.A;
public A(string a, int aNumber) {
public StructType type = StructType.B;
public System.Collections.Generic.List<string> bees;
public B(System.Collections.Generic.List<string> bees, string queenBee) {
this.queenBee = queenBee;
public StructType type = StructType.C;
public C(string cAmigo, int dinero) {
public static void Main()
var b = new B(new System.Collections.Generic.List<string> { "b1", "b2" }, "BEE!");
var c = new C("CeeeeAmigo", 100);
var aJson = JsonConvert.SerializeObject(a);
var bJson = JsonConvert.SerializeObject(b);
var cJson = JsonConvert.SerializeObject(c);
Console.WriteLine("aJson = {0}", aJson);
Console.WriteLine("bJson = {0}", bJson);
Console.WriteLine("cJson = {0}", cJson);
var randomJsonNumber = Math.Floor(new Random().NextDouble() * 3);
var randomJson = new string[] { aJson, bJson, cJson }[(int)randomJsonNumber];
Console.WriteLine("randomJson = {0}", randomJson);
StructBase baseStruct = JsonConvert.DeserializeObject<StructBase>(randomJson);
switch (baseStruct.type) {
var aStruct = JsonConvert.DeserializeObject<A>(randomJson);
Console.WriteLine("aStruct.a = {0}", aStruct.a);
Console.WriteLine("aStruct.aNumber = {0}", aStruct.aNumber);
var bStruct = JsonConvert.DeserializeObject<B>(randomJson);
Console.WriteLine("bStruct.bees = {0}", string.Join(", ", bStruct.bees));
Console.WriteLine("bStruct.queenBee = {0}", bStruct.queenBee);
var cStruct = JsonConvert.DeserializeObject<C>(randomJson);
Console.WriteLine("cStruct.cAmigo = {0}", cStruct.cAmigo);
Console.WriteLine("cStruct.dinero = {0}", cStruct.dinero);