Beispiel #1
0
        public static void Serialization1(Human human)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Human));
            StringBuilder sb = new StringBuilder();

            /* SERIALIZATION */
            using (StringWriter writer = new StringWriter(sb))
            {
                serializer.Serialize(writer, human);
            }
            // XML file
            //Console.WriteLine("SB: " +sb.ToString());
            /* END SERIALIZATION */



            /* DESERIALIZATION */
            Human newMartin = new Human();
            using (StringReader reader = new StringReader(sb.ToString()))
            {
                newMartin = serializer.Deserialize(reader) as Human;
            }
            Console.WriteLine(newMartin.ToString() + Environment.NewLine);
            /* END DESERIALIZATION */
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Human Martin = new Human()
            {
                Genre = "Male",
                Forename = "Martin",
                Surname = "Hromek",
                Age = 29,
                Proffesion = "Developer",
                Partner = new Human() { Genre = "Female", Forename = "Eva", Surname = "Brezovska", Age = 26, Proffesion = "Social Worker" }
            };

            Console.WriteLine(Martin.ToString()+Environment.NewLine);
            Serialization1(Martin);
            //Serialization2(Martin);
            
        }