/// <summary> /// 恢复 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="filePath">文件路径</param> /// <returns>返回对象</returns> public static T RecoveryJson <T>(string filePath) where T : new() { var result = new T(); if (FileSystemHelper.IsFileExists(filePath)) { string value = File.ReadAllText(filePath); result = ConverterManager.GetConverter().Deserialize <T>(value); } return(result); }
/// <summary> /// 保存 /// </summary> /// <param name="filePath">文件路径</param> /// <param name="value">持久化对象</param> public static void SaveJson(string filePath, object value) { FileSystemHelper.CreateDirectory(filePath); File.WriteAllText(filePath, ConverterManager.GetConverter().Serialize(value)); }