private async Task <IEnumerable <IMethodSymbol> > GetAddMethodsAsync( SearchScope searchScope, SyntaxNode expression) { string name; int arity; _syntaxFacts.GetNameAndArityOfSimpleName(_node, out name, out arity); if (name != null) { return(SpecializedCollections.EmptyEnumerable <IMethodSymbol>()); } if (_owner.IsAddMethodContext(_node, _semanticModel)) { var symbols = await searchScope.FindDeclarationsAsync("Add", SymbolFilter.Member).ConfigureAwait(false); return(symbols .OfType <IMethodSymbol>() .Where(method => method.IsExtensionMethod && method.IsAccessibleWithin(_semanticModel.Compilation.Assembly) == true && _owner.IsViableExtensionMethod(method, expression, _semanticModel, _syntaxFacts, _cancellationToken))); } return(SpecializedCollections.EmptyEnumerable <IMethodSymbol>()); }
/// <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(_diagnostic, _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)))); }
private async Task <ImmutableArray <SymbolResult <IMethodSymbol> > > GetAddMethodsAsync( SearchScope searchScope, SyntaxNode expression) { _syntaxFacts.GetNameAndArityOfSimpleName(_node, out var name, out var arity); if (name != null || !_owner.IsAddMethodContext(_node, _semanticModel)) { return(ImmutableArray <SymbolResult <IMethodSymbol> > .Empty); } // 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 symbols = await searchScope.FindDeclarationsAsync("Add", nameNode : null, filter : SymbolFilter.Member).ConfigureAwait(false); return(OfType <IMethodSymbol>(symbols) .WhereAsArray(s => s.Symbol.IsExtensionMethod && s.Symbol.IsAccessibleWithin(_semanticModel.Compilation.Assembly) == true && _owner.IsViableExtensionMethod(s.Symbol, expression, _semanticModel, _syntaxFacts, searchScope.CancellationToken)) .SelectAsArray(s => s.WithDesiredName(null))); }