public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (BsonArray) propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteNull(propertyMap.ElementName); } else { bsonWriter.WriteArrayName(propertyMap.ElementName); value.WriteTo(bsonWriter); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { // note: the DateTime portion cannot be serialized as a BsonType.DateTime because it is NOT in UTC var value = (DateTimeOffset) propertyMap.Getter(obj); if (propertyMap.UseCompactRepresentation) { bsonWriter.WriteArrayName(propertyMap.ElementName); bsonWriter.WriteStartDocument(); bsonWriter.WriteInt64("0", value.DateTime.Ticks); bsonWriter.WriteInt64("1", value.Offset.Ticks); bsonWriter.WriteEndDocument(); } else { bsonWriter.WriteDocumentName(propertyMap.ElementName); bsonWriter.WriteStartDocument(); bsonWriter.WriteString("_t", typeof(DateTimeOffset).FullName); bsonWriter.WriteString("dt", value.DateTime.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFF")); // omit trailing zeros bsonWriter.WriteString("o", Regex.Replace(value.Offset.ToString(), ":00$", "")); // omit trailing zeros bsonWriter.WriteEndDocument(); } }