Elaborating on my comment, you're better off converting your static class into an instance class for minimizing manual coding to store/read the property values in the future. This refactoring can be done in minutes. So do that as a first step, it shouldn't take too long to do, and a simple "Find/Replace" can fix all of your declarations everywhere in your code where you previously used "Configuration".
- Keep your implementation static, but change to a single instance that you are accessing.
public class Configuration
{
private static Configuration instance;
public static Configuration Instance
{
get
{
if (instance == null)
{
instance = new Configuration();
}
return instance;
}
set
{
instance = value;
}
}
public bool A { get; set; }
public bool B { get; set; }
public int C { get; set; }
}
- Do a Find/Replace where ever you declared your static class and replace "Configuration." with "Configuration.Instance.". Also, where you previously declared static properties like
public static bool A; public static bool B; ...
just select all of the text, do a Find/Replace and replace "static " with "".
- Save/Read your data
// To Save
File.WriteAllText(@"c:\temp\myconfig.json", Newtonsoft.Json.JsonConvert.SerializeObject(Configuration.Instance));
// To Read
using (var file = File.OpenText(@"c:\temp\myconfig.json"))
{
JsonSerializer serializer = new JsonSerializer();
Configuration.Instance = (Configuration)serializer.Deserialize(file, typeof(Configuration));
}