Skip to content

Commit

Permalink
hashet comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Sep 20, 2023
1 parent ae9b568 commit f670a69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
13 changes: 7 additions & 6 deletions src/Kiota.Builder/Refiners/TypeScriptRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static void CorrectCodeFileUsing(CodeElement currentElement)
// correct the using values
// eliminate the using refering the elements in the same file

HashSet<string> elementSet = codeFile.GetChildElements(true).Select(x => x.Name.ToLowerInvariant()).ToHashSet();
HashSet<string> elementSet = codeFile.GetChildElements(true).Select(x => x.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
foreach (var element in codeFile.GetChildElements(true))
{
var startBlockUsings = element switch
Expand All @@ -259,23 +259,24 @@ private static void CorrectCodeFileUsing(CodeElement currentElement)
var foundUsings = startBlockUsings
.Where(static x => x.Declaration != null && x.Declaration.TypeDefinition != null)
.Where(y => y.Declaration!.TypeDefinition!.GetImmediateParentOfType<CodeNamespace>() == codeNamespace)
.Where(y => elementSet.Contains(y.Declaration!.TypeDefinition!.Name.ToLowerInvariant()));
.Where(y => elementSet.Contains(y.Declaration!.TypeDefinition!.Name));

foreach (var x in foundUsings)
{
var declarationName = x.Declaration!.Name;
switch (element)
{
case CodeFunction ci:
ci.RemoveUsingsByDeclarationName(x.Declaration?.Name!);
ci.RemoveUsingsByDeclarationName(declarationName);
break;
case CodeInterface ci:
ci.RemoveUsingsByDeclarationName(x.Declaration?.Name!);
ci.RemoveUsingsByDeclarationName(declarationName);
break;
case CodeEnum ci:
ci.RemoveUsingsByDeclarationName(x.Declaration?.Name!);
ci.RemoveUsingsByDeclarationName(declarationName);
break;
case CodeClass ci:
ci.RemoveUsingsByDeclarationName(x.Declaration?.Name!);
ci.RemoveUsingsByDeclarationName(declarationName);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ public override void WriteCodeElement(CodeFileDeclaration codeElement, LanguageW
return startBlockUsings;
}
);
try
{
_codeUsingWriter.WriteCodeElement(usings, ns, writer);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
_codeUsingWriter.WriteCodeElement(usings, ns, writer);
}
}

Expand Down

0 comments on commit f670a69

Please sign in to comment.