Compare commits

...

2 Commits

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

@ -179,19 +179,9 @@ public class FactoryGenerator : IIncrementalGenerator
continue; continue;
if (!method.ReturnsVoid) if (!method.ReturnsVoid)
{ namespaces.AddRange(GetNamespacesOfType(method.ReturnType));
if (method.ReturnType is INamedTypeSymbol { IsGenericType: true } namedTypeSymbol)
{
namespaces.AddRange(namedTypeSymbol.TypeArguments.Select(GetNamespaceOfType));
if (method.ReturnType.Name != "Task") namespaces.AddRange(method.Parameters.SelectMany(p => GetNamespacesOfType(p.Type)));
namespaces.Add(GetNamespaceOfType(method.ReturnType));
}
else
namespaces.Add(GetNamespaceOfType(method.ReturnType));
}
namespaces.AddRange(method.Parameters.Select(p => GetNamespaceOfType(p.Type)));
} }
foreach (string @namespace in namespaces.Distinct().OfType<string>().OrderBy(n => n)) 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 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) => private IEnumerable<string> GetNamespacesOfTypes(ImmutableArray<ITypeSymbol?> types) =>
types.OfType<ITypeSymbol>() types.OfType<ITypeSymbol>()
.Select(GetNamespaceOfType) .SelectMany(GetNamespacesOfType)
.OfType<string>() .OfType<string>()
.Distinct(); .Distinct();

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

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

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

Loading…
Cancel
Save