当前位置: 首页>>代码示例>>C#>>正文


C# ImmutableArray.WhereAsArray方法代码示例

本文整理汇总了C#中ImmutableArray.WhereAsArray方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableArray.WhereAsArray方法的具体用法?C# ImmutableArray.WhereAsArray怎么用?C# ImmutableArray.WhereAsArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImmutableArray的用法示例。


在下文中一共展示了ImmutableArray.WhereAsArray方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FixDocumentAsync

 protected override Task<Document> FixDocumentAsync(
     Document document, ImmutableArray<Diagnostic> diagnostics, CancellationToken cancellationToken)
 {
     var filteredDiagnostics = diagnostics.WhereAsArray(
         d => !d.Descriptor.CustomTags.Contains(WellKnownDiagnosticTags.Unnecessary));
     return _provider.FixAllAsync(document, filteredDiagnostics, cancellationToken);
 }
开发者ID:jkotas,项目名称:roslyn,代码行数:7,代码来源:UseThrowExpressionCodeFixProvider.FixAllProvider.cs

示例2: FixDocumentAsync

            protected override Task<Document> FixDocumentAsync(
                Document document, ImmutableArray<Diagnostic> diagnostics, CancellationToken cancellationToken)
            {
                // Filter out the diagnostics we created for the faded out code.  We don't want
                // to try to fix those as well as the normal diagnostics we created.
                var filteredDiagnostics = diagnostics.WhereAsArray(
                    d => !d.Descriptor.CustomTags.Contains(WellKnownDiagnosticTags.Unnecessary));

                // Defer to the actual SimplifyNullCheckCodeFixProvider to process htis
                // document.  It can process all the diagnostics and apply them properly.
                return _provider.FixAllAsync(document, filteredDiagnostics, cancellationToken);
            }
开发者ID:jkotas,项目名称:roslyn,代码行数:12,代码来源:InvokeDelegateWithConditionalAccessCodeFixProvider.FixAllProvider.cs

示例3: TryNavigateToOrPresentItemsAsync

        /// <summary>
        /// If there's only a single item, navigates to it.  Otherwise, presents all the
        /// items to the user.
        /// </summary>
        public static async Task<bool> TryNavigateToOrPresentItemsAsync(
            this IStreamingFindUsagesPresenter presenter, string title, 
            ImmutableArray<DefinitionItem> items, bool alwaysShowDeclarations)
        {
            // Ignore any definitions that we can't navigate to.
            var definitions = items.WhereAsArray(d => d.CanNavigateTo());

            // See if there's a third party external item we can navigate to.  If so, defer 
            // to that item and finish.
            var externalItems = definitions.WhereAsArray(d => d.IsExternal);
            foreach (var item in externalItems)
            {
                if (item.TryNavigateTo())
                {
                    return true;
                }
            }

            var nonExternalItems = definitions.WhereAsArray(d => !d.IsExternal);
            if (nonExternalItems.Length == 0)
            {
                return false;
            }

            if (nonExternalItems.Length == 1 &&
                nonExternalItems[0].SourceSpans.Length <= 1)
            {
                // There was only one location to navigate to.  Just directly go to that location.
                return nonExternalItems[0].TryNavigateTo();
            }

            if (presenter != null)
            {
                // We have multiple definitions, or we have definitions with multiple locations.
                // Present this to the user so they can decide where they want to go to.

                var context = presenter.StartSearch(title, alwaysShowDeclarations);
                foreach (var definition in nonExternalItems)
                {
                    await context.OnDefinitionFoundAsync(definition).ConfigureAwait(false);
                }

                // Note: we don't need to put this in a finally.  The only time we might not hit
                // this is if cancellation or another error gets thrown.  In the former case,
                // that means that a new search has started.  We don't care about telling the
                // context it has completed.  In the latter case somethign wrong has happened
                // and we don't want to run any more code code in this particular context.
                await context.OnCompletedAsync().ConfigureAwait(false);
            }

            return true;
        }
开发者ID:TyOverby,项目名称:roslyn,代码行数:56,代码来源:IStreamingFindReferencesPresenter.cs

