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

Improve Default Value Handling

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • Serialization
    • None

    Description

      Currently, we allow default Serializers to be registered for all types in the current AppDomain. We also allow Default values to be configured for a field on a per class basis. For example:

      BsonClassMap.RegisterClassMap<SomeClass>(x =>
      {
          x.AutoMap();
          x.MapField(y => y.SomeProperty).SetDefaultValue(new SomeOtherClass());
      });

      The ability to call SetDefaultValue for a particular type (in this case, SomeOtherClass) for all references to the type within the current AppDomain would be helpful in ensuring incorrect or null values do not get written to the database (or deserialized from the database) if a SetDefaultValue is forgotten in a BsonClassMap call.

      Something similar to the way a BsonSerializer is registered, like:

      BsonSerializer.RegisterDefaultValue(typeof(SomeOtherClass), () => new SomeOtherClass());

      Attachments

        Activity

          People

            Unassigned Unassigned
            peter.garafano@mongodb.com Peter Garafano (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: