private ConfigSection FindOrCreateConfigSection(string name) { ConfigSection configSectionToFind = new ConfigSection(name); foreach (ConfigSection configSection in sections) { if (configSection.SectionName == configSectionToFind.SectionName && configSection.SubSection == configSectionToFind.SubSection) return configSection; } sections.Add(configSectionToFind); return configSectionToFind; }
private void Load() { if (!File.Exists(fileName)) return; string[] fileLines = File.ReadAllLines(fileName, Settings.Encoding); ConfigSection configSection = null; foreach (string line in fileLines) { Match m = regParseIsSection.Match(line); if (m.Success) //this line is a section { string name = m.Groups["SectionName"].Value; configSection = new ConfigSection(name); this.sections.Add(configSection); } else { m = regParseIsKey.Match(line); if (m.Success) //this line is a key { string key = m.Groups["Key"].Value; string value = unescapeString(m.Groups["Value"].Value); if (configSection == null) throw new Exception("Key " + key + " in configfile " + fileName + " is not in a section."); configSection.SetValue(key, value); } } } }
private ConfigSection FindConfigSection(string name) { ConfigSection configSectionToFind = new ConfigSection(name); foreach (ConfigSection configSection in sections) { if (configSection.SectionName == configSectionToFind.SectionName && configSection.SubSection == configSectionToFind.SubSection) return configSection; } return null; }