Skip to content

Commit

Permalink
Merge pull request #264 from Cratis:fix/import-uniqueness
Browse files Browse the repository at this point in the history
Making sure all import statements are unique per type
  • Loading branch information
einari authored Sep 30, 2024
2 parents b5b104d + cdefd77 commit ba697ca
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"cwd": "${workspaceFolder}/Source/DotNET/Tools/ProxyGenerator",
"program": "${workspaceFolder}/Source/DotNET/Tools/ProxyGenerator/bin/Debug/net8.0/Cratis.Applications.ProxyGenerator.dll",
"args": [
// "/Volumes/Code/KDI/Ocean/Source/Accounts/Api/bin/Debug/net8.0/Api.dll",
// "/Volumes/Code/KDI/Ocean/Source/Accounts/Web/Api",
"/Volumes/Code/KDI/Ocean/Source/Exercises/Main/bin/Debug/net8.0/Kongsberg.KSim.Ocean.Exercises.Main.dll",
"/Volumes/Code/KDI/Ocean/Source/Exercises/Web/Api",
// "/Volumes/Code/Cratis/Chronicle/Source/Api/bin/Debug/net8.0/Cratis.Chronicle.Api.dll",
// "/Volumes/Code/Cratis/Chronicle/Source/Workbench/Api",
"${workspaceFolder}/Samples/eCommerce/Basic/Main/bin/Debug/net8.0/Main.dll",
"${workspaceFolder}/Samples/eCommerce/Basic/Web/API",
// "${workspaceFolder}/Samples/eCommerce/Basic/Main/bin/Debug/net8.0/Main.dll",
// "${workspaceFolder}/Samples/eCommerce/Basic/Web/API",
"1"
],
"stopAtEntry": false,
Expand Down
2 changes: 1 addition & 1 deletion Source/DotNET/Tools/ProxyGenerator/CommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static CommandDescriptor ToCommandDescriptor(this MethodInfo method, stri
property.CollectTypesInvolved(additionalTypesInvolved);
}

imports = imports.Distinct().ToList();
imports = imports.DistinctBy(_ => _.Type).ToList();

var route = method.GetRoute();

Expand Down
5 changes: 4 additions & 1 deletion Source/DotNET/Tools/ProxyGenerator/QueryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public static QueryDescriptor ToQueryDescriptor(this MethodInfo method, string t
var argumentsWithComplexTypes = arguments.Where(_ => !_.OriginalType.IsKnownType());
typesInvolved.AddRange(argumentsWithComplexTypes.Select(_ => _.OriginalType));

var imports = typesInvolved.GetImports(targetPath, method.DeclaringType!.ResolveTargetPath(segmentsToSkip), segmentsToSkip).ToList();
var imports = typesInvolved
.GetImports(targetPath, method.DeclaringType!.ResolveTargetPath(segmentsToSkip), segmentsToSkip)
.DistinctBy(_ => _.Type)
.ToList();

var additionalTypesInvolved = new List<Type>();
foreach (var argument in argumentsWithComplexTypes)
Expand Down
5 changes: 3 additions & 2 deletions Source/DotNET/Tools/ProxyGenerator/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,9 @@ public static TypeDescriptor ToTypeDescriptor(this Type type, string targetPath,

imports.AddRange(typesInvolved.GetImports(targetPath, type!.ResolveTargetPath(segmentsToSkip), segmentsToSkip));
imports = imports
.Distinct()
.Where(_ => propertyDescriptors.Exists(pd => pd.Type == _.Type) && _.OriginalType != type).ToList();
.DistinctBy(_ => _.Type)
.Where(_ => propertyDescriptors.Exists(pd => pd.Type == _.Type) && _.OriginalType != type)
.ToList();

return new TypeDescriptor(
type,
Expand Down

0 comments on commit ba697ca

Please sign in to comment.