本文整理汇总了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;
}
}
示例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;
}
示例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;
}
}