Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-277

C# Driver does not Deserialize System.Drawing.Size

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.2
    • 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)

      { return Deserialize(bsonReader, nominalType, 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(); }

      }

            Assignee:
            sridhar Sridhar Nanjundeswaran
            Reporter:
            josefresno Joseph A Freeman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: