// protected methods /// <summary> /// Deserializes a class. /// </summary> /// <param name="context">The deserialization context.</param> /// <returns>An object.</returns> protected override GeoJsonNamedCoordinateReferenceSystem DeserializeValue(BsonDeserializationContext context) { var bsonReader = context.Reader; string type = null, name = null; _helper.DeserializeMembers(context, (elementName, flag) => { switch (flag) { case Flags.Type: type = bsonReader.ReadString(); break; case Flags.Properties: _propertiesHelper.DeserializeMembers(context, (propertiesElementName, propertiesFlag) => { switch (propertiesFlag) { case PropertiesFlags.Name: name = bsonReader.ReadString(); break; } }); break; } }); if (type != "name") { var message = string.Format("Expected type to be 'name'."); throw new FormatException(message); } return(new GeoJsonNamedCoordinateReferenceSystem(name)); }
public override DateTime Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) { var bsonReader = context.Reader; var currentBsonType = bsonReader.GetCurrentBsonType(); DateTime value; switch (currentBsonType) { case BsonType.Document: value = new DateTime(); _helper.DeserializeMembers(context, (elementName, flag) => { if (flag != DATE_TIME_FLAG) { if (flag != TICKS_FLAG) { return; } value = new DateTime(_int64Serializer.Deserialize(context), DateTimeKind.Utc); } else { bsonReader.SkipValue(); } }); break; default: throw CreateCannotDeserializeFromBsonTypeException(currentBsonType); } switch (Kind) { case DateTimeKind.Local: value = DateTime.SpecifyKind(BsonUtils.ToLocalTime(value), DateTimeKind.Local); break; case DateTimeKind.Unspecified: value = DateTime.SpecifyKind(value, DateTimeKind.Unspecified); break; case DateTimeKind.Utc: value = BsonUtils.ToUniversalTime(value); break; default: throw CreateCannotDeserializeFromBsonTypeException(currentBsonType); } return(value); }
// protected methods /// <summary> /// Deserializes a value. /// </summary> /// <param name="context">The deserialization context.</param> /// <param name="args">The deserialization args.</param> /// <returns>The value.</returns> protected override MongoDBRef DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args) { var bsonReader = context.Reader; string databaseName = null; string collectionName = null; BsonValue id = null; _helper.DeserializeMembers(context, (elementName, flag) => { switch (flag) { case Flags.CollectionName: collectionName = bsonReader.ReadString(); break; case Flags.Id: id = BsonValueSerializer.Instance.Deserialize(context); break; case Flags.DatabaseName: databaseName = bsonReader.ReadString(); break; } }); return(new MongoDBRef(databaseName, collectionName, id)); }