static void Main(string[] args) { if (args.Length == 0) { // If they provide no arguments, display the last person Person p = Deserialize(); Console.WriteLine(p.ToString()); } else { try { if (args.Length != 4) { throw new ArgumentException("You must provide four arguments."); } DateTime dob = new DateTime(Int32.Parse(args[1]), Int32.Parse(args[2]), Int32.Parse(args[3])); Person p = new Person(args[0], dob); Console.WriteLine(p.ToString()); Serialize(p); } catch (Exception ex) { DisplayUsageInformation(ex.Message); } } Console.ReadKey(); }
private static void Serialize(Person sp) { // TODO: Serialize sp object to binnaryserializer .dat to xml .xml using (FileStream fs = new FileStream("Person.xml", FileMode.Create)) { //Exercise Number 1 BinaryFormatter bf = new BinaryFormatter(); //XmlSerializer xs = new XmlSerializer(typeof(Person)); Console.WriteLine("Serialazed"); bf.Serialize(fs, sp); //xs.Serialize(fs, sp); } }