public Cserialization(ref Ccontroler obj) { obj = Mdeserialize(); if (obj == null) { obj = Mdeserialize(); } }
public void Mserialize(Ccontroler obj) { FileStream fs = new FileStream("db.bat", FileMode.OpenOrCreate); BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(fs, obj); } catch (SerializationException ex) { Console.WriteLine("Failed to serialize . Reason: " + ex.ToString()); } finally { fs.Close(); } }
public Ccontroler Mdeserialize() { Ccontroler newobj = null; FileStream fs = new FileStream("db.bat", FileMode.OpenOrCreate); try { BinaryFormatter formatter = new BinaryFormatter(); newobj = (Ccontroler)formatter.Deserialize(fs); } catch (Exception) { fs.Close(); Mserialize(new Ccontroler()); return(null); } finally { fs.Close(); } return(newobj); }