Пример #1
0
        /// <summary>
        /// Evaluates the pointer against a JSON instance.
        /// </summary>
        /// <param name="root">The JSON instance.</param>
        /// <returns>The element the pointer references, if any.</returns>
        public PointerEvaluationResults Evaluate(JsonValue root)
        {
            var upTo    = new JsonPointer();
            var current = root;

            foreach (var segment in this)
            {
                upTo.Add(segment);
                current = _EvaluateSegment(current, segment);
                if (current == null)
                {
                    return(new PointerEvaluationResults($"No value found at '{upTo}'"));
                }
            }

            return(new PointerEvaluationResults(current));
        }
Пример #2
0
 private JsonPointer(JsonPointer source, int capacity, bool usesHash)
     : base(capacity)
 {
     AddRange(source.FirstOrDefault() == "#" ? source.SkipWhile(s => s == "#") : source);
     _usesHash = usesHash;
 }
Пример #3
0
 /// <summary>
 /// Determines whether the pointer is a child of another pointer (starts with the same segments).
 /// </summary>
 /// <param name="pointer">Another pointer.</param>
 /// <returns>`true` if this pointer starts with all of the segments of <paramref name="pointer"/>; `false` otherwise.</returns>
 public bool IsChildOf(JsonPointer pointer)
 {
     return(this.Take(pointer.Count).SequenceEqual(pointer));
 }