diff --git a/FactoryGenerator/FactoryGenerator.cs b/FactoryGenerator/FactoryGenerator.cs index 4b818b9..1d53e5d 100644 --- a/FactoryGenerator/FactoryGenerator.cs +++ b/FactoryGenerator/FactoryGenerator.cs @@ -458,11 +458,12 @@ private static void CheckForCycles(ImmutableArray dataInjections) var tree = new Dictionary>(SymbolEqualityComparer.Default); foreach (var injection in dataInjections) { + var node = new List(); foreach (var iface in injection.Interfaces) { if (!tree.ContainsKey(iface)) { - tree[iface] = new List(); + tree[iface] = node; } } @@ -478,10 +479,7 @@ private static void CheckForCycles(ImmutableArray dataInjections) named = (INamedTypeSymbol) named.TypeArguments[0]; } - foreach (var iface in injection.Interfaces) - { - tree[iface].Add(named); - } + node.Add(named); if (tree.TryGetValue(named, out var list)) { @@ -492,18 +490,13 @@ private static void CheckForCycles(ImmutableArray dataInjections) } } - if (parameter.Type is IArrayTypeSymbol array) + if (parameter.Type is not IArrayTypeSymbol {ElementType: INamedTypeSymbol arrType}) continue; { - if (array.ElementType is INamedTypeSymbol arrType) + node.Add(arrType); + if (!tree.TryGetValue(arrType, out var list)) continue; + foreach (var iface in injection.Interfaces) { - tree[injection.Type].Add(arrType); - if (tree.TryGetValue(arrType, out var list)) - { - foreach (var iface in injection.Interfaces) - { - if (list.Contains(iface)) throw new InvalidOperationException($"Cyclic Dependency Detected between {injection.Type} and {iface}"); - } - } + if (list.Contains(iface)) throw new InvalidOperationException($"Cyclic Dependency Detected between {injection.Type} and {iface}"); } } }