public void Load(Stream s) { IniSection currentSection = null; foreach (var line in s.ReadAllLines()) { if (line.Length == 0) { continue; } switch (line[0]) { case ';': break; case '[': currentSection = ProcessSection(line); break; default: ProcessEntry(line, currentSection); break; } } }
static bool ProcessEntry(string line, IniSection currentSection) { var comment = line.IndexOf(';'); if (comment >= 0) { line = line.Substring(0, comment); } line = line.Trim(); if (line.Length == 0) { return(false); } var key = line; var value = ""; var eq = line.IndexOf('='); if (eq >= 0) { key = line.Substring(0, eq).Trim(); value = line.Substring(eq + 1, line.Length - eq - 1).Trim(); } if (currentSection == null) { throw new InvalidOperationException("No current INI section"); } if (!currentSection.Contains(key)) { currentSection.Add(key, value); } return(true); }
public void Load(Stream s) { var reader = new StreamReader(s); IniSection currentSection = null; while (!reader.EndOfStream) { var line = reader.ReadLine(); if (line.Length == 0) { continue; } switch (line[0]) { case ';': break; case '[': currentSection = ProcessSection(line); break; default: ProcessEntry(line, currentSection); break; } } }