public override AggregateResult Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) { var reader = context.Reader; var result = new AggregateResult(); reader.ReadStartDocument(); while (reader.ReadBsonType() != 0) { var elementName = reader.ReadName(); if (elementName == "id") { result.CursorId = new Int64Serializer().Deserialize(context); } else if (elementName == "firstBatch") { var arraySerializer = new ArraySerializer <TResult>(_resultSerializer); result.Results = arraySerializer.Deserialize(context); } else { reader.SkipValue(); } } reader.ReadEndDocument(); return(result); }
public override AggregateResult Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) { var reader = context.Reader; AggregateResult result = null; reader.ReadStartDocument(); while (reader.ReadBsonType() != 0) { var elementName = reader.ReadName(); if (elementName == "cursor") { var cursorDeserializer = new CursorDeserializer(_resultSerializer); result = cursorDeserializer.Deserialize(context); } else if (elementName == "result") { var arraySerializer = new ArraySerializer <TResult>(_resultSerializer); result = new AggregateResult(); result.Results = arraySerializer.Deserialize(context); } else { reader.SkipValue(); } } reader.ReadEndDocument(); return(result); }
public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) { var ser = new ArraySerializer <Card>(); var cards = (Card[])ser.Deserialize(bsonReader, typeof(Card[]), options); return(cards == null ? null : new Pack(cards)); }
public override AggregateResult Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) { var reader = context.Reader; var result = new AggregateResult(); reader.ReadStartDocument(); while (reader.ReadBsonType() != 0) { var elementName = reader.ReadName(); switch (elementName) { case "id": result.CursorId = new Int64Serializer().Deserialize(context); break; case "ns": var ns = reader.ReadString(); result.CollectionNamespace = CollectionNamespace.FromFullName(ns); break; case "firstBatch": var arraySerializer = new ArraySerializer <TResult>(_resultSerializer); result.Results = arraySerializer.Deserialize(context); break; default: reader.SkipValue(); break; } } reader.ReadEndDocument(); return(result); }
public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) { if (nominalType != typeof(Location)) { throw new ArgumentException("Cannot deserialize anything but self"); } var ser = new ArraySerializer <double>(); var arr = ((double[])ser.Deserialize(bsonReader, typeof(double[]), options)); return(new Location(arr[1], arr[0])); }
public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) { if (nominalType != typeof(Dictionary <TKey, TValue>)) { throw new ArgumentException("Cannot serialize anything but self"); } var ser = new ArraySerializer <MongoDictionaryValue <TKey, TValue> >(); var nameEntries = (MongoDictionaryValue <TKey, TValue>[])ser.Deserialize(bsonReader, typeof(MongoDictionaryValue <TKey, TValue>[]), options) ?? new MongoDictionaryValue <TKey, TValue>[] { }; return(nameEntries.ToDictionary(nameLookupEntry => nameLookupEntry.Key, nameLookupEntry => nameLookupEntry.Value)); }
public void ReadXml(XmlReader reader) { if (reader.IsEmptyElement) { reader.Read(); } else { List <T[]> collection = new List <T[]>(); reader.Read(); while (reader.NodeType != XmlNodeType.EndElement) { reader.MoveToContent(); T[] value = (T[])ArraySerializer.Deserialize(reader); if (value != null) { collection.Add(value); } } reader.ReadEndElement(); array = collection.Select(r => r as IList <T>).ToArray(); } }