public object Deserialize(
BsonReader bsonReader,
Type nominalType,
Type actualType,
IBsonSerializationOptions options)
{
if (actualType != typeof(object))
{
var message = string.Format("ObjectSerializer can only be used with actual type System.Object, not type {0}.", actualType.FullName);
throw new ArgumentException(message, "actualType");
}
var bsonType = bsonReader.GetCurrentBsonType();
if (bsonType == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else if (bsonType == BsonType.Document)
{
bsonReader.ReadStartDocument();
if (bsonReader.ReadBsonType() == BsonType.EndOfDocument)
{
bsonReader.ReadEndDocument();
return new object();
}
else
{
var message = string.Format("A document being deserialized to System.Object must be empty.");
throw new Exception(message);
}
}
else
{
var message = string.Format("Cannot deserialize System.Object from BsonType {0}.", bsonType);
throw new Exception(message);
}
}