Example #1
0
        public static TOut SerializeAndDeserializeBson <TIn, TOut>(this TIn value)
        {
            var obj = new ObjectHolder <TIn>
            {
                Value = value
            };

            var stream = new MemoryStream();

            using (var writer = new BsonBinaryWriter(stream))
            {
                BsonSerializer.Serialize(writer, obj);

                writer.Flush();
            }

            stream.Position = 0;

            using (var reader = new BsonBinaryReader(stream))
            {
                var result = BsonSerializer.Deserialize <ObjectHolder <TOut> >(reader);

                return(result.Value);
            }
        }
Example #2
0
        public void TestFlushAndClose()
        {
            var stream = new MemoryStream();

            using (var bsonWriter = new BsonBinaryWriter(stream))
            {
                bsonWriter.WriteStartDocument();
                bsonWriter.WriteEndDocument();
                bsonWriter.Flush();
                bsonWriter.Close();
            }
        }
Example #3
0
        private static TOut SerializeAndDeserializeBson <TIn, TOut>(TIn source)
        {
            var stream = new MemoryStream();

            using (var writer = new BsonBinaryWriter(stream))
            {
                BsonSerializer.Serialize(writer, source);

                writer.Flush();
            }

            stream.Position = 0;

            using (var reader = new BsonBinaryReader(stream))
            {
                var target = BsonSerializer.Deserialize <TOut>(reader);

                return(target);
            }
        }