Its classes have properties that are complex (classes) then they need to be instantiated, so that you have access to their innermost properties, look at the changes:
public class Name
{
public string type { get; set; }
}
public class Items
{
public string type { get; set; }
}
public class Hobbies
{
public Hobbies()
{
items = new Items();
}
public string type { get; set; }
public Items items { get; set; }
}
public class Properties
{
public Properties()
{
hobbies = new Hobbies();
name = new Name();
}
public Name name { get; set; }
public Hobbies hobbies { get; set; }
}
public class Example
{
public Example()
{
properties = new Properties();
}
public string description { get; set; }
public string type { get; set; }
public Properties properties { get; set; }
}
The sequence would be in builder of Hobbies instantiate Items, in the builder of Properties is instantiated Hobbies and Name and finally within the builder Example is instantiated Properties.
Online Project
If by chance do not want to do so, after instantiating Example if you can instantiate the classes as well, but I believe that the form I gave you is ideal, if you are going to use all this code, an example with another way to work with these instances:
using Newtonsoft.Json;
public class Name
{
public string type { get; set; }
}
public class Items
{
public string type { get; set; }
}
public class Hobbies
{
public string type { get; set; }
public Items items { get; set; }
}
public class Properties
{
public Name name { get; set; }
public Hobbies hobbies { get; set; }
}
public class Example
{
public string description { get; set; }
public string type { get; set; }
public Properties properties { get; set; }
}
public class Program
{
public static void Main()
{
Example model = new Example();
model.properties = new Properties();
model.properties.name = new Name();
model.properties.hobbies = new Hobbies();
model.properties.hobbies.items = new Items();
model.properties.name.type = "cc";
var data = JsonConvert.SerializeObject(model);
System.Console.WriteLine(data);
}
}
Online Project
Now I understand where I went wrong, thank you Virgilio :)
– Matheus Miranda