Пример #1
0
        public static void TestSer()
        {
            BsonClassMap.RegisterClassMap <SagaTest.MyState>(
                x =>
            {
                x.AutoMap();
                x.SetIgnoreExtraElements(true);
            });


            var bd = new MongoDB.Bson.BsonDocument();

            MongoDB.Bson.IO.BsonDocumentWriter bdw = (BsonDocumentWriter)BsonDocumentWriter.Create(bd);

            var obj = new SagaTest.MyState {
                Collected = new List <int>(), Last = DateTime.Now
            };


            MongoDB.Bson.Serialization.BsonSerializer.Serialize(bdw, obj);
            bdw.Flush();

            /*
             * bd["_t"] = MongoDB.Bson.Serialization.TypeNameDiscriminator.GetDiscriminator(obj.GetType());
             * bd["version"] = "3823424";
             * Console.WriteLine(bd.ToJson());
             * Type t = TypeNameDiscriminator.GetActualType(bd["_t"].AsString);
             * var obj2 = BsonSerializer.Deserialize(bd, t);
             * Console.WriteLine("deser: " + obj2);
             */
        }