Compare commits

...

2 Commits

  1. 34
      LightweightIocContainer.FactoryGenerator/FactoryGenerator.cs
  2. 2
      LightweightIocContainer.FactoryGenerator/LightweightIocContainer.FactoryGenerator.csproj
  3. 2
      LightweightIocContainer.Validation/LightweightIocContainer.Validation.csproj
  4. 2
      LightweightIocContainer/LightweightIocContainer.csproj

@ -178,20 +178,10 @@ public class FactoryGenerator : IIncrementalGenerator
if (member is not IMethodSymbol method)
continue;
if (!method.ReturnsVoid)
{
if (method.ReturnType is INamedTypeSymbol { IsGenericType: true } namedTypeSymbol)
{
namespaces.AddRange(namedTypeSymbol.TypeArguments.Select(GetNamespaceOfType));
if (method.ReturnType.Name != "Task")
namespaces.Add(GetNamespaceOfType(method.ReturnType));
}
else
namespaces.Add(GetNamespaceOfType(method.ReturnType));
}
if (!method.ReturnsVoid)
namespaces.AddRange(GetNamespacesOfType(method.ReturnType));
namespaces.AddRange(method.Parameters.Select(p => GetNamespaceOfType(p.Type)));
namespaces.AddRange(method.Parameters.SelectMany(p => GetNamespacesOfType(p.Type)));
}
foreach (string @namespace in namespaces.Distinct().OfType<string>().OrderBy(n => n))
@ -270,9 +260,25 @@ public class FactoryGenerator : IIncrementalGenerator
}
private string? GetNamespaceOfType(ITypeSymbol s) => s.ContainingNamespace.IsGlobalNamespace ? null : s.ContainingNamespace.ToString();
private List<string?> GetNamespacesOfType(ITypeSymbol typeSymbol)
{
List<string?> namespaces = [];
if (typeSymbol is INamedTypeSymbol { IsGenericType: true } namedTypeSymbol)
{
namespaces.AddRange(namedTypeSymbol.TypeArguments.SelectMany(GetNamespacesOfType));
if (typeSymbol.Name != "Task")
namespaces.Add(GetNamespaceOfType(typeSymbol));
}
else
namespaces.Add(GetNamespaceOfType(typeSymbol));
return namespaces;
}
private IEnumerable<string> GetNamespacesOfTypes(ImmutableArray<ITypeSymbol?> types) =>
types.OfType<ITypeSymbol>()
.Select(GetNamespaceOfType)
.SelectMany(GetNamespacesOfType)
.OfType<string>()
.Distinct();

@ -12,7 +12,7 @@
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
<VersionPrefix>5.0.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
<VersionSuffix>beta2</VersionSuffix>
</PropertyGroup>
<PropertyGroup>

@ -11,7 +11,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<DocumentationFile>LightweightIocContainer.Validation.xml</DocumentationFile>
<VersionPrefix>5.0.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
<VersionSuffix>beta2</VersionSuffix>
</PropertyGroup>
<PropertyGroup>

@ -11,7 +11,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<DocumentationFile>LightweightIocContainer.xml</DocumentationFile>
<VersionPrefix>5.0.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
<VersionSuffix>beta2</VersionSuffix>
</PropertyGroup>
<PropertyGroup>

Loading…
Cancel
Save