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


C# ConcurrentDictionary.ToImmutableDictionary方法代码示例

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


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

示例1: GetProjectDiagnosticsToFixAsync

        public virtual async Task<ImmutableDictionary<Project, ImmutableArray<Diagnostic>>> GetProjectDiagnosticsToFixAsync(FixAllContext fixAllContext)
        {
            using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation_Diagnostics, fixAllContext.CancellationToken))
            {
                var project = fixAllContext.Project;
                if (project != null)
                {
                    switch (fixAllContext.Scope)
                    {
                        case FixAllScope.Project:
                            var diagnostics = await fixAllContext.GetProjectDiagnosticsAsync(project).ConfigureAwait(false);
                            var kvp = SpecializedCollections.SingletonEnumerable(KeyValuePair.Create(project, diagnostics));
                            return ImmutableDictionary.CreateRange(kvp);

                        case FixAllScope.Solution:
                            var projectsAndDiagnostics = new ConcurrentDictionary<Project, ImmutableArray<Diagnostic>>();
                            var options = new ParallelOptions() { CancellationToken = fixAllContext.CancellationToken };
                            Parallel.ForEach(project.Solution.Projects, options, proj =>
                            {
                                fixAllContext.CancellationToken.ThrowIfCancellationRequested();
                                var projectDiagnostics = fixAllContext.GetProjectDiagnosticsAsync(proj).WaitAndGetResult(fixAllContext.CancellationToken);
                                if (projectDiagnostics.Any())
                                {
                                    projectsAndDiagnostics.TryAdd(proj, projectDiagnostics);
                                }
                            });

                            return projectsAndDiagnostics.ToImmutableDictionary();
                    }
                }

                return ImmutableDictionary<Project, ImmutableArray<Diagnostic>>.Empty;
            }
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:34,代码来源:BatchFixAllProvider.cs

示例2: GetProjectDiagnosticsToFixAsync

        public virtual async Task<ImmutableDictionary<Project, ImmutableArray<Diagnostic>>> GetProjectDiagnosticsToFixAsync(FixAllContext fixAllContext)
        {
            var project = fixAllContext.Project;
            if (project != null)
            {
                switch (fixAllContext.Scope)
                {
                case FixAllScope.Project:
                    var diagnostics = await fixAllContext.GetProjectDiagnosticsAsync(project).ConfigureAwait(false);
                    return ImmutableDictionary<Project, ImmutableArray<Diagnostic>>.Empty.SetItem(project, diagnostics);

                case FixAllScope.Solution:
                    var projectsAndDiagnostics = new ConcurrentDictionary<Project, ImmutableArray<Diagnostic>>();
                    var options = new ParallelOptions() { CancellationToken = fixAllContext.CancellationToken };
                    Parallel.ForEach(project.Solution.Projects, options, proj =>
                    {
                        fixAllContext.CancellationToken.ThrowIfCancellationRequested();
                        var projectDiagnosticsTask = fixAllContext.GetProjectDiagnosticsAsync(proj);
                        projectDiagnosticsTask.Wait(fixAllContext.CancellationToken);
                        var projectDiagnostics = projectDiagnosticsTask.Result;
                        if (projectDiagnostics.Any())
                        {
                            projectsAndDiagnostics.TryAdd(proj, projectDiagnostics);
                        }
                    });

                    return projectsAndDiagnostics.ToImmutableDictionary();
                }
            }

            return ImmutableDictionary<Project, ImmutableArray<Diagnostic>>.Empty;
        }
开发者ID:journeyman,项目名称:StyleCopAnalyzers,代码行数:32,代码来源:CustomBatchFixAllProvider.cs

示例3: GetDocumentDiagnosticsToFixAsync

        public virtual async Task<ImmutableDictionary<Document, ImmutableArray<Diagnostic>>> GetDocumentDiagnosticsToFixAsync(FixAllContext fixAllContext)
        {
            using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation_Diagnostics, fixAllContext.CancellationToken))
            {
                IEnumerable<Document> documentsToFix = null;
                var document = fixAllContext.Document;
                var project = fixAllContext.Project;

                var generatedCodeServices = project.Solution.Workspace.Services.GetService<IGeneratedCodeRecognitionService>();

                switch (fixAllContext.Scope)
                {
                    case FixAllScope.Document:
                        if (document != null && !generatedCodeServices.IsGeneratedCode(document))
                        {
                            var diagnostics = await fixAllContext.GetDocumentDiagnosticsAsync(document).ConfigureAwait(false);
                            var kvp = SpecializedCollections.SingletonEnumerable(KeyValuePair.Create(document, diagnostics));
                            return ImmutableDictionary.CreateRange(kvp);
                        }

                        break;

                    case FixAllScope.Project:
                        documentsToFix = project.Documents;
                        break;

                    case FixAllScope.Solution:
                        documentsToFix = project.Solution.Projects
                            .Where(p => p.Language == project.Language)
                            .SelectMany(p => p.Documents);
                        break;
                }

                if (documentsToFix != null && documentsToFix.Any())
                {
                    var documentAndDiagnostics = new ConcurrentDictionary<Document, ImmutableArray<Diagnostic>>();
                    var options = new ParallelOptions() { CancellationToken = fixAllContext.CancellationToken };
                    Parallel.ForEach(documentsToFix, options, doc =>
                    {
                        fixAllContext.CancellationToken.ThrowIfCancellationRequested();

                        if (!generatedCodeServices.IsGeneratedCode(doc))
                        {
                            var documentDiagnostics = fixAllContext.GetDocumentDiagnosticsAsync(doc).WaitAndGetResult(fixAllContext.CancellationToken);
                            if (documentDiagnostics.Any())
                            {
                                documentAndDiagnostics.TryAdd(doc, documentDiagnostics);
                            }
                        }
                    });

                    return documentAndDiagnostics.ToImmutableDictionary();
                }

                return ImmutableDictionary<Document, ImmutableArray<Diagnostic>>.Empty;
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:57,代码来源:BatchFixAllProvider.cs


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