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

Interface to allow control of object serialization

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 1.8.3
    • Component/s: Serialization
    • Labels:
      None
    • Environment:
      All

      A suggestion.

      Provide a pre-defined C# interface to control whether entire object instances should be serialized (e.g. IControlledSerialization).

      I have many objects that are part of documents that get saved to Mongo. Very often, I will not want to serialize that object at all, depending upon conditions within that object instance. Rather than having to write separate ShouldSerialize[PropertyName] for each field in which that object appears, it would be simpler if the object could determine for itself whether it should be persisted.

      I have written a custom convention to implement this scheme, but it seems like it may be of more general use to the user community, and would be pretty simple to impement:

      public interface IControlledSerialization
      {
      bool ShouldSerialize();
      }

      Classes that have consistent criteria for serialization can then implement this interface, and use whatever criteria are appropriate for the action.

      If the interface (and the corresponding convention) were built into the driver, I think it would be useful to many.

            Assignee:
            Unassigned Unassigned
            Reporter:
            curt Curt Mayers
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: