示例#1
0
        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);
        }
示例#2
0
        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);
            }
        }
示例#3
0
 private IAggregateEvent ConstructEvent(BsonValue bsonValue)
 {
     return(CommoditySerializer.Deserialize <IAggregateEvent>(bsonValue.AsBsonDocument));
 }