Given the following class:
public class Config {
public string Property1 {get; set;} = "foo";
public string Property2 {get; set;} = "bar";
public string Property3 {get; set;} = "baz";
public string Property4 {get; set;} = "baz1";
}
I want to serialize an instance of this class into two separate JSON strings. Some of the properties should go into the first JSON string:
{
"Property1": "foo",
"Property2": "bar"
}
while the rest of the properties should go into the other JSON string:
{
"Property3": "baz",
"Property4": "baz1"
}
The division of properties is always the same, and properties will go either to one or the other.
(I can deserialize the two JSON strings back into a single object using JObject.Merge.)
Currently, I am writing to a pair of JObject instances, but that is a maintenance nightmare (json["Property1"] = x.Property1; json["Property2"] = x.Property2; etc.).
How can I do this in a way which is easier to maintain?