Suppose I have 2 objects:
public class CInfo
{
[JsonProperty(PropertyName = "Id")]
public string cID { get; set; }
[JsonProperty(PropertyName = "Name")]
public string cName { get; set; }
}
public class Event
{
[JsonProperty(PropertyName = "Time")]
public DateTime dateTime { get; set; }
[JsonProperty(PropertyName = "Note")]
public string comment { get; set; }
}
Couple of functions return the following:
CInfo cInfo = getCInfo();
List<Event> = getEvents();
Both of these meant to be combined together, into a final (hypothetical) object that needs to look this:
public class CInfoWithEvents
{
[JsonProperty(PropertyName = "Id")]
public string cID { get; set; }
[JsonProperty(PropertyName = "Name")]
public string cName { get; set; }
[JsonProperty(PropertyName = "Events")]
public List<Event> { get; set; }
}
At which point the intention is to do a JsonConvert.SerialzeObject(CInfoWithEvents)
, and get a json string representing this final object.
Question: what is the best way to combine them? There has to be a more elegant way than just creating whole new object and copying each property, or worse: serialize cInfo
and List<Event>
separately and do some sort of string manipulation.
Thank you for your time