예제 #1
0
        // Serialize to XML File.
        private void SaveToFile(object sender, EventArgs e)
        {
            XmlSerializer xsSubmit = new XmlSerializer(typeof(Serial_Items));
            Serial_Items  subReq   = new Serial_Items(this.CPUs, this.Monitors);

            using (var sww = new StringWriter()) {
                using (XmlWriter writer = XmlWriter.Create("data.xml")) {
                    xsSubmit.Serialize(writer, subReq);
                }
            }
        }
예제 #2
0
        // Deserialize from XML File.
        private void ReadFromFile(object sender, EventArgs e)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Serial_Items));

            try {
                using (var reader = XmlReader.Create("data.xml")) {
                    Serial_Items items = (Serial_Items)serializer.Deserialize(reader);
                    this.CPUs     = items.CPUs;
                    this.Monitors = items.Monitors;
                }
            } catch (FileNotFoundException) { }
        }