示例#1
0
 public Cserialization(ref Ccontroler obj)
 {
     obj = Mdeserialize();
     if (obj == null)
     {
         obj = Mdeserialize();
     }
 }
示例#2
0
        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();
            }
        }
示例#3
0
        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);
        }