Beispiel #1
0
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="nominalType">The nominal type of the object.</param>
        /// <param name="configurator">The configurator.</param>
        /// <returns>A deserialized value.</returns>
        public static object Deserialize(IBsonReader bsonReader, Type nominalType, Action <BsonDeserializationContext.Builder> configurator = null)
        {
            var serializer = LookupSerializer(nominalType);
            var context    = BsonDeserializationContext.CreateRoot(bsonReader, configurator);

            return(serializer.Deserialize(context));
        }
Beispiel #2
0
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <typeparam name="TNominalType">The nominal type of the object.</typeparam>
        /// <param name="bsonReader">The BsonReader.</param>
        /// <param name="configurator">The configurator.</param>
        /// <returns>A deserialized value.</returns>
        public static TNominalType Deserialize <TNominalType>(IBsonReader bsonReader, Action <BsonDeserializationContext.Builder> configurator = null)
        {
            var serializer = LookupSerializer <TNominalType>();
            var context    = BsonDeserializationContext.CreateRoot(bsonReader, configurator);

            return(serializer.Deserialize(context));
        }
        /// <summary>
        /// Deserializes the value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>The deserialized value.</returns>
        public object DeserializeValue(BsonValue value)
        {
            var tempDocument = new BsonDocument("value", value);

            using (var reader = new BsonDocumentReader(tempDocument))
            {
                var context = BsonDeserializationContext.CreateRoot <BsonDocument>(reader);
                reader.ReadStartDocument();
                reader.ReadName("value");
                var deserializedValue = context.DeserializeWithChildContext(_serializer);
                reader.ReadEndDocument();
                return(deserializedValue);
            }
        }