示例#1
0
 public static void Save(Config config)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(Config));
     TextWriter textWriter = new StreamWriter(@"config.xml");
     serializer.Serialize(textWriter, config);
     textWriter.Close();
 }
示例#2
0
        public static Config Load()
        {
            Config config;

            if (File.Exists(@"config.xml"))
            {
                XmlSerializer deserializer = new XmlSerializer(typeof(Config));
                TextReader textReader = new StreamReader(@"config.xml");
                config = (Config) deserializer.Deserialize(textReader);
                textReader.Close();
            }
            else
            {
                config = new Config();
                Save(config);
            }

            return config;
        }