Ejemplo n.º 1
0
        private static IEnumerable <MatchDetail> MatchToKeyValuePairs(string allLine, Type matchTo)
        {
            List <JsonMapping> mappings = JsonMapping.MappingFromType(matchTo);
            MatchCollection    matches  = Regex.Matches(allLine, REGEX, RegexOptions.Multiline);

            foreach (Match regexMatch in matches)
            {
                string      key          = regexMatch.Groups[1].Value.Trim();
                JsonMapping foundMapping = mappings.Find(x => x.JsonPropertyName.Equals(key, StringComparison.CurrentCultureIgnoreCase));
                if (foundMapping != null)
                {
                    yield return(foundMapping.ToMatchDetail(key, regexMatch.Groups[2].Value.Trim()));
                }
            }
        }
Ejemplo n.º 2
0
        private static List <MatchDetail> MatchToKeyValuePairsAsList(string allLine, Type matchTo)
        {
            List <JsonMapping> mappings = JsonMapping.MappingFromType(matchTo);
            MatchCollection    matches  = Regex.Matches(allLine, REGEX, RegexOptions.Multiline);
            var finalList = new List <MatchDetail>(matches.Count);

            foreach (Match regexMatch in matches)
            {
                string      key          = regexMatch.Groups[1].Value.Trim();
                JsonMapping foundMapping = mappings.Find(x => x.JsonPropertyName.Equals(key, StringComparison.CurrentCultureIgnoreCase));
                if (foundMapping != null)
                {
                    MatchDetail md = foundMapping.ToMatchDetail(key, regexMatch.Groups[2].Value.Trim());
                    if (md != null)
                    {
                        finalList.Add(md);
                    }
                }
            }
            return(finalList);
        }