[CSHARP-1068] Improve Default Value Handling Created: 17/Sep/14  Updated: 25/Mar/19  Resolved: 25/Mar/19

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Peter Garafano (Inactive) Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends

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



 Comments   
Comment by Ian Whalen (Inactive) [ 25/Mar/19 ]

Closing as Won't Fix, but you should be able to achieve this by writing a new MemberMap convention.

Generated at Wed Feb 07 21:38:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.