终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

69 行
2.0 KiB

  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace BPASmartClient.Compiler
  8. {
  9. public class FJson<T> where T : class, new()
  10. {
  11. private static string path
  12. {
  13. get
  14. {
  15. Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"AccessFile\\JSON"));
  16. return AppDomain.CurrentDomain.BaseDirectory + "AccessFile\\JSON\\" + typeof(T).Name + ".json";
  17. }
  18. }
  19. public static T Data
  20. {
  21. get;
  22. set;
  23. } = new T();
  24. public static void Save()
  25. {
  26. string contents = JsonConvert.SerializeObject(Data);
  27. File.WriteAllText(path,contents);
  28. }
  29. public static void Read()
  30. {
  31. if (File.Exists(path))
  32. {
  33. T val = JsonConvert.DeserializeObject<T>(File.ReadAllText(path));
  34. if (val != null)
  35. {
  36. Data = val;
  37. }
  38. }
  39. }
  40. public static void SaveInterface()
  41. {
  42. JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
  43. jsonSerializerSettings.TypeNameHandling = TypeNameHandling.Objects;
  44. string contents = JsonConvert.SerializeObject(Data,Formatting.Indented,jsonSerializerSettings);
  45. File.WriteAllText(path,contents);
  46. }
  47. public static void ReadInterface()
  48. {
  49. if (File.Exists(path))
  50. {
  51. JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
  52. jsonSerializerSettings.TypeNameHandling = TypeNameHandling.Objects;
  53. T val = JsonConvert.DeserializeObject<T>(File.ReadAllText(path),jsonSerializerSettings);
  54. if (val != null)
  55. {
  56. Data = val;
  57. }
  58. }
  59. }
  60. }
  61. }