Compare commits

..

No commits in common. 'f3d17117fc372a61fc8e16295d2dc911f6ca8b79' and 'a584095df22edf6931bce5eb9f3345ae63ee4bad' have entirely different histories.

  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,9 +179,19 @@ 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));
namespaces.AddRange(method.Parameters.SelectMany(p => GetNamespacesOfType(p.Type))); if (method.ReturnType.Name != "Task")
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))
@ -260,25 +270,9 @@ 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>()
.SelectMany(GetNamespacesOfType) .Select(GetNamespaceOfType)
.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>beta2</VersionSuffix> <VersionSuffix>beta</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>beta2</VersionSuffix> <VersionSuffix>beta</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>beta2</VersionSuffix> <VersionSuffix>beta</VersionSuffix>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

Loading…
Cancel
Save