-
Type: New Feature
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 1.5
-
Component/s: Feature Request
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
{
private readonly BsonObjectId id;
private readonly string name;
public Person(BsonObjectId id, string name)
{ this.id = id; this.name = name; }public BsonObjectId Id { get
{ return id; } }
public string Name { get
}
}
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#.
- is related to
-
CSHARP-476 Support parameterized constructors on deserialization
- Closed