Improve Default Value Handling

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Fix
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Serialization
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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());
      

            Assignee:
            Unassigned
            Reporter:
            Peter Garafano (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: