Esempio n. 1
0
        static void callDeSerialization()
        {
            XmlSerializer xs = new XmlSerializer(typeof(Student1));
            TextReader    tr = new StreamReader("F:\\Bizruntime\\Workspace\\Serialization\\hello1.xml");
            Student1      s  = (Student1)xs.Deserialize(tr);

            Console.WriteLine("Student Name : " + s.sName);
            Console.WriteLine("Student Age : " + s.sAge);
            Console.WriteLine("Student Address : " + s.sAdd);
        }
Esempio n. 2
0
        public static void Serialize(string filename)
        {
            Student1 student = new Student1();

            student.Name    = "TestName";
            student.Salary  = 700;
            student.Address = "TestAddress";
            using (FileStream ioStream = new FileStream(filename, FileMode.Create))
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(Student));
                serializer.WriteObject(ioStream, student);
            }
        }
Esempio n. 3
0
        static void callSerialization()
        {
            XmlSerializer xs = new XmlSerializer(typeof(Student1));
            Student1      s1 = new Student1()
            {
                sName = "ansh", sAge = 18, sAdd = "btm"
            };
            TextWriter tw = new StreamWriter("F:\\Bizruntime\\Workspace\\Serialization\\hello2.xml");

            xs.Serialize(tw, s1);
            Console.WriteLine("serialize successfully");
            tw.Close();
        }