public ProfileKey this[string key] { get { var existingKey = Keys .FirstOrDefault(k => string.Compare(k.Name, key, StringComparison.InvariantCultureIgnoreCase) == 0); if (existingKey != null) { return(existingKey); } var newKey = new ProfileKey(this, key); Keys.Add(newKey); return(newKey); } }
private void LoadContent(TextReader content) { var currentSection = new ProfileSection(this, ProfileSection.UnnamedGlobalSectionName); Sections.Add(currentSection); while (true) { var line = content.ReadLine(); if (line == null) { break; } if (string.IsNullOrEmpty(line)) { continue; } if ((CommentLines != null) && line.StartsWith(CommentLines)) { continue; } var isSection = SectionFmt.Match(line); if (isSection.Success) { var name = isSection.Groups[1].Value; currentSection = new ProfileSection(this, name); Sections.Add(currentSection); continue; } var isKey = KeyFmt.Match(line); if (!isKey.Success) { continue; } var thisKey = new ProfileKey(currentSection, isKey.Groups[1].Value); thisKey.LoadValue(isKey.Groups[2].Value); currentSection.Keys.Add(thisKey); } }