支援多用戶登入器規劃,預留集合序列化介面。使用 `BinaryFormatter` 將 `UserInfo` / `List
public static void SerializeUserInfo(UserInfo ui)
{
try
{
using (var fs = new FileStream(Path.Combine(Application.StartupPath, "UserInfo.bin"), FileMode.Create))
{
new BinaryFormatter().Serialize(fs, ui);
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
public static UserInfo DeserializeUserInfo()
{
try
{
using (var fs = new FileStream(Path.Combine(Application.StartupPath, "UserInfo.bin"), FileMode.Open))
{
return (UserInfo)new BinaryFormatter().Deserialize(fs);
}
}
catch { return null; }
}
public static void SerializeList(List list)
{
try
{
using (var fs = new FileStream(Path.Combine(Application.StartupPath, "UserInfo.bin"), FileMode.Create))
{
new BinaryFormatter().Serialize(fs, list);
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
public static List DeserializeList()
{
try
{
using (var fs = new FileStream(Path.Combine(Application.StartupPath, "UserInfo.bin"), FileMode.Open))
{
return (List)new BinaryFormatter().Deserialize(fs);
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); return null; }
}