using System; using System.Collections.Generic; using System.Runtime.Serialization; using Sony.Filtr.Utility.Extensions; namespace Sony.Filtr.API.ViewModels { [Serializable] [KnownType("GetValueTypes")] public class MyJsonDictionary : ISerializable { readonly Dictionary dict = new Dictionary(); public MyJsonDictionary() { } public void GetObjectData(SerializationInfo info, StreamingContext context) { foreach (K key in dict.Keys) { info.AddValue(key.ToString(), dict[key], typeof(V)); } } public void Add(K key, V value) { dict.Add(key, value); } public bool ContainsKey(K key) { return dict.ContainsKey(key); } public V this[K index] { set { dict[index] = value; } get { return dict[index]; } } public static IEnumerable GetValueTypes() { return typeof(V).AsEnumerable(); } } }