示例#1
0
 public static void Serialize(Stream bytes, Dictionary <TKey, TValue> instance, Serializer <TKey> keySerialization, Serializer <TValue> valueSerialization)
 {
     Int32Proxy.Serialize(bytes, instance.Count);
     foreach (KeyValuePair <TKey, TValue> current in instance)
     {
         keySerialization(bytes, current.Key);
         valueSerialization(bytes, current.Value);
     }
 }
示例#2
0
        public static Dictionary <TKey, TValue> Deserialize(Stream bytes, Deserializer <TKey> keySerialization, Deserializer <TValue> valueSerialization)
        {
            int length     = Int32Proxy.Deserialize(bytes);
            var dictionary = new Dictionary <TKey, TValue>(length);

            for (int i = 0; i < length; i++)
            {
                dictionary.Add(keySerialization(bytes), valueSerialization(bytes));
            }

            return(dictionary);
        }