[CSHARP-528] Support deserializing immutable types Created: 16/Jul/12 Updated: 12/Feb/13 Resolved: 12/Feb/13 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Feature Request |
| Affects Version/s: | 1.5 |
| Fix Version/s: | 1.8 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Tim Kellogg | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | driver, immutable | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
I'm trying to write a F# driver implementation that wraps what the C# driver does. Right now the main thing that I'm getting stuck on is deserializing immutable record types. If I have this F# record: type Person = { Id : BsonObjectId Name : string }it compiles to [roughly] this C# code public class Person public Person(BsonObjectId id, string name) { this.id = id; this.name = name; }public BsonObjectId Id { get { return id; } } } I can configure the BsonClassMapSerializer to serialize objects just fine, however when I try deserializing it skips all the properties of the record because they don't have setter methods. A big part of the problem is that BsonClassMapSerializer does 90% of what I need, but it's an internal class. Even if it were public, it's too much of a behemoth to be able to customize via subclassing. A better solution might be to add configuration to class maps. Perhaps an interface such as: interface IMemberAccumulator { object Initialize(Type nominalType); void AccumulateMember(object state, Type nominalType, MemberInfo memberInfo, object value); object GetFinalValue(object state, Type nominalType); }and a `BsonClassMap.SetMemberAccumulator(IMemberAccumulator)` would probably get me what I need. I'm sure this sort of thing might even be useful for other languages, including C#. https://github.com/tkellogg/MongoDB.FSharp |
| Comments |
| Comment by Robert Stam [ 12/Feb/13 ] |
|
Implemented by |
| Comment by Tim Kellogg [ 17/Jul/12 ] |
|
yeah that's what I need. Probably a better implementation too. Thanks! |
| Comment by Craig Wilson [ 16/Jul/12 ] |
|
Tim, |