public void DeserializeProperty(
     BsonReader bsonReader,
     object obj,
     BsonPropertyMap propertyMap
 )
 {
     BsonType bsonType = bsonReader.PeekBsonType();
     object value;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull(propertyMap.ElementName);
         value = null;
     } else {
         bsonReader.ReadDocumentName(propertyMap.ElementName);
         value = BsonSerializer.Deserialize(bsonReader, propertyMap.PropertyInfo.PropertyType);
     }
     propertyMap.Setter(obj, value);
 }
 public void DeserializeProperty(
     BsonReader bsonReader,
     object obj,
     BsonPropertyMap propertyMap
 )
 {
     BsonType bsonType = bsonReader.PeekBsonType();
     byte value;
     if (bsonType == BsonType.Int32) {
         value = (byte) bsonReader.ReadInt32(propertyMap.ElementName);
     } else if (bsonType == BsonType.Document) {
         bsonReader.ReadDocumentName(propertyMap.ElementName);
         bsonReader.ReadStartDocument();
         bsonReader.VerifyString("_t", typeof(byte).FullName);
         value = (byte) bsonReader.ReadInt32("v");
         bsonReader.ReadEndDocument();
     } else {
         throw new FileFormatException("Element is not valid System.Byte");
     }
     propertyMap.Setter(obj, value);
 }
 public void DeserializeProperty(
     BsonReader bsonReader,
     object obj,
     BsonPropertyMap propertyMap
 )
 {
     var bsonType = bsonReader.PeekBsonType();
     BsonNull value;
     if (bsonType == BsonType.Document) {
         bsonReader.ReadDocumentName(propertyMap.ElementName);
         bsonReader.ReadStartDocument();
         bsonReader.VerifyString("$null", "c#null");
         bsonReader.ReadEndDocument();
         value = null;
     } else {
         bsonReader.ReadNull(propertyMap.ElementName);
         value = Bson.Null;
     }
     propertyMap.Setter(obj, value);
 }
 public void DeserializeProperty(
     BsonReader bsonReader,
     object obj,
     BsonPropertyMap propertyMap
 )
 {
     var bsonType = bsonReader.PeekBsonType();
     BsonDocument value;
     if (bsonType == BsonType.Null) {
         bsonReader.ReadNull(propertyMap.ElementName);
         value = null;
     } else {
         bsonReader.ReadDocumentName(propertyMap.ElementName);
         value = BsonDocument.ReadFrom(bsonReader);
     }
     propertyMap.Setter(obj, value);
 }
 public void DeserializeProperty(
     BsonReader bsonReader,
     object obj,
     BsonPropertyMap propertyMap
 )
 {
     BsonType bsonType = bsonReader.PeekBsonType();
     TimeSpan value;
     if (bsonType == BsonType.Int64) {
         value = new TimeSpan(bsonReader.ReadInt64(propertyMap.ElementName));
     } else if (bsonType == BsonType.Document) {
         bsonReader.ReadDocumentName(propertyMap.ElementName);
         bsonReader.ReadStartDocument();
         bsonReader.VerifyString("_t", typeof(TimeSpan).FullName);
         value = TimeSpan.Parse(bsonReader.ReadString("v"));
         bsonReader.ReadEndDocument();
     } else {
         throw new FileFormatException("Element is not valid System.TimeSpan");
     }
     propertyMap.Setter(obj, value);
 }
 public void DeserializeProperty(
     BsonReader bsonReader,
     object obj,
     BsonPropertyMap propertyMap
 )
 {
     BsonType bsonType = bsonReader.PeekBsonType();
     double doubleValue;
     if (bsonType == BsonType.Double) {
         doubleValue = bsonReader.ReadDouble(propertyMap.ElementName);
     } else if (bsonType == BsonType.Document) {
         bsonReader.ReadDocumentName(propertyMap.ElementName);
         bsonReader.ReadStartDocument();
         bsonReader.VerifyString("_t", typeof(float).FullName);
         doubleValue = bsonReader.ReadDouble("v");
         bsonReader.ReadEndDocument();
     } else {
         throw new FileFormatException("Element is not valid System.Single");
     }
     var value = doubleValue == double.MinValue ? float.MinValue : doubleValue == double.MaxValue ? float.MaxValue : (float) doubleValue;
     propertyMap.Setter(obj, value);
 }
 public void DeserializeProperty(
     BsonReader bsonReader,
     object obj,
     BsonPropertyMap propertyMap
 )
 {
     bsonReader.ReadDocumentName(propertyMap.ElementName);
     bsonReader.ReadStartDocument();
     bsonReader.VerifyString("_t", typeof(Decimal).FullName);
     var value = XmlConvert.ToDecimal(bsonReader.ReadString("v"));
     bsonReader.ReadEndDocument();
     propertyMap.Setter(obj, value);
 }
 public void DeserializeProperty(
     BsonReader bsonReader,
     object obj,
     BsonPropertyMap propertyMap
 )
 {
     BsonType bsonType = bsonReader.PeekBsonType();
     DateTimeOffset value;
     if (bsonType == BsonType.Array) {
         bsonReader.ReadArrayName(propertyMap.ElementName);
         bsonReader.ReadStartDocument();
         var dateTime = new DateTime(bsonReader.ReadInt64("0"));
         var offset = new TimeSpan(bsonReader.ReadInt64("1"));
         bsonReader.ReadEndDocument();
         value = new DateTimeOffset(dateTime, offset);
     } else if (bsonType == BsonType.Document) {
         bsonReader.ReadDocumentName(propertyMap.ElementName);
         bsonReader.ReadStartDocument();
         bsonReader.VerifyString("_t", typeof(DateTimeOffset).FullName);
         var dateTime = DateTime.Parse(bsonReader.ReadString("dt")); // Kind = DateTimeKind.Unspecified
         var offset = TimeSpan.Parse(bsonReader.ReadString("o"));
         bsonReader.ReadEndDocument();
         value = new DateTimeOffset(dateTime, offset);
     } else {
         throw new FileFormatException("Element is not valid System.DateTimeOffset");
     }
     propertyMap.Setter(obj, value);
 }
 public void DeserializeProperty(
     BsonReader bsonReader,
     object obj,
     BsonPropertyMap propertyMap
 )
 {
     bsonReader.ReadDocumentName(propertyMap.ElementName);
     bsonReader.ReadStartDocument();
     bsonReader.VerifyString("_t", typeof(CultureInfo).FullName);
     var value = new CultureInfo(bsonReader.ReadString("v"));
     bsonReader.ReadEndDocument();
     propertyMap.Setter(obj, value);
 }