Goal
I currently have a valid method of saving the information
I then want the program to load the saved state upon clicking a 'load' button after exiting.
I then want the program to display the data in the appropriate place
In the form I have two DataGridView's one for an employee and another for a supervisor.
=============================================================
Method
I have serialised two generic lists into a .dat file
BinaryFormatter bFormatter = new BinaryFormatter();
using (FileStream fs = new FileStream(FILENAME, FileMode.OpenOrCreate))
{
bFormatter.Serialize(fs, employees);
bFormatter.Serialize(fs, supervisors);
}
So far in the .dat file, I have 3 Employees and 2 Supervisors, and I am not sure how to extract the information and place them into the appropriate place
The lists are as follows:
List<Employee> employees = new List<Employee>();
List<Supervisor> supervisors = new List<Supervisor>();
Employee e1 = new Employee(MemberJob.Employee, "Name", MemberSkills.CPlus | MemberSkills.CSharp, false);
Supervisor s1 = new Supervisor(MemberJob.Supervisor, "Another name", false);
employees.Add(e1);
supervisors.Add(s1);
=========================================================================
Attempt
I have had an extensive look around the internet and on Stackoverflow, but mainly it's irrelevant to my context or they are using the XML format which I do not want to use.
I assumed it would just be a case of replicating the serialize
method and just changing the bFormatter.Serialize(fs, employees);
to bFormatter.Deserialize(fs, employees);
but I am stuck on what to do after I deserialize the list.
BinaryFormatter bFormatter = new BinaryFormatter();
FileStream fs = File.Open(FILENAME, FileMode.Open);
object obj = bFormatter.Deserialize(fs);
The object then brings back the data I need but I cannot put the object obj
data into a usable format, it is stuck in the object obj
if possible I'd like to try to put it back into the Employee list