// ----- Загрузка -------- public static Settings Load(string settingsFilePath) { XmlTextReader reader = null; Settings settings = new Settings(); try { Parameter parameter = null; reader = new XmlTextReader(settingsFilePath); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: parameter = new Parameter(reader.Name); while (reader.MoveToNextAttribute()) { Property property = new Property(reader.Name, reader.Value); parameter.Insert(property); } break; case XmlNodeType.Text: if (parameter != null) parameter.Value = reader.Value; break; case XmlNodeType.EndElement: if (settings != null) { if (parameter != null) { settings.Insert(parameter); parameter = null; } } break; } } settings.SettingsFilePath = settingsFilePath; return settings; } catch (Exception ex) { throw new Exception(ex.Message, ex.InnerException); } finally { if (reader != null) reader.Close(); } }
// ---- Управление параметрами ----- public void Insert(Parameter parameter) { parameters.Add(parameter); }