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

Serialize/Deserialize for readonly properties

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.4.1
    • Affects Version/s: 1.4
    • Component/s: Feature Request
    • Environment:
      All
    • Fully Compatible

      Sometimes we have some readonly properties, but they should be persisted to db, mainly for index and search purpose.

      These properties's values are generated from other properties, but is criticaly useful when perform a search in db, so they should be readonly and should be serialized to BSON.

      My suggest is that the C# driver by default serialize all read/write properties (same as current), but give a configure possibility to serialize readonly properties, such as:

      map.MapProperty(c => c.ReadOnlyProperty);

      Then once a value is deserialized from BSON, and corresonding property doesn't have a set accessor, C# driver does not throw an exception, this causes a modification to /Bson/Serialization/BsonMemberMap.cs (line 560 as in master on github).

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            otakustay Gray Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: