I want to create my own Serializer from scratch for c#, I'm familiar with newtonsoft and other c# serializes but want to avoid using them (trying to remove dependencies in my project) I know that Json is just a string, so I can append strings but I want to use classes.
For example, I have a simple class here and I want to create a JSON.
public class Account
{
public string Email { get; set; }
public bool Active { get; set; }
public DateTime CreatedDate { get; set; }
public IList<string> Roles { get; set; }
}
Account account = new Account
{
Email = "james@example.com",
Active = true,
CreatedDate = new DateTime(2013, 1, 20, 0, 0, 0, DateTimeKind.Utc),
Roles = new List<string>
{
"User",
"Admin"
}
};
string json = JsonConvert.SerializeObject(account, Formatting.Indented);
// Want to create alternative for this line.
Is there a recommended way to achieve it? Any references will be helpful, I failed to find anything relevant.