Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            List <Human> hum          = (new Human[] { new Human("Obama"), new Professor("Avdoshka", "PI") }).ToList();
            var          dep1         = new Department[] { new Department("PI", hum), };
            var          university   = new University("HSE", new List <Department>(dep1));
            var          universities = new University[] { university };

            (new JSONCollectionSerializer <University>()).Serialize("univ.xml", universities, new Type[]
            {
                typeof(Department),
                typeof(Professor),
                typeof(Human)
            });
            var ans = (new JSONCollectionDeserializer <University>()).Deserialize("univ.xml", new Type[]
            {
                typeof(Department),
                typeof(Professor),
                typeof(Human)
            });

            Console.WriteLine(ans);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            University HSE = new University();

            HSE.UniversityName = "NRU HSE";
            Human[]     deptStaff = { new Professor("Ivanov", "PI"),
                                      new Professor("Petrov",     "PI") };
            Departament SE = new Departament(deptStaff.ToList(), "SE");

            HSE.Departaments = new List <Departament>();
            HSE.Departaments.Add(SE);


            University HSE1 = new University();

            HSE1.UniversityName = "NRU HSE";
            Human[]     deptStaff1 = { new Professor("Ivanov2", "PI2"),
                                       new Professor("Petrov2",     "PI2") };
            Departament SE2 = new Departament(deptStaff.ToList(), "SE2");

            HSE1.Departaments = new List <Departament>();
            HSE1.Departaments.Add(SE2);

            using (FileStream stream = new FileStream("xml.xml", FileMode.OpenOrCreate))
            {
                var formatter = new XmlSerializer(typeof(University[]), new Type[] { typeof(Departament), typeof(Professor), typeof(Human) });
                formatter.Serialize(stream, new University[] { HSE, HSE1 });
            }

            using (FileStream stream = new FileStream("xml.xml", FileMode.OpenOrCreate))
            {
                var formatter = new XmlSerializer(typeof(University[]), new Type[] { typeof(Departament), typeof(Professor), typeof(Human) });
                var obj       = (University[])formatter.Deserialize(stream);
                Console.WriteLine(obj);
            }
        }