[CSHARP-169] Deserialize Arrays to Properties without Setter Created: 14/Feb/11  Updated: 08/Feb/23  Resolved: 03/Dec/20

Status: Closed
Project: C# Driver
Component/s: Feature Request
Affects Version/s: 0.11
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Thomas Tucker Assignee: Unassigned
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-1999 Support for readonly properties/field... Closed
is duplicated by CSHARP-782 Respect Already Instantiated Collecti... Closed

 Description   

Provide support for De-serializing Arrays to read only properties

Like so:
private List<contact> _contacts;

public IEnumerable<contact> Contacts
{
get

{ if (_contacts == null) _contacts = new List<contact>(); return _contacts; }

}



 Comments   
Comment by Daniel Hegener [ 24/Nov/17 ]

Potential duplicate of CSHARP-1999 which I already created a pull request for.

Comment by David Pfeffer [ 29/Jul/13 ]

I really need to be able to reuse my existing, constructor instantiated, instances.

Comment by Alexander Nagy [ 16/Apr/12 ]

IMO a better way to implement this would be to have a private setter and support a PrivateMemberFinderConvention. Such an approach would be cleaner and wouldn't require decompilation with semantic inference.

Example:

private List<contact> _contacts;

public IEnumerable<contact> Contacts

{ get { if (_contacts == null) _contacts = new List<contact>(); return _contacts; }

}
private set
{
_contacts = value;
}

var conventionProfile = ConventionProfile.GetDefault()
.SetMemberFinderConvention(
new PrivateMemberFinderConvention());

BsonClassMap.RegisterConventions(
conventionProfile,
type => type == typeof(MyType));

BTW, we've already got this implemented in our private fork, wouldn't be hard to push this out.

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