private string GetParentSection(string sectionName, out Section section) { var idx = sectionName.LastIndexOf('.'); var newSectionName = idx == -1 ? null : sectionName.Substring(0, idx); return(options.TryGetValue(sectionName, out section) || newSectionName == null ? newSectionName : GetParentSection(newSectionName, out section)); }
private static OptionStore Parse(IEnumerable <string> lines) { Section currentSection = new Section(); OptionStore options = new OptionStore(StringComparer.OrdinalIgnoreCase) { { "DEFAULT", currentSection } }; foreach (var rawline in lines) { string line = rawline.Split(new [] { ';', '#' }, 2)[0].Trim(); if (line.StartsWith("[") && line.EndsWith("]")) { var sectionName = line.Substring(1, line.Length - 2); if (!options.TryGetValue(sectionName, out currentSection)) { currentSection = new Section(); options.Add(sectionName, currentSection); } } else { var result = line.Split(new [] { '=' }, 2); var key = result[0].Trim(); var value = result.Length > 1 ? result[1] : "1"; currentSection.Add(key, value); } } return(options); }