public void Parse() { if (Filedata == string.Empty) throw new Exception("No data assigned to this reader"); var filelines = Filedata .Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Contains("//") ? x.Remove(x.IndexOf("//")).Trim() : x.Trim()) .Where(x => x.Length != 0) .ToList(); ApplyGroup("Main",false); for (var i = 0; i < filelines.Count; i++) { var line = filelines[i]; var nextLine = (i + 1 == filelines.Count) ? "" : filelines[i + 1]; if (line == "{") continue; if (line.StartsWith("[") && line.EndsWith("]")) { if (line.Length < 3) ApplyGroup("", false); ApplyGroup(line.Substring(1, line.Length - 2), false); continue; } if (line == "}") { LeaveGroup(true); continue; } if (nextLine == "{") { // This is a header. ApplyGroup(line, true); continue; } // Parse this value. var key = ""; var value = ""; if (line.Contains("=")) { var data = line.Split(new[] { '=' }, 2); key = data[0].Trim(); value = data[1].Trim(); } else { value = line; } var obj = new IniValueObject(_group, key, value); foreach (var handler in _handlers) handler(obj); } }
public void Parse() { if (Filedata == string.Empty) { throw new Exception("No data assigned to this reader"); } var filelines = Filedata .Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Contains("//") ? x.Remove(x.IndexOf("//")).Trim() : x.Trim()) .Where(x => x.Length != 0) .ToList(); ApplyGroup("Main", false); for (var i = 0; i < filelines.Count; i++) { var line = filelines[i]; var nextLine = (i + 1 == filelines.Count) ? "" : filelines[i + 1]; if (line == "{") { continue; } if (line.StartsWith("[") && line.EndsWith("]")) { if (line.Length < 3) { ApplyGroup("", false); } ApplyGroup(line.Substring(1, line.Length - 2), false); continue; } if (line == "}") { LeaveGroup(true); continue; } if (nextLine == "{") { // This is a header. ApplyGroup(line, true); continue; } // Parse this value. var key = ""; var value = ""; if (line.Contains("=")) { var data = line.Split(new[] { '=' }, 2); key = data[0].Trim(); value = data[1].Trim(); } else { value = line; } var obj = new IniValueObject(_group, key, value); foreach (var handler in _handlers) { handler(obj); } } }