-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.1
-
Component/s: Feature Request
-
Environment:.Net 4
System.Drawing.Size objects are serialized properly, but not deserialized due to how System.Drawing.Size is constructed. We wrote a custom Serializer to fix this:
public class SizeSerializer : IBsonSerializer
{
public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
{ if (nominalType != typeof(System.Drawing.Size)) throw new ArgumentException("Cannot serialize anything but System.Drawing.Size"); var doc = MongoDBBson.BsonDocument.ReadFrom(bsonReader); return new System.Drawing.Size(doc["Width"].AsInt32, doc["Height"].AsInt32); }public bool GetDocumentId(object document, out object id, out IIdGenerator idGenerator)
{ throw new NotImplementedException(); }public void Serialize(global::MongoDB.Bson.IO.BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{ if (nominalType != typeof(System.Drawing.Size)) throw new ArgumentException("Cannot serialize anything but System.Drawing.Size"); var ser = new BsonClassMapSerializer(); ser.Serialize(bsonWriter, nominalType, value, options); }
public void SetDocumentId(object document, object id)
{ throw new NotImplementedException(); }
}