Пример #1
0
        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);
                }
            }
        }
Пример #2
0
 private static void Serialize(Person sp)
 {
     BinaryFormatter bf = new BinaryFormatter();
     FileStream fs = new FileStream("Person.dat", FileMode.Create);
     bf.Serialize(fs, sp);
     fs.Close();
 }
        private static Person Deserialize()
        {
            Person dsp = new Person();

            // TODO: Restore previously serialized Person object

            return dsp;
        }
Пример #4
0
        private static void Serialize(Person sp)
        {
            FileStream fs = new FileStream("Person.Dat", FileMode.Create);

            XmlSerializer xs = new XmlSerializer(typeof(Person));

            xs.Serialize(fs, sp);

            fs.Close();
        }
Пример #5
0
 private static void Serialize(Person sp)
 {
     // Create file to save the data to
     FileStream fs = new FileStream("Person.Dat", FileMode.Create);
     // Create a BinaryFormatter object to perform the serialization
     BinaryFormatter bf = new BinaryFormatter();
     // Use the BinaryFormatter object to serialize the data to the file
     bf.Serialize(fs, sp);
     // Close the file
     fs.Close();
 }
Пример #6
0
 private static Person Deserialize()
 {
     Person dsp = new Person();
     // Open file to read the data from
     FileStream fs = new FileStream("Person.Dat", FileMode.Open);
     // Create a BinaryFormatter object to perform the deserialization
     BinaryFormatter bf = new BinaryFormatter();
     // Use the BinaryFormatter object to deserialize the data from the file
     dsp = (Person)bf.Deserialize(fs);
     // Close the file
     fs.Close();
     return dsp;
 }
Пример #7
0
        private static void Serialize(Person sp)
        {
            // Create file to save the data to
            FileStream fs = new FileStream("Person.XML", FileMode.Create);

            // Create an XmlSerializer object to perform the serialization
            XmlSerializer xs = new XmlSerializer(typeof(Person));

            // Use the XmlSerializer object to serialize the data to the file
            xs.Serialize(fs, sp);

            // Close the file
            fs.Close();
        }
Пример #8
0
        private static Person Deserialize()
        {
            Person dsp = new Person();

            // Create file to save the data to
            FileStream fs = new FileStream("Person.XML", FileMode.Open);

            // Create an XmlSerializer object to perform the serialization
            XmlSerializer xs = new XmlSerializer(typeof(Person));

            // Use the XmlSerializer object to serialize the data to the file
            dsp = (Person)xs.Deserialize(fs);

            // Close the file
            fs.Close();
            return dsp;
        }
 private static void Serialize(Person sp)
 {
     // TODO: Serialize sp object
 }