Ok, so I have this basic class setup...
public class Location
{
public string Name{ get; set; }
private LocationList _LocationList = new LocationList();
public LocationList Locations{ get{ return _LocationList; } }
}
public class LocationList : List<Location>{}
public class ViewModel
{
private LocationList _LocationList = new LocationList();
public LocationList Locations{ get{ return _LocationList; } }
}
which I want to use with the Newtonsoft JSON serializer. However, the serializer doesn't insert the items into the existing collection behind the read-only property accessor, but rather tries to assign an entirely new List to the property, which of course it can't since there isn't a setter.
Now I could just switch to this...
public class Location
{
public string Name{ get; set; }
public LocationList Locations{ get; set; }
}
public class LocationList : List<Location>{}
public class ViewModel
{
public LocationList RootLocations{ get; set; }
}
But now the list property isn't read-only and can be set to null. Even if we make the setter private, JSON deserialization can still set it to null.
What I want is a way to tell the serializer 'Take the items you have in your list and insert them into this already-existing list' rather than saying 'Replace my list with yours altogether'.
So can this be done, or am I going to have to write my own JSON serialization converter and plug that in?
M