Hopefully this is possible and straightforward. But I would like to dynamically populate the dynamic object at runtime so I can use a json schema generator (for a swagger file)
I have a list that I want to populate the object with. I.e each item in a list will be a property within the dynamic object.
This is the non adding dynamic properties way.
using Newtonsoft.Json.Schema;
public class Program
{
public static void Main()
{
dynamic person = new
{
Id = 1,
FirstName = "John",
LastName = "Doe"
};
var schemaGenerator = new JsonSchemaGenerator { };
var schema = schemaGenerator.Generate(person.GetType());
Console.WriteLine(schema.ToString());
}
}
But I would like to loop through a list or json and dynamically create properties in the person object.
I can't see how I can add properties to the person object after it's been created. This can be done with an Expando object, but expando doesn't work as expected with the Schema Generator.