public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
Type actualType,
IBsonSerializationOptions options)
{
VerifyTypes(nominalType, actualType, typeof(uint));
var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Double:
return representationSerializationOptions.ToUInt32(bsonReader.ReadDouble());
case BsonType.Int32:
return representationSerializationOptions.ToUInt32(bsonReader.ReadInt32());
case BsonType.Int64:
return representationSerializationOptions.ToUInt32(bsonReader.ReadInt64());
case BsonType.String:
return XmlConvert.ToUInt32(bsonReader.ReadString());
default:
var message = string.Format("Cannot deserialize UInt32 from BsonType {0}.", bsonType);
throw new Exception(message);
}
}