public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
Type actualType,
IBsonSerializationOptions options)
{
VerifyTypes(nominalType, actualType, typeof(ObjectId));
BsonType bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.ObjectId:
return bsonReader.ReadObjectId();
case BsonType.String:
return ObjectId.Parse(bsonReader.ReadString());
default:
var message = string.Format("Cannot deserialize ObjectId from BsonType {0}.", bsonType);
throw new Exception(message);
}
}