diff --git a/FactoryGenerator/Injection.cs b/FactoryGenerator/Injection.cs index d5cae0c..68d4213 100644 --- a/FactoryGenerator/Injection.cs +++ b/FactoryGenerator/Injection.cs @@ -177,6 +177,15 @@ private Injection(INamedTypeSymbol type, ImmutableArray interf var singleInstance = false; var acquireChildInterfaces = false; + var asSelf = false; + if(namedTypeSymbol.Interfaces.Length == 0) + { + asSelf = true; + } + if (namedTypeSymbol.TypeKind == TypeKind.Interface) + { + asSelf = true; + } BooleanInjection? boolean = null; HashSet attributedInterfaces = new(SymbolEqualityComparer.Default); HashSet preventedInterfaces = new(SymbolEqualityComparer.Default); @@ -207,7 +216,7 @@ private Injection(INamedTypeSymbol type, ImmutableArray interf break; case "SelfAttribute": - attributedInterfaces.Add(namedTypeSymbol); + asSelf = true; break; case "BooleanAttribute": boolean = HandleBoolean(attributeData); @@ -218,9 +227,9 @@ private Injection(INamedTypeSymbol type, ImmutableArray interf } var interfaces = acquireChildInterfaces ? namedTypeSymbol.AllInterfaces : namedTypeSymbol.Interfaces; - if (namedTypeSymbol.TypeKind == TypeKind.Interface) + if (asSelf) { - interfaces = ImmutableArray.Create(namedTypeSymbol); + interfaces = interfaces.Add(namedTypeSymbol); } interfaces = interfaces.AddRange(attributedInterfaces);