All pastes #468448 Raw Edit

Untitled

public text v1 · immutable
·published 2007-05-03 03:23 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;


namespace InsulinSim
{
    class SimFileManager
    {
        string err;
        BinaryFormatter bformatter;
        Stream stream;

        public SimFileManager()
        {

        }


        public Person openPerson(String path){
            Person p;
            stream = File.Open(path, FileMode.Create);

            bformatter = new BinaryFormatter();
            
            p = (Person)bformatter.Deserialize(stream);
           
            stream.Close();
            
            return p;

        }

        public bool savePerson(Person p, String path){

            stream = File.Open(path, FileMode.Create);

            bformatter = new BinaryFormatter();

            try
            {
                bformatter.Serialize(stream, p);
            }
            catch
            {

                return false; ;

            }
            finally
            {
                stream.Close();
            }


            return true;
        }
    }
}