public string Serialize(INIModel model) { return(Serialize(new List <INIModel>() { model })); }
public List <INIModel> Deserialize(string data) { MatchCollection matches = Regex.Matches(data, pattern, RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline); if (matches == null || matches.Count == 0) { return(null); } List <INIModel> result = new List <INIModel>(); foreach (Match match in matches) { var maxContent = match.Groups["KVPs"].Captures.Count; var keys = match.Groups["Key"].Captures.Cast <Capture>().Select(c => c.Value.Trim()).ToArray(); var values = match.Groups["Value"].Captures.Cast <Capture>().Select(c => c.Value.Trim()).ToArray(); var model = new INIModel() { Section = match.Groups["Section"].Value }; for (var i = 0; i < maxContent; i++) { model.Content.Add(keys[i], values[i]); } result.Add(model); } return(result); }