本文整理汇总了C#中Microsoft.CodeAnalysis.CodeFixes.FixAllContext.GetProjectDiagnosticsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# FixAllContext.GetProjectDiagnosticsAsync方法的具体用法?C# FixAllContext.GetProjectDiagnosticsAsync怎么用?C# FixAllContext.GetProjectDiagnosticsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CodeFixes.FixAllContext
的用法示例。
在下文中一共展示了FixAllContext.GetProjectDiagnosticsAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProjectDiagnosticsToFixAsync
public static 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;
}
示例2: 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;
}
}
示例3: GetProjectDiagnosticsToFixAsync
internal 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 = ImmutableDictionary.CreateBuilder<Project, ImmutableArray<Diagnostic>>();
var tasks = project.Solution.Projects.Select(async p => new
{
Project = p,
Diagnostics = await fixAllContext.GetProjectDiagnosticsAsync(p).ConfigureAwait(false)
}).ToArray();
await Task.WhenAll(tasks).ConfigureAwait(false);
foreach (var task in tasks)
{
var projectAndDiagnostics = await task.ConfigureAwait(false);
if (projectAndDiagnostics.Diagnostics.Any())
{
projectsAndDiagnostics[projectAndDiagnostics.Project] = projectAndDiagnostics.Diagnostics;
}
}
return projectsAndDiagnostics.ToImmutable();
}
}
return ImmutableDictionary<Project, ImmutableArray<Diagnostic>>.Empty;
}
}