adam
dd7efe9155
"no, please explain each and every nuance of it in excruciating detail." "eh. the gist is good enough."
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
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<T>() 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<T>(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;
|
|
}
|
|
}
|
|
}
|
|
}
|