I'm trying to take a list of objects and serialize them as an objects instead of a list, the object name would be from a property on the object.
The issue I have is that I can get it to work, but I'm have to walk all the properties on the object manually.
I'm wondering if there is some built-in way to do that?
So I have
public class Config
{
public List<Component> Components { get; set; }
}
public class Component
{
public string Name { get; set; }
public string OtherProperties { get; set; }
}
Then I want the output of this to look like
Components:
nameFromObjectProperty:
OtherProperties: ""
nameOfOtherComponent:
OtherProperties: ""
As an option, you can implement custom converter:
Usage:
Example in .NET Fiddle