deployment/Deployment/Configuration.cs

24 lines
586 B
C#
Raw Normal View History

using System;
using Newtonsoft.Json;
namespace Deployment;
public static class ConfigurationBootstrapper
{
private const string confpath = "appsettings.json";
public static T Load<T>() where T : new()
{
if(File.Exists("appsettings.json"))
{
return JsonConvert.DeserializeObject<T>(File.ReadAllText(confpath)) ?? new T();
}
else
{
var toReturn = new T();
File.WriteAllText(confpath, JsonConvert.SerializeObject(toReturn));
return toReturn;
}
}
}