public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, // ignored
IBsonSerializationOptions options)
{
VerifyDeserializeType(nominalType);
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Int32: return Enum.ToObject(nominalType, bsonReader.ReadInt32());
case BsonType.Int64: return Enum.ToObject(nominalType, bsonReader.ReadInt64());
case BsonType.Double: return Enum.ToObject(nominalType, (long)bsonReader.ReadDouble());
case BsonType.String: return Enum.Parse(nominalType, bsonReader.ReadString());
default:
var message = string.Format("Cannot deserialize {0} from BsonType {1}.", nominalType.FullName, bsonType);
throw new Exception(message);
}
}