using System; using System.Dynamic; using System.Reflection; using System.Runtime.CompilerServices; using Newtonsoft.Json; [assembly: InternalsVisibleTo("deployment.tests")] namespace greyn.Deployment { public static class ConfigurationBootstrapper { private const string confpath = "appsettings.json"; public static T Load() where T : new() { if (File.Exists("appsettings.json")) { /* * if the configuration expects new values we write them in. * if you left other junk for whatever reason, get rekt */ var toReturn = JsonConvert.DeserializeObject(File.ReadAllText(confpath)) ?? new T(); File.WriteAllText(confpath, JsonConvert.SerializeObject(toReturn, Formatting.Indented)); return toReturn; } else { var toReturn = new T(); File.WriteAllText(confpath, JsonConvert.SerializeObject(toReturn)); return toReturn; } } } }