Consider the below example program
var calendar = new Calendar
{
Id = 42,
CoffeeProvider = "Espresso2000",
Meetings = new[]
{
new Meeting
{
Location = "Room1",
From = DateTimeOffset.Parse("2014-01-01T00:00:00Z"),
To = DateTimeOffset.Parse("2014-01-01T01:00:00Z")
},
new Meeting
{
Location = "Room2",
From = DateTimeOffset.Parse("2014-01-01T02:00:00Z"),
To = DateTimeOffset.Parse("2014-01-01T03:00:00Z")
},
}
};
var patch = @"{
'coffeeprovider': null,
'meetings': [
{
'location': 'Room3',
'from': '2014-01-01T04:00:00Z',
'to': '2014-01-01T05:00:00Z'
}
]
}";
var patchedCalendar = Patch(calendar, patch);
The result of the Patch()
method should be equal to calendar
except as changed by patch
. That means; Id
would be unchanged, CoffeeProvider
would be set to null
and Meetings
would contain a single item located in Room3.
How does one create a general
Patch()
method that will work for any object (not just the example Calendar object) deserializable by Json.NET?If (1) this is not feasible, what would be some restrictions that would make it feasible and how would it be implemented?