24 lines
586 B
C#
24 lines
586 B
C#
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|