示例#1
0
        private static JsonMapping Construct(PropertyInfo pi)
        {
            JsonMapping           mapping = null;
            JsonPropertyAttribute att     = pi.GetCustomAttribute <JsonPropertyAttribute>();

            if (att != null)
            {
                mapping = new JsonMapping(pi, att);
            }
            return(mapping);
        }
示例#2
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()));
                }
            }
        }
示例#3
0
        public static List <JsonMapping> MappingFromType(Type fromThisType)
        {
            PropertyInfo[] propInfos = fromThisType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var            list      = new List <JsonMapping>(propInfos.Length);

            foreach (PropertyInfo pi in propInfos)
            {
                JsonMapping mapping = Construct(pi);
                if (mapping != null)
                {
                    list.Add(mapping);
                }
            }
            return(list);
        }
示例#4
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);
        }