using System.Collections.Generic;
public enum ConfigItemType {
public interface IConfigItem {
ConfigItemType ConfigType { get; set; }
public class ConfigNumberList : IConfigItem {
public ConfigItemType ConfigType { get; set; }
public Dictionary<int, string> Value { get; set; }
public class ConfigurationService {
public Dictionary<string, object> _dict = new Dictionary<string, object>();
public void Add<T>(string key, T value) where T : class, IConfigItem {
public T GetValue<T>(string key) where T : class, IConfigItem {
public static void Main()
var cfg = new ConfigurationService();
var list = new ConfigNumberList();
list.Value = new Dictionary<int, string>() {
cfg.Add<ConfigNumberList>("test", list);
string json = JsonConvert.SerializeObject(cfg, Formatting.Indented, new JsonSerializerSettings{TypeNameHandling = TypeNameHandling.All});
ConfigurationService config = JsonConvert.DeserializeObject<ConfigurationService>(json, new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.Auto});
var dList = config.GetValue<ConfigNumberList>("test");
Console.WriteLine(dList.Value[100]);