public object ReadBinary(string file, ref ResultBinary resultBinary) { String Path = CurPath + "\\" + file; try { using (Stream outPut = File.OpenRead(Path)) { BinaryFormatter bf = new BinaryFormatter(); object user = bf.Deserialize(outPut); if (user != null) { resultBinary.Inf = "读取成功"; resultBinary.Result = true; return(user); } } } catch { resultBinary.Inf = "读取失败"; resultBinary.Result = false; } return(null); }
public void WriteBinary(object obj, string file, ref ResultBinary resultBinary) { try { String Path = CurPath + "\\" + file; using (Stream input = File.OpenWrite(Path)) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(input, obj); resultBinary.Result = true; resultBinary.Inf = "写入成功"; } } catch { resultBinary.Inf = "写入失败"; resultBinary.Result = false; } }