diff --git a/InterfaceStubGenerator.Shared/InterfaceStubGenerator.cs b/InterfaceStubGenerator.Shared/InterfaceStubGenerator.cs index 041775363..d33ffc17d 100644 --- a/InterfaceStubGenerator.Shared/InterfaceStubGenerator.cs +++ b/InterfaceStubGenerator.Shared/InterfaceStubGenerator.cs @@ -183,9 +183,9 @@ public void Initialize(GeneratorInitializationContext context) class SyntaxReceiver : ISyntaxReceiver { - public List CandidateMethods { get; } = new(); + public List CandidateMethods { get; } = []; - public List CandidateInterfaces { get; } = new(); + public List CandidateInterfaces { get; } = []; public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { diff --git a/InterfaceStubGenerator.Shared/Parser.cs b/InterfaceStubGenerator.Shared/Parser.cs index ec43f5e4a..6665c5a1b 100644 --- a/InterfaceStubGenerator.Shared/Parser.cs +++ b/InterfaceStubGenerator.Shared/Parser.cs @@ -16,6 +16,7 @@ internal static class Parser /// The refit internal namespace. /// The candidate methods. /// The candidate interfaces. + /// The cancellation token. /// public static ( List diagnostics, @@ -28,6 +29,9 @@ ContextGenerationModel contextGenerationSpec CancellationToken cancellationToken ) { + if (compilation == null) + throw new ArgumentNullException(nameof(compilation)); + refitInternalNamespace = $"{refitInternalNamespace ?? string.Empty}RefitInternalGenerated"; // we're going to create a new compilation that contains the attribute. @@ -67,7 +71,7 @@ CancellationToken cancellationToken foreach (var method in group) { // Get the symbol being declared by the method - var methodSymbol = model.GetDeclaredSymbol(method); + var methodSymbol = model.GetDeclaredSymbol(method, cancellationToken: cancellationToken); if (!IsRefitMethod(methodSymbol, httpMethodBaseAttributeSymbol)) continue; @@ -85,7 +89,11 @@ CancellationToken cancellationToken m => m.ContainingType, SymbolEqualityComparer.Default ) - .ToDictionary(g => g.Key, v => v.ToList()); + .ToDictionary, INamedTypeSymbol, List>( + g => g.Key, + v => [.. v], + SymbolEqualityComparer.Default + ); // Look through the candidate interfaces var interfaceSymbols = new List(); @@ -95,7 +103,7 @@ CancellationToken cancellationToken foreach (var iface in group) { // get the symbol belonging to the interface - var ifaceSymbol = model.GetDeclaredSymbol(iface); + var ifaceSymbol = model.GetDeclaredSymbol(iface, cancellationToken: cancellationToken); // See if we already know about it, might be a dup if (ifaceSymbol is null || interfaces.ContainsKey(ifaceSymbol)) @@ -162,7 +170,7 @@ sealed class PreserveAttribute : global::System.Attribute // Is it needed in order to get the preserve attribute display name. // Will the compilation ever change this. compilation = compilation.AddSyntaxTrees( - CSharpSyntaxTree.ParseText(SourceText.From(attributeText, Encoding.UTF8), options) + CSharpSyntaxTree.ParseText(SourceText.From(attributeText, Encoding.UTF8), options, cancellationToken: cancellationToken) ); // get the newly bound attribute