using System.Collections.Generic; using System.Linq; namespace mpvnet { public class StringPair { public string Name { get; set; } public string Value { get; set; } } public class ConfParser { public static List Parse(string content) { string[] lines = content.Split("\r\n".ToCharArray()); var sections = new List(); ConfSection currentGroup = null; foreach (string i in lines) { string line = i.Trim(); if (string.IsNullOrEmpty(line)) continue; if (line.StartsWith("[") && line.EndsWith("]")) { currentGroup = new ConfSection() { Name = line.TrimStart('[').TrimEnd(']') }; sections.Add(currentGroup); } else if (line.Contains("=")) { string name = line.Substring(0, line.IndexOf("=")).Trim(); string value = line.Substring(line.IndexOf("=") + 1).Trim(); currentGroup.Items.Add(new StringPair() { Name = name, Value = value }); } } return sections; } } public class ConfSection { public string Name { get; set; } public List Items { get; set; } = new List(); public bool HasName(string name) { foreach (var i in Items) if (i.Name == name) return true; return false; } public string GetValue(string name) { foreach (var i in Items) if (i.Name == name) return i.Value; return null; } public List GetValues(string name) => Items.Where(i => i.Name == name).ToList(); } }