public bool parse(string file) { if (System.IO.File.Exists(file)) { string[] lines = System.IO.File.ReadAllLines(file); string newGroup = ""; string currentGroup = ""; for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("[")) { newGroup = lines[i].Substring(1, lines[i].Length - 2); } if (newGroup != "") { groups.Add(new IniReaderGroup(newGroup)); currentGroup = newGroup; newGroup = ""; } else { IniReaderGroup g = groups.Where(group => group.Group == currentGroup).FirstOrDefault(); if (g != null) { int equalSignPos = lines[i].IndexOf("="); if (equalSignPos > -1) { string key = lines[i].Substring(0, equalSignPos).Trim(); string value = lines[i].Substring(equalSignPos + 1, lines[i].Length - equalSignPos - 1).Trim(); // Trim " at start if (value.IndexOf((char)34) == 0) { value = value.Substring(1, value.Length - 1); } // Trim " at end if (value.IndexOf((char)34) == value.Length - 1) { value = value.Substring(0, value.Length - 1); } g.Add(key, value); } } } } return(true); } return(false); }
public string get(string group, string key) { IniReaderGroup g = groups.Where(gr => gr.Group == group).FirstOrDefault(); if (g != null) { return(g.Get(key)); } return(""); }