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


C# ImmutableArray.SelectMany方法代码示例

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


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

示例1: AnalyseSolutionAsync

        private async Task<List<ProjectAnalysisResult>> AnalyseSolutionAsync(Solution solution, ImmutableArray<DiagnosticAnalyzer> analyzers, Configuration configuration)
        {
            var ruleIds = analyzers
                .SelectMany(a => a.SupportedDiagnostics.Select(d => d.Id))
                .Where(d => !_configuration.DisabledDiagnostics.Contains(d))
                .ToImmutableHashSet();

            var projectAnalysisTasks = solution.Projects
                // First, Running analysis
                .Select(p => new { Project = p, Task = AnalyzeProjectAsync(p, analyzers) })
                .ToList()
                // Then we need to print all the results
                .Select(p => new { Project = p.Project, Task = p.Task.ContinueWith(t =>
                    {
                        var diagnostics = t.Result.Where(d => ruleIds.Contains(d.Id)).ToImmutableArray();
                        if (configuration.RunInfoLevelDiagnostics)
                        {
                            diagnostics = diagnostics.Where(d => d.Severity != DiagnosticSeverity.Info).ToImmutableArray();
                        }
                        LogDiagnostics(p.Project, diagnostics);

                        return t;
                    }).Unwrap()})
                .ToList();

            // And need to wait when all the analysis and printing tasks would be finished
            await Task.WhenAll(projectAnalysisTasks.Select(p => p.Task));

            // And only after now we can build the result
            var result =
                projectAnalysisTasks
                .Select(r => new ProjectAnalysisResult(r.Project, r.Task.Result.Where(d => ruleIds.Contains(d.Id)).ToImmutableArray())).ToList();

            return result;
        }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:35,代码来源:AnalyzerRunner.cs

示例2: PrintStatistics

        public static void PrintStatistics(List<ProjectAnalysisResult> diagnostics, ImmutableArray<DiagnosticAnalyzer> analyzers)
        {
            Contract.Requires(diagnostics != null);

            var analyzerDictionary = analyzers.SelectMany(a => a.SupportedDiagnostics).ToDictionarySafe(a => a.Id, a => a);

            var result =
                diagnostics
                    .SelectMany(d => d.Diagnostics)
                    .GroupBy(d => d.Id)
                    .Select(
                        g =>
                            new
                            {
                                Message = $"Diagnostic {g.Key}: {analyzerDictionary[g.Key].Title} -- {g.Count()} issues",
                                Severity = analyzerDictionary[g.Key].DefaultSeverity
                            })
                    .OrderBy(r => r.Severity);

            foreach (var e in result)
            {
                WriteInfo(e.Message);
                WriteFile(e.Message);
            }
        }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:25,代码来源:CustomLogger.cs

示例3: EncodeDescription

 private static string EncodeDescription(ImmutableArray<TaggedText> description)
 {
     if (description.Length > 0)
     {
         return string.Join("|",
             description
                 .SelectMany(d => new string[] { d.Tag, d.Text })
                 .Select(t => t.Escape('\\', s_descriptionSeparators)));
     }
     else
     {
         return null;
     }
 }
开发者ID:TyOverby,项目名称:roslyn,代码行数:14,代码来源:CommonCompletionItem.cs

