|
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmart.ConfigurationSoftware
- {
- public class ProjectDataServer<TClass> where TClass : class, new()
- {
- public static TClass Data { get; set; } = new TClass();
-
- /// <summary>
- /// 保存数据
- /// </summary>
- public static void Save(string path)
- {
- FileStream fs = new FileStream(path, FileMode.Create);
- BinaryFormatter bf = new BinaryFormatter();//创建一个二进制格式化器
- bf?.Serialize(fs, Data);
- fs.Close();
- }
-
- /// <summary>
- /// 获取保存的数据
- /// </summary>
- public static void Read(string path)
- {
- if (File.Exists(path))
- {
- FileStream fs = new FileStream(path, FileMode.Open);
- BinaryFormatter bf = new BinaryFormatter();
- var res = (TClass)bf.Deserialize(fs);
- fs.Close();
- }
- }
- }
- }
|