示例4: ProcessParameterlessCrefMemberLookupResults

        /// <summary>
        /// At this point, we have a list of viable symbols and no parameter list with which to perform
        /// overload resolution.  We'll just return the first symbol, giving a diagnostic if there are
        /// others.
        /// Caveat: If there are multiple candidates and only one is from source, then the source symbol
        /// wins and no diagnostic is reported.
        /// </summary>
        private ImmutableArray<Symbol> ProcessParameterlessCrefMemberLookupResults(
            ImmutableArray<Symbol> symbols,
            int arity,
            MemberCrefSyntax memberSyntax,
            TypeArgumentListSyntax typeArgumentListSyntax,
            out Symbol ambiguityWinner,
            DiagnosticBag diagnostics)
        {
            // If the syntax indicates arity zero, then we match methods of any arity.
            // However, if there are both generic and non-generic methods, then the
            // generic methods should be ignored.
            if (symbols.Length > 1 && arity == 0)
            {
                bool hasNonGenericMethod = false;
                bool hasGenericMethod = false;
                foreach (Symbol s in symbols)
                {
                    if (s.Kind != SymbolKind.Method)
                    {
                        continue;
                    }

                    if (((MethodSymbol)s).Arity == 0)
                    {
                        hasNonGenericMethod = true;
                    }
                    else
                    {
                        hasGenericMethod = true;
                    }

                    if (hasGenericMethod && hasNonGenericMethod)
                    {
                        break; //Nothing else to be learned.
                    }
                }

                if (hasNonGenericMethod && hasGenericMethod)
                {
                    symbols = symbols.WhereAsArray(s =>
                        s.Kind != SymbolKind.Method || ((MethodSymbol)s).Arity == 0);
                }
            }

            Debug.Assert(!symbols.IsEmpty);

            Symbol symbol = symbols[0];

            // If there's ambiguity, prefer source symbols.
            // Logic is similar to ResultSymbol, but separate because the error handling is totally different.
            if (symbols.Length > 1)
            {
                // Size is known, but IndexOfSymbolFromCurrentCompilation expects a builder.
                ArrayBuilder<Symbol> unwrappedSymbols = ArrayBuilder<Symbol>.GetInstance(symbols.Length);

                foreach (Symbol wrapped in symbols)
                {
                    unwrappedSymbols.Add(UnwrapAliasNoDiagnostics(wrapped));
                }

                BestSymbolInfo secondBest;
                BestSymbolInfo best = GetBestSymbolInfo(unwrappedSymbols, out secondBest);

                Debug.Assert(!best.IsNone);
                Debug.Assert(!secondBest.IsNone);

                unwrappedSymbols.Free();

                int symbolIndex = 0;

                if (best.IsFromCompilation)
                {
                    symbolIndex = best.Index;
                    symbol = symbols[symbolIndex]; // NOTE: symbols, not unwrappedSymbols.
                }

                if (symbol.Kind == SymbolKind.TypeParameter)
                {
                    CrefSyntax crefSyntax = GetRootCrefSyntax(memberSyntax);
                    diagnostics.Add(ErrorCode.WRN_BadXMLRefTypeVar, crefSyntax.Location, crefSyntax.ToString());
                }
                else if (secondBest.IsFromCompilation == best.IsFromCompilation)
                {
                    CrefSyntax crefSyntax = GetRootCrefSyntax(memberSyntax);
                    int otherIndex = symbolIndex == 0 ? 1 : 0;
                    diagnostics.Add(ErrorCode.WRN_AmbiguousXMLReference, crefSyntax.Location, crefSyntax.ToString(), symbol, symbols[otherIndex]);

                    ambiguityWinner = ConstructWithCrefTypeParameters(arity, typeArgumentListSyntax, symbol);
                    return symbols.SelectAsArray(sym => ConstructWithCrefTypeParameters(arity, typeArgumentListSyntax, sym));
                }
            }
            else if (symbol.Kind == SymbolKind.TypeParameter)
            {
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:101,代码来源:Binder_Crefs.cs

示例5: SuppressDefaultTupleElements

        /// <summary>
        /// If container is a tuple type, any of its tuple element which has a friendly name will cause
        /// the suppression of the corresponding default name (ItemN).
        /// In that case, Rest is also removed.
        /// </summary>
        protected static ImmutableArray<ISymbol> SuppressDefaultTupleElements(
            INamespaceOrTypeSymbol container, ImmutableArray<ISymbol> symbols)
        {
            var namedType = container as INamedTypeSymbol;
            if (namedType?.IsTupleType != true)
            {
                // container is not a tuple
                return symbols;
            }

            //return tuple elements followed by other members that are not fields
            return ImmutableArray<ISymbol>.CastUp(namedType.TupleElements).
                Concat(symbols.WhereAsArray(s => s.Kind != SymbolKind.Field));
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:19,代码来源:AbstractRecommendationService.cs

示例6: FixDocumentAsync

 private Task<Document> FixDocumentAsync(
     Document document, ImmutableArray<Diagnostic> diagnostics, CancellationToken cancellationToken)
 {
     var filteredDiagnostics = diagnostics.WhereAsArray(_codeFixProvider.IncludeDiagnosticDuringFixAll);
     return _codeFixProvider.FixAllAsync(document, filteredDiagnostics, cancellationToken);
 }
开发者ID:TyOverby,项目名称:roslyn,代码行数:6,代码来源:SyntaxEditorBasedCodeFixProvider.FixAllProvider.cs

示例7: GetFilteredDocumentDiagnostics

        private ImmutableArray<Diagnostic> GetFilteredDocumentDiagnostics(ImmutableArray<Diagnostic> diagnostics, Compilation compilationOpt)
        {
            if (_root == null)
            {
                return diagnostics;
            }

            if (compilationOpt == null)
            {
                return diagnostics.WhereAsArray(IsLocalDiagnostic);
            }

            return CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics.Where(IsLocalDiagnostic), compilationOpt).ToImmutableArray();
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:14,代码来源:DiagnosticAnalyzerDriver.cs

示例8: SuppressDefaultTupleElements

        /// <summary>
        /// If container is a tuple type, any of its tuple element which has a friendly name will cause
        /// the suppression of the corresponding default name (ItemN).
        /// In that case, Rest is also removed.
        /// </summary>
        protected static ImmutableArray<ISymbol> SuppressDefaultTupleElements(
            INamespaceOrTypeSymbol container, ImmutableArray<ISymbol> symbols)
        {
            if (container?.IsType != true)
            {
                return symbols;
            }

            var type = (ITypeSymbol)container;
            if (!type.IsTupleType)
            {
                return symbols;
            }

            var tuple = (INamedTypeSymbol)type;
            var elementNames = tuple.TupleElementNames;
            if (elementNames.IsDefault)
            {
                return symbols;
            }

            // TODO This should be revised once we have a good public API for tuple fields
            // See https://github.com/dotnet/roslyn/issues/13229
            var fieldsToRemove = elementNames.Select((n, i) => IsFriendlyName(i, n) ? "Item" + (i + 1) : null)
                .Where(n => n != null).Concat("Rest").ToSet();

            return symbols.WhereAsArray(
                s => s.Kind != SymbolKind.Field ||
                     elementNames.Contains(s.Name) || 
                     !fieldsToRemove.Contains(s.Name));
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:36,代码来源:AbstractRecommendationService.cs


注:本文中的ImmutableArray.WhereAsArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。