void IBsonSerializable.Serialize( BsonWriter bsonWriter, bool serializeIdFirst, bool serializeDiscriminator ) { document.Serialize(bsonWriter, serializeIdFirst, serializeDiscriminator); }
public void Serialize( BsonWriter bsonWriter, object obj, bool serializeIdFirst, bool serializeDiscriminator ) { ((IBsonSerializable) obj).Serialize(bsonWriter, serializeIdFirst, serializeDiscriminator); }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (bool) propertyMap.Getter(obj); bsonWriter.WriteBoolean(propertyMap.ElementName, value); }
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 ) { var value = propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteNull(propertyMap.ElementName); } else { bsonWriter.WriteDocumentName(propertyMap.ElementName); var propertyType = propertyMap.PropertyInfo.PropertyType; var serializeDiscriminator = BsonPropertyMap.IsPolymorphicType(propertyType) || obj.GetType() != propertyType; BsonSerializer.Serialize(bsonWriter, value, false, serializeDiscriminator); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (BsonDateTime) propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteNull(propertyMap.ElementName); } else { bsonWriter.WriteDateTime(propertyMap.ElementName, value.Value); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (BsonBinaryData) propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteNull(propertyMap.ElementName); } else { bsonWriter.WriteBinaryData(propertyMap.ElementName, value.Bytes, value.SubType); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (BsonValue) propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteNull(propertyMap.ElementName); } else { var element = new BsonElement(propertyMap.ElementName, value); element.WriteTo(bsonWriter); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (BsonRegularExpression) propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteNull(propertyMap.ElementName); } else { bsonWriter.WriteRegularExpression(propertyMap.ElementName, value.Pattern, value.Options); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (BsonObjectId) propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteNull(propertyMap.ElementName); } else { bsonWriter.WriteObjectId(propertyMap.ElementName, value.Timestamp, value.MachinePidIncrement); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (CultureInfo) propertyMap.Getter(obj); bsonWriter.WriteDocumentName(propertyMap.ElementName); bsonWriter.WriteStartDocument(); bsonWriter.WriteString("_t", typeof(CultureInfo).FullName); bsonWriter.WriteString("v", value.ToString()); bsonWriter.WriteEndDocument(); }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (BsonMinKey) propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteNull(propertyMap.ElementName); } else { bsonWriter.WriteMinKey(propertyMap.ElementName); } }
public void Serialize( BsonWriter bsonWriter ) { Serialize(bsonWriter, false, false); }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (ulong) propertyMap.Getter(obj); if (propertyMap.UseCompactRepresentation) { bsonWriter.WriteInt64(propertyMap.ElementName, (long) value); } else { bsonWriter.WriteDocumentName(propertyMap.ElementName); bsonWriter.WriteStartDocument(); bsonWriter.WriteString("_t", typeof(ulong).FullName); bsonWriter.WriteInt64("v", (long) value); bsonWriter.WriteEndDocument(); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (DateTime) propertyMap.Getter(obj); bsonWriter.WriteDateTime(propertyMap.ElementName, value); }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (float) propertyMap.Getter(obj); var doubleValue = value == float.MinValue ? double.MinValue : value == float.MaxValue ? double.MaxValue : value; if (propertyMap.UseCompactRepresentation) { bsonWriter.WriteDouble(propertyMap.ElementName, doubleValue); } else { bsonWriter.WriteDocumentName(propertyMap.ElementName); bsonWriter.WriteStartDocument(); bsonWriter.WriteString("_t", typeof(float).FullName); bsonWriter.WriteDouble("v", doubleValue); bsonWriter.WriteEndDocument(); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (Decimal) propertyMap.Getter(obj); bsonWriter.WriteDocumentName(propertyMap.ElementName); bsonWriter.WriteStartDocument(); bsonWriter.WriteString("_t", typeof(Decimal).FullName); bsonWriter.WriteString("v", XmlConvert.ToString(value)); bsonWriter.WriteEndDocument(); }
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(); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (BsonJavaScriptWithScope) propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteNull(propertyMap.ElementName); } else { bsonWriter.WriteJavaScriptWithScope(propertyMap.ElementName, value.Code); value.Scope.WriteTo(bsonWriter); } }
public void Serialize( BsonWriter bsonWriter, bool serializeIdFirst, bool serializeDiscriminator ) { BsonSerializer.Serialize(bsonWriter, document, serializeIdFirst, serializeDiscriminator); }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (Guid) propertyMap.Getter(obj); bsonWriter.WriteBinaryData(propertyMap.ElementName, value.ToByteArray(), BsonBinarySubType.Uuid); }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (char) propertyMap.Getter(obj); if (propertyMap.UseCompactRepresentation) { bsonWriter.WriteString(propertyMap.ElementName, new string(new char[] { value })); } else { bsonWriter.WriteDocumentName(propertyMap.ElementName); bsonWriter.WriteStartDocument(); bsonWriter.WriteString("_t", typeof(char).FullName); bsonWriter.WriteString("v", new string(new char[] { value })); bsonWriter.WriteEndDocument(); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (BsonNull) propertyMap.Getter(obj); if (value == null) { bsonWriter.WriteDocumentName(propertyMap.ElementName); bsonWriter.WriteStartDocument(); bsonWriter.WriteString("$null", "c#null"); bsonWriter.WriteEndDocument(); } else { bsonWriter.WriteNull(propertyMap.ElementName); } }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var value = (long) propertyMap.Getter(obj); bsonWriter.WriteInt64(propertyMap.ElementName, value); }
public void Serialize( BsonWriter bsonWriter, object obj, bool serializeIdFirst, bool serializeDiscriminator ) { var objType = obj.GetType(); var classMap = BsonClassMap.LookupClassMap(objType); bsonWriter.WriteStartDocument(); BsonPropertyMap idPropertyMap = null; if (serializeIdFirst) { idPropertyMap = classMap.IdPropertyMap; if (idPropertyMap != null) { idPropertyMap.PropertySerializer.SerializeProperty(bsonWriter, obj, idPropertyMap); } } if (serializeDiscriminator) { bsonWriter.WriteString("_t", classMap.Discriminator); } foreach (var propertyMap in classMap.PropertyMaps) { // note: if serializeIdFirst is false then idPropertyMap will be null (so no property will be skipped) if (propertyMap != idPropertyMap) { if (obj == null && propertyMap.IgnoreIfNull) { continue; // don't serialize null value } if (propertyMap.HasDefaultValue && !propertyMap.SerializeDefaultValue && obj.Equals(propertyMap.DefaultValue)) { continue; // don't serialize default value } propertyMap.PropertySerializer.SerializeProperty(bsonWriter, obj, propertyMap); } } bsonWriter.WriteEndDocument(); }
public void SerializeProperty( BsonWriter bsonWriter, object obj, BsonPropertyMap propertyMap ) { var employee = (Employee) obj; bsonWriter.WriteString(propertyMap.ElementName, employee.DateOfBirth.ToString("yyyy-MM-dd")); }