[CSHARP-1077] Support deserialization of readonly collection interfaces (IReadOnlyCollection<T>, IReadOnlyLis<T>t) Created: 23/Sep/14  Updated: 08/Apr/15  Resolved: 08/Apr/15

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

Type: New Feature Priority: Minor - P4
Reporter: Bar Arnon Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

The driver does support serialization of these types, as they extend IEnumerable<T>, but it doesn't support deserialization.

It's unfortunate as these types are the only option for properties that are both readonly (as IEnumerable<T> is) and imply they are already materialized (which IEnumerable<T> isn't).



 Comments   
Comment by Robert Stam [ 08/Apr/15 ]

This is now supported in the 2.0 version of the driver.

The following class can be successfully serialized and deserialized:

public class C
{
    public int Id;
    public IReadOnlyCollection<int> Values;
}

And the serialized form looks like this:

{ "_id" : 1, "Values" : [1, 2, 3] }

Comment by Craig Wilson [ 30/Sep/14 ]

Thanks for the report. We have not been compiling for .NET 4 or .NET 4.5 in our 1.x branch and as such don't have access to these types. However, our next major version, 2.0, will be targetting .NET 4.5. We certainly should include support for these types. We are using them heavily in the actual driver code and know their benefits.

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