/// <summary> /// Searches for extension methods exactly called 'Add'. Returns /// <see cref="SymbolReference"/>s to the <see cref="INamespaceSymbol"/>s that contain /// the static classes that those extension methods are contained in. /// </summary> private async Task <ImmutableArray <SymbolReference> > GetReferencesForCollectionInitializerMethodsAsync(SearchScope searchScope) { searchScope.CancellationToken.ThrowIfCancellationRequested(); if (!_owner.CanAddImportForMethod(_diagnosticId, _syntaxFacts, _node, out var nameNode)) { return(ImmutableArray <SymbolReference> .Empty); } _syntaxFacts.GetNameAndArityOfSimpleName(_node, out var name, out var arity); if (name != null || !_owner.IsAddMethodContext(_node, _semanticModel)) { return(ImmutableArray <SymbolReference> .Empty); } var symbols = await searchScope.FindDeclarationsAsync( nameof(IList.Add), nameNode : null, filter : SymbolFilter.Member).ConfigureAwait(false); // Note: there is no desiredName for these search results. We're searching for // extension methods called "Add", but we have no intention of renaming any // of the existing user code to that name. var methodSymbols = OfType <IMethodSymbol>(symbols).SelectAsArray(s => s.WithDesiredName(null)); var viableMethods = GetViableExtensionMethods( methodSymbols, _node.Parent, searchScope.CancellationToken); return(GetNamespaceSymbolReferences(searchScope, viableMethods.SelectAsArray(m => m.WithSymbol(m.Symbol.ContainingNamespace)))); }