public static bool LoadPropertiesFromStream(string fileName) { if (!File.Exists(fileName)) { return(false); } try { using (LockPropertyFile()) { using (XmlTextReader reader = new XmlTextReader(fileName)) { while (reader.Read()) { if (reader.IsStartElement()) { if (reader.LocalName == propertyXmlRootNodeName) { properties.ReadProperties(reader, propertyXmlRootNodeName); return(true); } } } } } } catch (XmlException ex) { MessageService.ShowError("Error loading properties: " + ex.Message + "\nSettings have been restored to default values."); } return(false); }
internal void ReadProperties(XmlReader reader, string endElement) { if (reader.IsEmptyElement) { return; } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.EndElement: if (reader.LocalName == endElement) { return; } break; case XmlNodeType.Element: string propertyName = reader.LocalName; if (propertyName == "Properties") { propertyName = reader.GetAttribute(0); Properties p = new Properties(); p.ReadProperties(reader, "Properties"); properties[propertyName] = p; } else if (propertyName == "Array") { propertyName = reader.GetAttribute(0); properties[propertyName] = ReadArray(reader); } else if (propertyName == "SerializedValue") { propertyName = reader.GetAttribute(0); properties[propertyName] = new SerializedValue(reader.ReadInnerXml()); } else { properties[propertyName] = reader.HasAttributes ? reader.GetAttribute(0) : null; } break; } } }
// public void BinarySerialize(BinaryWriter writer) // { // writer.Write((byte)properties.Count); // foreach (KeyValuePair<string, object> entry in properties) { // writer.Write(AddInTree.GetNameOffset(entry.Key)); // writer.Write(AddInTree.GetNameOffset(entry.Value.ToString())); // } // } public static Properties Load(string fileName) { if (!File.Exists(fileName)) { return null; } using (XmlTextReader reader = new XmlTextReader(fileName)) { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.LocalName) { case "Properties": Properties properties = new Properties(); properties.ReadProperties(reader, "Properties"); return properties; } } } } return null; }