コード例 #1
0
            private async Task <IList <SymbolReference> > GetNamespacesForQueryPatternsAsync(SearchScope searchScope)
            {
                if (!_owner.CanAddImportForQuery(_diagnostic, ref _node))
                {
                    return(null);
                }

                ITypeSymbol type = _owner.GetQueryClauseInfo(_semanticModel, _node, _cancellationToken);

                if (type == null)
                {
                    return(null);
                }

                // find extension methods named "Select"
                var symbols = await searchScope.FindDeclarationsAsync("Select", SymbolFilter.Member).ConfigureAwait(false);

                var extensionMethodSymbols = symbols
                                             .OfType <IMethodSymbol>()
                                             .Where(s => s.IsExtensionMethod && _owner.IsViableExtensionMethod(type, s))
                                             .ToList();

                return(GetProposedNamespaces(
                           searchScope, extensionMethodSymbols.Select(s => s.ContainingNamespace)));
            }
            private async Task <IList <SymbolReference> > GetNamespacesForQueryPatternsAsync(SearchScope searchScope)
            {
                searchScope.CancellationToken.ThrowIfCancellationRequested();

                if (!_owner.CanAddImportForQuery(_diagnostic, _node))
                {
                    return(null);
                }

                ITypeSymbol type = _owner.GetQueryClauseInfo(_semanticModel, _node, searchScope.CancellationToken);

                if (type == null)
                {
                    return(null);
                }

                // find extension methods named "Select"
                var symbols = await searchScope.FindDeclarationsAsync("Select", nameNode : null, filter : SymbolFilter.Member).ConfigureAwait(false);

                // Note: there is no "desiredName" when doing this.  We're not going to do any
                // renames of the user code.  We're just looking for an extension method called
                // "Select", but that name has no bearing on the code in question that we're
                // trying to fix up.
                var extensionMethodSymbols = OfType <IMethodSymbol>(symbols)
                                             .Where(s => s.Symbol.IsExtensionMethod && _owner.IsViableExtensionMethod(s.Symbol, type))
                                             .Select(s => s.WithDesiredName(null))
                                             .ToList();

                return(GetProposedNamespaces(
                           searchScope, extensionMethodSymbols.Select(s => s.WithSymbol(s.Symbol.ContainingNamespace))));
            }
コード例 #3
0
            /// <summary>
            /// Searches for extension methods exactly called 'Select'.  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> > GetReferencesForQueryPatternsAsync(SearchScope searchScope)
            {
                searchScope.CancellationToken.ThrowIfCancellationRequested();

                if (_owner.CanAddImportForQuery(_diagnostic, _node))
                {
                    var type = _owner.GetQueryClauseInfo(_semanticModel, _node, searchScope.CancellationToken);
                    if (type != null)
                    {
                        // find extension methods named "Select"
                        return(await GetReferencesForExtensionMethodAsync(
                                   searchScope, nameof(Enumerable.Select), type).ConfigureAwait(false));
                    }
                }

                return(ImmutableArray <SymbolReference> .Empty);
            }