コード例 #1
0
        public static void Serialize(TestInformation t, string fileName)
        {
            XmlSerializer mySerializer = new XmlSerializer(typeof(TestInformation));
            // To write to a file, create a StreamWriter object.
            StreamWriter myWriter = new StreamWriter(fileName);

            mySerializer.Serialize(myWriter, t);
            myWriter.Close();
        }
コード例 #2
0
        public static TestInformation DeSerialize(string fileName)
        {
            TestInformation ret = null;

            try
            {
                XmlSerializer mySerializer = new XmlSerializer(typeof(TestInformation));
                // To read the file, create a FileStream.
                FileStream myFileStream = new FileStream(fileName, FileMode.Open);
                // Call the Deserialize method and cast to the object type.
                ret = (TestInformation)mySerializer.Deserialize(myFileStream);
                myFileStream.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception at LoadFromString: " + e.ToString());
            }
            return(ret);
        }