public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
IBsonSerializationOptions options)
{
if (nominalType != typeof(Image))
{
var message = string.Format("Nominal type must be Image, not {0}.", nominalType.FullName);
throw new ArgumentException(message, "nominalType");
}
var discriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(typeof(Image));
var actualType = discriminatorConvention.GetActualType(bsonReader, typeof(Image));
if (actualType == typeof(Image))
{
var message = string.Format("Unable to determine actual type of Image to deserialize.");
throw new FileFormatException(message);
}
var serializer = BsonSerializer.LookupSerializer(actualType);
return serializer.Deserialize(bsonReader, nominalType, actualType, options);
}