コード例 #1
0
        /// <summary>
        /// Reloads the configuration file (path). If file is not present, it will generate a new one.
        /// </summary>
        /// <returns>A RootConfig object.</returns>
        public DefaultConfig Reload()
        {
            var defaultConfig = new DefaultConfig();

            if (!File.Exists(_path))
            {
                File.WriteAllText(_path, defaultConfig.SerializeToXml());
            }

            using (var sr = new StreamReader(_path))
            {
                defaultConfig =
                    (DefaultConfig)
                    new XmlSerializer(typeof(DefaultConfig)).Deserialize(sr);
            }

            return(defaultConfig);
        }
コード例 #2
0
        /// <summary>
        /// Reloads the configuration file (path). If file is not present, it will generate a new one.
        /// </summary>
        /// <returns>A RootConfig object.</returns>
        public DefaultConfig Reload(DefaultConfig config)
        {
            DefaultConfig defaultConfig = new DefaultConfig(config.Path);

            if (!File.Exists(config.Path))
            {
                File.WriteAllText(config.Path, defaultConfig.SerializeToXml());
            }

            using (var sr = new StreamReader(config.Path))
            {
                defaultConfig =
                    (DefaultConfig)
                        new XmlSerializer(typeof (DefaultConfig)).Deserialize(sr);
            }

            return defaultConfig;
        }
コード例 #3
0
 /// <summary>
 /// Writes the changes made to the config.
 /// </summary>
 /// <param name="towrite"></param>
 public void WriteChanges(DefaultConfig towrite)
 {
     File.WriteAllText(_path, towrite.SerializeToXml());
 }
コード例 #4
0
 /// <summary>
 /// Writes the changes made to the config.
 /// </summary>
 /// <param name="towrite"></param>
 public void WriteChanges(DefaultConfig towrite)
 {
     File.WriteAllText(towrite.Path, towrite.SerializeToXml());
 }