Пример #1
0
 /// <summary>
 /// 读取文件
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static async Task <T> GetConfig <T>(string fileName)
 {
     return(await Task.Run(() =>
     {
         JsonFileHelper jsonFileHelper = new JsonFileHelper(fileName);
         T jObject = jsonFileHelper.Read <T>();
         return jObject;
     }));
 }
Пример #2
0
        /// <summary>
        /// 写入文件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static async Task <bool> SetConfig <T>(string fileName, T data)
        {
            JsonFileHelper         jsonFileHelper = new JsonFileHelper(fileName);
            Dictionary <string, T> json           = new Dictionary <string, T>
            {
                { "data", data }
            };

            jsonFileHelper.Write(json);
            JObject jObject = await GetConfig <JObject>(fileName);

            string str         = jObject.GetValue("data").ToString();
            T      baseConfigs = JsonConvert.DeserializeObject <T>(str);

            return(baseConfigs != null && !baseConfigs.Equals(data));
        }