using System.Collections.Generic;
using System.ComponentModel;
public static void Main()
var product = new Product
Params = new Dictionary<string, dynamic>
var product2 = new Product2
Params = new Dictionary<string, string>
var json = Jil.JSON.SerializeDynamic(product);
var json2 = Jil.JSON.Serialize(product2);
Console.WriteLine(json2);
var deserialized = Jil.JSON.Deserialize<Product>(json);
Console.WriteLine(deserialized.Params["test"]);
Console.WriteLine(ResolveDynamicValue(deserialized.Params["test"], false));
var deserialized2 = Jil.JSON.Deserialize<Product2>(json2);
Console.WriteLine(deserialized2.Params["test"]);
public Dictionary<string,dynamic> Params{get;set;}
public Dictionary<string,string> Params{get;set;}
public static object ResolveDynamicValue(
var descriptor = val as ICustomTypeDescriptor;
var converter = descriptor.GetConverter();
if (converter.CanConvertTo(typeof(double)))
return converter.ConvertTo(val, typeof(double));
if (converter.CanConvertTo(typeof(DateTime)))
return converter.ConvertTo(val, typeof(DateTime));
if (converter.CanConvertTo(typeof(string)))
return converter.ConvertToString(val);
if (converter.CanConvertTo(typeof(IDictionary<string, object>)) && recursively)
var converted = (IDictionary<string, object>)converter.ConvertTo(val, typeof(IDictionary<string, object>));
return converted?.ToDictionary(kv => kv.Key, kv => ResolveDynamicValue(kv.Value, true));