[CSHARP-541] Make BsonClassMap<TClass>.MapMember Typesafe Created: 27/Jul/12  Updated: 20/May/19  Resolved: 20/May/19

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

Type: Improvement Priority: Minor - P4
Reporter: Alexander Nagy Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All



 Description   

Right now the BsonClassMap<TClass>.MapMember functionality is cumbersome because the returned type is of type BsonMemberMap rather than BsonMemberMap<TMember>. This forces the user to always recast when dealing with various BsonMemberMap Set methods.

This is error prone, overly verbose, and violates the design principle of forcing the caller reprovide information that has already been specified.

Consider the current situation:

BsonClassMap.RegisterClassMap<MyType>(classMap =>

{ classMap.AutoMap(); classMap.MapMember(myType => myType.MyField) .SetShouldSerializeMethod(obj => !((MyType)obj).MyField != null); }

);

Instead it really should be:

BsonClassMap.RegisterClassMap<MyType>(classMap =>

{ classMap.AutoMap(); classMap.MapMember(myType => myType.MyField) .SetShouldSerializeMethod(myType => myType.MyField != null); }

);



 Comments   
Comment by Ian Whalen (Inactive) [ 20/May/19 ]

optimiz3 thanks a lot for the PR and apologies for the delay in responding here. Given that this does not add any real new functionality we don't plan to make this change. As such closing as Won't Fix.

Comment by Craig Wilson [ 30/Jul/12 ]

Since this is such a large and braking change, I've assigned this to 2.0.

Comment by Alexander Nagy [ 28/Jul/12 ]

Ended up implementing this, pull request here: https://github.com/mongodb/mongo-csharp-driver/pull/121

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