Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/project/aggregated/Combined/Combined.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<ProjectReference Include="../A/A.csproj" />
<ProjectReference Include="../B/B.csproj" />
<ProjectReference Include="../C/C.csproj" />
<ProjectReference Include="../D/D.csproj" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions examples/project/aggregated/D/D.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Project Sdk="Microsoft.NET.Sdk" />
3 changes: 3 additions & 0 deletions examples/project/aggregated/D/DTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace D;

public class DTO;
19 changes: 13 additions & 6 deletions src/LeanCode.ContractsGenerator.Tests/ExampleBased/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public void Aggregated_project_compiles()
.WithTopic("C.Topic")
.WithNotification(
NotificationTypeRefExtensions.WithTag(TypeRefExtensions.Internal("C.Notification"), "C.Notification")
);
)
.WithDto("D.DTO");
}

[Fact]
Expand All @@ -36,14 +37,16 @@ public void Multiple_separate_projects_compile()
ProjectsCompile(
"project/aggregated/A/A.csproj",
"project/aggregated/B/B.csproj",
"project/aggregated/C/C.csproj"
"project/aggregated/C/C.csproj",
"project/aggregated/D/D.csproj"
)
.WithCommand("A.Command")
.WithQuery("B.Query")
.WithTopic("C.Topic")
.WithNotification(
NotificationTypeRefExtensions.WithTag(TypeRefExtensions.Internal("C.Notification"), "C.Notification")
);
)
.WithDto("D.DTO");
}

[Fact]
Expand All @@ -62,27 +65,31 @@ public void Multiple_separate_projects_compile_even_if_some_references_overlap()
"project/aggregated/A/A.csproj",
"project/aggregated/B/B.csproj",
"project/aggregated/C/C.csproj",
"project/aggregated/D/D.csproj",
"project/aggregated/Combined/Combined.csproj"
)
.WithCommand("A.Command")
.WithQuery("B.Query")
.WithTopic("C.Topic")
.WithNotification(
NotificationTypeRefExtensions.WithTag(TypeRefExtensions.Internal("C.Notification"), "C.Notification")
);
)
.WithDto("D.DTO");

ProjectsCompile(
"project/aggregated/Combined/Combined.csproj",
"project/aggregated/A/A.csproj",
"project/aggregated/B/B.csproj",
"project/aggregated/C/C.csproj"
"project/aggregated/C/C.csproj",
"project/aggregated/D/D.csproj"
)
.WithCommand("A.Command")
.WithQuery("B.Query")
.WithTopic("C.Topic")
.WithNotification(
NotificationTypeRefExtensions.WithTag(TypeRefExtensions.Internal("C.Notification"), "C.Notification")
);
)
.WithDto("D.DTO");
}

[Fact]
Expand Down
31 changes: 7 additions & 24 deletions src/LeanCode.ContractsGenerator/Compilation/ContractTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,10 @@ public ContractTypes(IReadOnlyCollection<CSharpCompilation> compilations)
private static HashSet<INamedTypeSymbol> GetTypeSymbols<T>(IReadOnlyCollection<CSharpCompilation> compilations)
{
var name = typeof(T).FullName!;
var result = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);

foreach (var c in compilations)
{
var type =
c.GetTypeByMetadataName(name)
?? throw new CompilationFailedException(
$"Cannot locate type {name} in compilation unit `{c.AssemblyName ?? "UNKNOWN"}`."
);
result.Add(type);
}

return result;
return compilations
.SelectMany(c => c.GetTypesByMetadataName(name))
.ToHashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);
}

private static HashSet<INamedTypeSymbol> GetUnboundTypeSymbols(
Expand All @@ -76,19 +67,11 @@ Type type
)
{
var name = type.FullName!;
var result = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);

foreach (var c in compilations)
{
var t =
(c.GetTypeByMetadataName(name)?.ConstructUnboundGenericType())
?? throw new CompilationFailedException(
$"Cannot locate generic type {name} in compilation unit `{c.AssemblyName ?? "UNKNOWN"}`."
);
result.Add(t);
}

return result;
return compilations
.SelectMany(c => c.GetTypesByMetadataName(name))
.Select(nts => nts.ConstructUnboundGenericType())
.ToHashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);
}

public bool IsQuery(ITypeSymbol symbol) =>
Expand Down
Loading