C#序列化对象为XMl于反序列化

C#-Code             // Create the serializer
            XmlSerializer serializer = new XmlSerializer(typeof(MySerializableType));

            // Serialize the object to an XML file
            using (StreamWriter streamWriter = File.CreateText("CSXmlSerialization.xml"))
            {
                serializer.Serialize(streamWriter, instance);
            }


            // Deserialize from a XML file to an object instance.

            // Deserialize the object
            MySerializableType deserializedInstance;
            using (StreamReader streamReader = File.OpenText(
                "CSXmlSerialization.xml"))
            {
                deserializedInstance = serializer.Deserialize(streamReader)
                    as MySerializableType;
            }

posted on 2009-09-16 20:03  ToKens  阅读(306)  评论(0编辑  收藏  举报