private static void EnsureHasNoCycles(string node, TraversalState state) { state.Visit(node); var nextNodes = state.GetNext(node); if (!nextNodes.Any()) { state.Yield(node); return; } foreach (var adjacentNode in nextNodes) { if (state.IsVisited(adjacentNode) && !state.IsYielded(adjacentNode)) { var msg = $"Cyclic config dependency detected, visited undeleted node twice: '{adjacentNode}'"; throw new BadYamlException("configurations", msg); } EnsureHasNoCycles(adjacentNode, state); } state.Yield(node); }