Пример #1
0
        static void Main(string[] args)
        {
            Department dep = new Department(506, "IT Heaven");
            Employee e = new Employee(101, "Martin", "Hromek", dep);

            Console.WriteLine("Serializing...");

            //XmlSerialization(e);
            //BinarySerialization(e);
            JsonSerializovat();

            Console.WriteLine("Finish.");
        }
Пример #2
0
        private static void XmlSerialization(Employee e)
        {
            Console.WriteLine("Original object: {0}", e.ToString());

            using (FileStream stream = new FileStream("c:\\temp\\employee.xml", FileMode.Create, FileAccess.Write))
            {
                XmlSerializer formatter = new XmlSerializer(e.GetType());
                formatter.Serialize(stream, e);
            }

            System.Threading.Thread.Sleep(2000);
            Console.WriteLine("Deserializing...");
            using (FileStream stream = new FileStream("c:\\temp\\employee.xml", FileMode.Open, FileAccess.Read))
            {
                XmlSerializer formatter = new XmlSerializer(e.GetType());
                Employee e2 = (Employee)formatter.Deserialize(stream);
                Console.WriteLine("Desirialized object: {0}", e2.ToString());
            }
        }