public static bool Load(string filename, ref ResearcherObservable obj) { bool f = true; FileStream fs = null; try { fs = File.OpenRead(filename); BinaryFormatter bf = new BinaryFormatter(); obj = bf.Deserialize(fs) as ResearcherObservable; obj.CollectionChanged += obj.CollectionChangedEventHandler; } catch (Exception ex) // мб другая обработка { MessageBox.Show(ex.Message); //Console.WriteLine(ex.Message); //obj = new ResearcherObservable(); f = false; } finally { if (fs != null) { fs.Close(); } } return(f); }
public static bool Save(string filename, ResearcherObservable obj) { bool f = true; FileStream fs = null; try { fs = File.Open(filename, FileMode.OpenOrCreate); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, obj); } catch (Exception ex) { MessageBox.Show(ex.Message); //Console.WriteLine(ex.Message); f = false; } finally { if (fs != null) { fs.Close(); } } return(f); }