private object DeserializeDictionary(Type type, BinaryReader stream) { var keyType = type.GenericTypeArguments[0]; var valueType = type.GenericTypeArguments[1]; CheckIfCanRead(keyType); CheckIfCanRead(valueType); var instance = ConstructorCache.Create(typeof(Dictionary <,>) .MakeGenericType(keyType, valueType)) as IDictionary; if (stream.BaseStream.CanSeek) { if (stream.BaseStream.Length == stream.BaseStream.Position) { return(instance); } } #pragma warning disable CS0168 try { int count = stream.ReadInt32(); if (count == 0) { return(instance); } for (int i = 0; i < count; i++) { instance.Add(readMethods[keyType](stream), readMethods[valueType](stream)); } } catch (EndOfStreamException ex) { } #pragma warning restore CS0168 return(instance); }
private object DeserializeList(Type type, XmlNode node) { var itemType = type.GenericTypeArguments[0]; var instance = ConstructorCache.Create(typeof(List <>).MakeGenericType(itemType)) as IList; Read(node, s => instance.Add(DeserializeSingle(itemType, s))); return(instance); }
private object DeserializeList(Type type, BinaryReader stream) { var itemType = type.GenericTypeArguments[0]; CheckIfCanRead(itemType); var instance = ConstructorCache.Create(typeof(List <>).MakeGenericType(itemType)) as IList; var count = stream.ReadInt32(); Read(stream, count, itemType, v => instance.Add(v)); return(instance); }
private object DeserializeDictionary(Type type, XmlNode node) { var keyType = type.GenericTypeArguments[0]; var valueType = type.GenericTypeArguments[1]; var instance = ConstructorCache.Create(typeof(Dictionary <,>) .MakeGenericType(keyType, valueType)) as IDictionary; if (!node.HasChildNodes) { return(instance); } foreach (XmlNode child in node.ChildNodes) { var key = child.Attributes["key"].Value; var value = child.Attributes["value"].Value; instance.Add(DeserializeSingle(keyType, key), DeserializeSingle(valueType, value)); } return(instance); }