public static bool TryParse(string line, out IniFileLine record) { if (string.IsNullOrWhiteSpace(line)) { record = IniFileNoMeaningContentLine.EmptyLine; } else { var match = Regex.Match(line, @"^((\[(?<sectionName>[^\]]*)\])|((?<key>[^=]*)=(?<value>[^\;]*)))(\;(?<commentText>[^\n]*))?$"); if (match.Success) { var sectionNameGroup = match.Groups["sectionName"]; var keyGroup = match.Groups["key"]; var valueGroup = match.Groups["value"]; var commentTextGroup = match.Groups["commentText"]; var commentText = commentTextGroup.Success ? commentTextGroup.Value : null; if (sectionNameGroup.Success) { record = new IniFileSectionDeclarationLine(sectionNameGroup.Value.Trim(), commentText); } else if (keyGroup.Success && valueGroup.Success) { record = new IniFileKeyValueLine(keyGroup.Value.Trim(), valueGroup.Value.Trim(), commentText); } else { record = null; } } else { record = null; } } return(record != null); }
void IIniFileContentLineHandler.HandleKeyValue(IniFileKeyValueLine kvLine) { _currSection.Add(kvLine.Key, kvLine.Value); }