예제 #1
0
        private JToken FindParentNodeBySiblingValue(SiblingValueArguments args)
        {
            var collectionMatch = GetJToken(
                _Json, GetJsonQueryForNodes(args.PathArguments));

            if (collectionMatch == null)
            {
                return(null);
            }

            var matches = collectionMatch.Children().ToList();

            if (matches == null || matches.Count == 0)
            {
                return(null);
            }
            else
            {
                foreach (var item in matches)
                {
                    if (item.HasValues == true)
                    {
                        if (item[args.SiblingSearchKey] != null &&
                            item[args.SiblingSearchKey].Value <string>() == args.SiblingSearchValue)
                        {
                            return(item);
                        }
                    }
                }

                return(null);
            }
        }
예제 #2
0
        public void SetSiblingValue(SiblingValueArguments args)
        {
            var parentNode = FindParentNodeBySiblingValue(args);

            if (parentNode == null)
            {
                return;
            }
            else
            {
                parentNode[args.DesiredNodeKey] = args.DesiredNodeValue;
            }
        }
예제 #3
0
        public string GetSiblingValue(SiblingValueArguments args)
        {
            var parentNode = FindParentNodeBySiblingValue(args);

            if (parentNode == null)
            {
                return(null);
            }
            else
            {
                var match = parentNode[args.DesiredNodeKey];

                if (match == null)
                {
                    return(null);
                }
                else
                {
                    return(match.Value <string>());
                }
            }
        }