using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; using System.IO; using System.Xml; using System.Collections.Specialized; namespace JamSoft.CALDemo.Modules.SettingsManager { internal class SettingsManager { public readonly Uri SettingsFile; private PropertiesCollection _settings = new PropertiesCollection(); internal SettingsManager(string file) { SettingsFile = new Uri(file, UriKind.RelativeOrAbsolute); ReadSettingsFile(); } public void SetSettingValue(string key, object value) { _settings.SetSetting(key, value); } public T GetSettingValue<T>(string key) { return (T)_settings.GetSettingValue(key); } private void ReadSettingsFile() { bool e = File.Exists(SettingsFile.OriginalString); StreamReader reader = new StreamReader(SettingsFile.OriginalString); XmlSerializer _settingsSerializer = new XmlSerializer(typeof(PropertiesCollection)); _settings = (PropertiesCollection)_settingsSerializer.Deserialize(reader); } public void SaveSettingsFile() { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlSerializer _settingsSerializer = new XmlSerializer(typeof(PropertiesCollection)); StreamWriter writer = new StreamWriter(SettingsFile.OriginalString); _settingsSerializer.Serialize(writer, _settings); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)