/// <summary> /// Skips to the field with the specified name. Does not traverse descendants. /// </summary> /// <param name="key">The name of the field.</param> /// <returns>True if the reader wound up on said, field, otherwise, false</returns> /// <remarks>This will return false unless called from an object start or from a field.</remarks> public bool SkipToField(string key, bool searchDescendants = false) { string okey = key; key = JsonObject.DecorateString(okey); string rv; if (searchDescendants) { while (Read()) { if (1 == _state) // key { rv = _pc.GetCapture(); if (key == rv) { return(true); } } } return(false); } switch (_state) { case -1: if (Read()) { return(SkipToField(okey)); } return(false); case 4: while (Read() && 1 == _state) // first read will move to the child field of the root { rv = _pc.GetCapture(); if (key != rv) { SkipSubtree(); // if this field isn't the target so just skip over the rest of it } else { break; } } return(1 == _state); case 1: // we're already on a field rv = _pc.GetCapture(); if (key == rv || okey == rv) { return(true); } else if (!SkipSubtree()) { return(false); } while (Read() && 1 == _state) // first read will move to the child field of the root { rv = _pc.GetCapture(); if (key != rv && okey != rv) { SkipSubtree(); // if this field isn't the target just skip over the rest of it } else { break; } } return(1 == _state); default: return(false); } }