示例4: GetFixAllAnalyzerAsync

        private static async Task<Document> GetFixAllAnalyzerAsync(FixAllScope scope, ImmutableArray<DiagnosticAnalyzer> analyzers, CodeFixProvider codeFixProvider, int? codeFixIndex, Document document, int numberOfIterations, CancellationToken cancellationToken)
        {
            int expectedNumberOfIterations = numberOfIterations;
            if (numberOfIterations < 0)
            {
                numberOfIterations = -numberOfIterations;
            }

            var previousDiagnostics = ImmutableArray.Create<Diagnostic>();

            var fixAllProvider = codeFixProvider.GetFixAllProvider();

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

            bool done;
            do
            {
                var analyzerDiagnostics = await GetSortedDiagnosticsFromDocumentsAsync(analyzers, new[] { document }, cancellationToken).ConfigureAwait(false);
                if (analyzerDiagnostics.Length == 0)
                {
                    break;
                }

                if (!AreDiagnosticsDifferent(analyzerDiagnostics, previousDiagnostics))
                {
                    break;
                }

                if (--numberOfIterations < 0)
                {
                    Assert.True(false, "The upper limit for the number of fix all iterations was exceeded");
                }

                string equivalenceKey = null;
                foreach (var diagnostic in analyzerDiagnostics)
                {
                    if (!codeFixProvider.FixableDiagnosticIds.Contains(diagnostic.Id))
                    {
                        // do not pass unsupported diagnostics to a code fix provider
                        continue;
                    }

                    var actions = new List<CodeAction>();
                    var context = new CodeFixContext(document, diagnostic, (a, d) => actions.Add(a), cancellationToken);
                    await codeFixProvider.RegisterCodeFixesAsync(context).ConfigureAwait(false);
                    if (actions.Count > (codeFixIndex ?? 0))
                    {
                        equivalenceKey = actions[codeFixIndex ?? 0].EquivalenceKey;
                        break;
                    }
                }

                previousDiagnostics = analyzerDiagnostics;

                done = true;

                FixAllContext.DiagnosticProvider fixAllDiagnosticProvider = TestDiagnosticProvider.Create(analyzerDiagnostics);

                IEnumerable<string> analyzerDiagnosticIds = analyzers.SelectMany(x => x.SupportedDiagnostics).Select(x => x.Id);
                IEnumerable<string> compilerDiagnosticIds = codeFixProvider.FixableDiagnosticIds.Where(x => x.StartsWith("CS", StringComparison.Ordinal));
                IEnumerable<string> disabledDiagnosticIds = document.Project.CompilationOptions.SpecificDiagnosticOptions.Where(x => x.Value == ReportDiagnostic.Suppress).Select(x => x.Key);
                IEnumerable<string> relevantIds = analyzerDiagnosticIds.Concat(compilerDiagnosticIds).Except(disabledDiagnosticIds).Distinct();
                FixAllContext fixAllContext = new FixAllContext(document, codeFixProvider, scope, equivalenceKey, relevantIds, fixAllDiagnosticProvider, cancellationToken);

                CodeAction action = await fixAllProvider.GetFixAsync(fixAllContext).ConfigureAwait(false);
                if (action == null)
                {
                    return document;
                }

                var fixedDocument = await ApplyFixAsync(document, action, cancellationToken).ConfigureAwait(false);
                if (fixedDocument != document)
                {
                    done = false;
                    var newText = await fixedDocument.GetTextAsync(cancellationToken).ConfigureAwait(false);

                    // workaround for issue #936 - force re-parsing to get the same sort of syntax tree as the original document.
                    document = document.WithText(newText);
                }
            }
            while (!done);

            if (expectedNumberOfIterations >= 0)
            {
                Assert.Equal($"{expectedNumberOfIterations} iterations", $"{expectedNumberOfIterations - numberOfIterations} iterations");
            }

            return document;
        }
开发者ID:sharwell,项目名称:PublicApiAnalyzer,代码行数:92,代码来源:CodeFixVerifier.cs

示例5: HasPureAttribute

        private bool HasPureAttribute(ImmutableArray<IMethodSymbol> methodChain)
        {
            var pureAttribute = _semanticModel.Compilation.GetTypeByMetadataName(typeof(PureAttribute).FullName);

            return methodChain.SelectMany(m => m.GetAttributes()).Any(a => a.AttributeClass.Equals(pureAttribute));
        }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:6,代码来源:PureMethodVerifier.cs

示例6: AnalyseSolutionAsync

        private static async Task<List<ProjectAnalysisResult>> AnalyseSolutionAsync(Solution solution, ImmutableArray<DiagnosticAnalyzer> analyzers, Options options)
        {
            var ruleIds = analyzers.SelectMany(a => a.SupportedDiagnostics.Select(d => d.Id)).ToImmutableHashSet();

            var projectAnalysisTasks = solution.Projects.Select(p => new {Project = p, Task = AnalyzeProjectAsync(p, analyzers)}).ToList();

            foreach (var task in projectAnalysisTasks)
            {
                var local = task;
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                task.Task.ContinueWith(tsk =>
                {
                    var relevantRules = tsk.Result.Where(d => ruleIds.Contains(d.Id)).ToImmutableArray();
                    if (options.PrintWarningsAndErrors)
                    {
                        PrintDiagnostics(local.Project, relevantRules);
                    }
                    if (!string.IsNullOrEmpty(options.LogFile))
                    {
                        WriteDiagnosticsToLog(options.LogFile, local.Project, relevantRules);
                    }
                }, TaskContinuationOptions.OnlyOnRanToCompletion);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }

            await Task.WhenAll(projectAnalysisTasks.Select(p => p.Task));

            var result = 
                projectAnalysisTasks
                .Select(r => new ProjectAnalysisResult(r.Project, r.Task.Result.Where(d => ruleIds.Contains(d.Id)).ToImmutableArray())).ToList();
            
            return result;
        }
开发者ID:SergeyTeplyakov,项目名称:SolutionDiagnosticRunner,代码行数:33,代码来源:Program.cs


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