Exemplo n.º 1
0
 /// <summary>
 /// 用json字符串更改配置
 /// </summary>
 /// <param name="jsonString"></param>
 public void SetConfig(string jsonString)
 {
     try
     {
         var config = JsonConvert.DeserializeObject <JsonFileConfig>(jsonString);
         _lazyInstance = new JsonFileConfig();
         WriteToFile();
     }
     catch
     {
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 从文件读取配置
 /// </summary>
 /// <returns></returns>
 public static JsonFileConfig ReadFromFile()
 {
     try
     {
         var str    = File.ReadAllText(PathAndFileName);
         var config = JsonConvert.DeserializeObject <JsonFileConfig>(str);
         return(config);
     }
     catch (FileNotFoundException)
     {
         var config = new JsonFileConfig();
         config.WriteToFile();
         return(new JsonFileConfig());
     }
     catch (StackOverflowException)
     {
         var config = new JsonFileConfig();
         config.WriteToFile();
         return(new JsonFileConfig());
     }
 }