예제 #1
0
 /// <summary>
 /// Load a json from a given path
 /// </summary>
 /// <typeparam name="T">The type to cast to</typeparam>
 /// <param name="path">The path toi load from</param>
 /// <param name="isPathFile">Is it the path file (Where the path for all config is written)</param>
 /// <returns>The instance of the config</returns>
 public static T LoadJson <T>(string path, bool isPathFile = false)
 {
     if (!File.Exists(path))
     {
         if (isPathFile)
         {
             Config = new ConfigLoaderConfig();
             Directory.CreateDirectory(Config.Path);
             File.WriteAllText("Config.json", JsonConvert.SerializeObject(Config, Formatting.Indented));
         }
         Console.WriteLine(
             String.Format("Impossible to load the config file ({0}). An empty config file was created", path));
     }
     return(JsonConvert.DeserializeObject <T>(File.ReadAllText(path)));
 }
예제 #2
0
 /// <summary>
 /// Initializes the class
 /// </summary>
 public static void InitConfig()
 {
     Config = LoadJson <ConfigLoaderConfig>("config.json", true);
 }