internal List <HoconField> TraversePath(HoconPath path) { var result = new List <HoconField>(); var pathLength = 1; var currentObject = this; while (true) { var child = currentObject.GetOrCreateKey(new HoconPath(path.GetRange(0, pathLength))); result.Add(child); pathLength++; if (pathLength > path.Count) { return(result); } child.EnsureFieldIsObject(); currentObject = child.GetObject(); } }
public HoconField GetField(HoconPath path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (path.Count == 0) { throw new ArgumentException("Path is empty.", nameof(path)); } var currentObject = this; var pathIndex = 0; while (true) { var key = path[pathIndex]; if (!currentObject.TryGetValue(key, out var field)) { throw new KeyNotFoundException( $"Could not find field with key `{key}` at path `{new HoconPath(path.GetRange(0, pathIndex + 1)).Value}`"); } if (pathIndex >= path.Count - 1) { return(field); } if (field.Type != HoconType.Object) { throw new HoconException( $"Invalid path, trying to access a key on a non object field. Path: `{new HoconPath(path.GetRange(0, pathIndex + 1)).Value}`"); } currentObject = field.GetObject(); pathIndex++; } }