public object Deserialize(ICommodityReader reader, Type nominalType) { BsonType bsonType = reader.ReadBsonType(); switch (bsonType) { case BsonType.Null: return(null); break; case BsonType.Document: reader.ReadStartOfObject(); var typeName = reader.ReadName(); Type actualType = CommoditySerializer.Deserialize <Type>(reader); // Create type object instance = InstantiateType(actualType); var valueName = reader.ReadName(); // is always "v" reader.ReadStartOfObject(); DeserializeAttributes(reader, actualType, instance); reader.ReadEndOfObject(); reader.ReadEndOfObject(); return(instance); break; } throw new Exception("nothing to deserialize?"); return(null); }
private void DeserializeAttributes(ICommodityReader reader, Type actualType, object instance) { var serializableMembers = GetSerializableMemberInfos(actualType); //var bsonType = ; // loop over reader while (reader.ReadBsonType() != BsonType.EndOfDocument) { string name = reader.ReadName(); // find name in the serializableMembers CommodityMemberInfoSerializer memberInfoSerializer = serializableMembers.FirstOrDefault(member => member.Name == name); if (memberInfoSerializer == null) { throw new Exception("Member not found."); } // read value (call into deserializer) object value = CommoditySerializer.Deserialize(reader, memberInfoSerializer.MemberType); memberInfoSerializer.SetValue(instance, value); } }
private IAggregateEvent ConstructEvent(BsonValue bsonValue) { return(CommoditySerializer.Deserialize <IAggregateEvent>(bsonValue.AsBsonDocument)); }