Example #1
0
        internal MatchDetail ToMatchDetail(Match regexMatch)
        {
            MatchDetail md = null;

            if (regexMatch.Success)
            {
                string key   = regexMatch.Groups[1].Value.Trim();
                string value = regexMatch.Groups[2].Value.Trim();
                md = new MatchDetail(key, value, this.PropertyInfo);
            }
            return(md);
        }
Example #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);
        }
Example #3
0
        private static IEnumerable <WorkAccount> MatchToWorkAccounts(string allOne, int howMany)
        {
            var list          = new WorkAccountCollection(howMany);
            var matchDets     = MatchToKeyValuePairsAsList(allOne, typeof(WorkAccount));
            var listOfMatches = new List <MatchDetailCollection>(howMany);

            for (int i = 0; i < howMany; i++)
            {
                listOfMatches.Add(new MatchDetailCollection(matchDets.GetRange(i * 8, 8)));
            }
            for (int l = 0; l < listOfMatches.Count; l++)
            {
                MatchDetailCollection li = listOfMatches[l];
                var wa = new WorkAccount();
                for (int m = 0; m < li.Count; m++)
                {
                    MatchDetail md = li[m];
                    md.SetValue(wa);
                }
                list.Add(wa);
            }
            return(list);
        }