static CircularDependency TryGetCircularDependency(ExecutableRuleAndDependencies ruleAndDependencies, CandidateRulesCollection remainingCandidates) { // This optimisation probably isn't required but it makes it // incredibly clear that for rules with no dependencies, there's no work to do. if (!ruleAndDependencies.Dependencies.Any()) { return(null); } var firstDependencies = ruleAndDependencies.Dependencies .Select(x => (x, new List <ExecutableRule> { ruleAndDependencies.ExecutableRule, x }));
/// <summary> /// Gets a collection of any circular dependencies which are detected. /// </summary> /// <param name="rulesAndDependencies">A collection of the all of the rules and dependencies</param> /// <returns>A collection of circular dependency models, indicating the circular dependencies detected.</returns> public IEnumerable <CircularDependency> GetCircularDependencies(IEnumerable <ExecutableRuleAndDependencies> rulesAndDependencies) { var candidates = new CandidateRulesCollection(rulesAndDependencies); while (candidates.TryGetNext(out var current)) { var circularDependency = TryGetCircularDependency(current, candidates); if (circularDependency == null) { continue; } candidates.CloseFoundCircularDependency(circularDependency); yield return(circularDependency); } }