public static void Main() { var trainee = new Trainee() { FirstName = "Uzair", LastName = "Khan", SpartaNo = 1 }; var trainee2 = new Trainee() { FirstName = "Git", LastName = "Hub", SpartaNo = 2 }; var course = new Course() { Subject = "C# SDET", Title = "Eng86", StartDate = DateTime.Now }; course.AddTrainee(trainee); course.AddTrainee(trainee2); //var _serialiser = new SerialiserBinary(); //_serialiser.SerialiseToFile($"{_path}/BinaryFile.bin", trainee); //var deserializedTrainee = _serialiser.DeserialiseFromFile<Trainee>($"{_path}/BinaryFile.bin"); //var _serialiser = new SerialiserXML(); //_serialiser.SerialiseToFile($"{_path}/XMLTrainee.xml", trainee); //var deserializedTrainee = _serialiser.DeserialiseFromFile<Trainee>($"{_path}/XMLTrainee.xml"); //var _serialiser = new SerialiserXML(); //_serialiser.SerialiseToFile($"{_path}/XMLCourse.xml", course); //var deserializedCourse = _serialiser.DeserialiseFromFile<Course>($"{_path}/XMLCourse2.xml"); var _serialiser = new SerialiserJSON(); _serialiser.SerialiseToFile($"{_path}/JSONCourse.xml", course); var deserializedCourse = _serialiser.DeserialiseFromFile <Course>($"{_path}/JSONCourse.xml"); }
static void Main(string[] args) { //Create a trainee Trainee t1 = new Trainee { FirstName = "Cathy", LastName = "French", SpartaNo = 100 }; //the file we get is not in human readable format. Can be found in Documents folder SerializeToFileJSON(t1); //Trainee t2 = DeserializeFromFileJSON("100 - Cathy French.json"); Course eng83 = new Course { Title = "Engineering 83", Subject = "C# SDET", StartDate = new DateTime(2021, 3, 16) }; eng83.AddTrainee(t1); eng83.AddTrainee(new Trainee { FirstName = "Martin", LastName = "Beard", SpartaNo = 101 }); SerializeToFileJSON(eng83); Course otherCourse = DeserializeCourseFromFileJSON("NewCourse.json"); }
static void Main(string[] args) { ////Create a Trainee var trainee = new Trainee { FirstName = "Hamse", LastName = "Ahmed", SpartaNo = 100 }; ////Crete a binary serializer //var serializer = new SerializerBinary(); //serializer.SerializeToFile($"{_path}/BinaryTrainee.bin", trainee); ////Read the trainee back //var deserialisedBinaryTrainee = serializer.DeserializeFromFile<Trainee>($"{_path}/BinaryTrainee.bin"); ////Serialize our trainee in xml _serializer = new SerealizerXML(); ////write trainee to file(xml) //_serializer.SerialiseToFile($"{_path}/XMLTrainee.xml", trainee); ////Create and Serialize a Course to XML var eng86 = new Course { Title = "Engineering86", Subject = "C# SDET", StartDate = new DateTime(2021, 5, 3) }; //eng86.AddTrainee(trainee); //eng86.AddTrainee(new Trainee { FirstName = "Uzair", LastName = "Khan", SpartaNo = 101 }); //_serializer.SerialiseToFile($"{_path}/XMLCourse.xml", eng86); ////var editedCourse = _serializer.DeserialiseFromFile<Course>($"{_path}/XMLCourseEdited.xml"); /// _serializer = new SerializeJSON(); _serializer.SerialiseToFile($"{_path}/JsonTrainee.json", trainee); _serializer.SerialiseToFile($"{_path}/JsonCourse.json", eng86); ////Open edited version //var editedCourse2 = _serializer.DeserialiseFromFile<Course>($"{_path}/JsonCourse2.json"); }
public void AddTrainee(Trainee newTrainee) { Trainees.Add(newTrainee); }