终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace BPASmart.ConfigurationSoftware
  9. {
  10. public class ProjectDataServer<TClass> where TClass : class, new()
  11. {
  12. public static TClass Data { get; set; } = new TClass();
  13. /// <summary>
  14. /// 保存数据
  15. /// </summary>
  16. public static void Save(string path)
  17. {
  18. FileStream fs = new FileStream(path, FileMode.Create);
  19. BinaryFormatter bf = new BinaryFormatter();//创建一个二进制格式化器
  20. bf?.Serialize(fs, Data);
  21. fs.Close();
  22. }
  23. /// <summary>
  24. /// 获取保存的数据
  25. /// </summary>
  26. public static void Read(string path)
  27. {
  28. if (File.Exists(path))
  29. {
  30. FileStream fs = new FileStream(path, FileMode.Open);
  31. BinaryFormatter bf = new BinaryFormatter();
  32. var res = (TClass)bf.Deserialize(fs);
  33. fs.Close();
  34. }
  35. }
  36. }
  37. }