/// <summary> /// Saves the specified property information to the xml file /// </summary> /// <param name="property">The property itself</param> public override void WriteToFile(SettingsPropertyInfo property, bool fileExists = true) { // Store Xml file var doc = new XmlDocument(); // If file doesn't exists yet if (!fileExists) { // Add crucial informations at the top var docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); // Create config root node var rootNode = doc.CreateElement("Config"); doc.AppendChild(rootNode); } else { // Load current file state to the doc variable var xmlReader = new XmlReader(SaveableObjects.Config); doc = xmlReader.LoadXmlFile("config"); } // Get every property node in the file var propertyNodeList = doc.GetElementsByTagName("Property"); foreach (XmlNode propertyXmlNode in propertyNodeList) { // Find if property with that name already exists if (propertyXmlNode.FirstChild.InnerText == property.Name) { // If yes, delete it to make a room for new value doc.DocumentElement.RemoveChild(propertyXmlNode); break; } } // Create new property node var propertyNode = doc.CreateElement("Property"); // Append it to config node tree doc.DocumentElement.AppendChild(propertyNode); // Put a property infos inside of property node AppendNodeXml("Name", property.Name, propertyNode, doc); AppendNodeXml("Type", property.Type.ToString(), propertyNode, doc); AppendNodeXml("Value", property.Value.ToString(), propertyNode, doc); // Finally save the file if (!WriteXmlDocumentFile("config", doc)) { // If something went wrong, throw an error throw new Exception("Cannot save config file!"); } }
/// <summary> /// Writes object's property info to file /// </summary> public virtual void WriteToFile(SettingsPropertyInfo property, bool fileExists = true) { }