本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.DiagnosticData.ToDiagnosticAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticData.ToDiagnosticAsync方法的具体用法?C# DiagnosticData.ToDiagnosticAsync怎么用?C# DiagnosticData.ToDiagnosticAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Diagnostics.DiagnosticData
的用法示例。
在下文中一共展示了DiagnosticData.ToDiagnosticAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContainsAnyFix
private async Task<bool> ContainsAnyFix(Document document, DiagnosticData diagnostic, bool considerSuppressionFixes, CancellationToken cancellationToken)
{
ImmutableArray<CodeFixProvider> workspaceFixers = ImmutableArray<CodeFixProvider>.Empty;
List<CodeFixProvider> projectFixers = null;
Lazy<ImmutableDictionary<DiagnosticId, ImmutableArray<CodeFixProvider>>> fixerMap;
bool hasAnySharedFixer = _workspaceFixersMap.TryGetValue(document.Project.Language, out fixerMap) && fixerMap.Value.TryGetValue(diagnostic.Id, out workspaceFixers);
var hasAnyProjectFixer = GetProjectFixers(document.Project).TryGetValue(diagnostic.Id, out projectFixers);
// TODO (https://github.com/dotnet/roslyn/issues/4932): Don't restrict CodeFixes in Interactive
if (hasAnySharedFixer && document.Project.Solution.Workspace.Kind == WorkspaceKind.Interactive)
{
workspaceFixers = workspaceFixers.WhereAsArray(IsInteractiveCodeFixProvider);
hasAnySharedFixer = workspaceFixers.Any();
}
Lazy<ISuppressionFixProvider> lazySuppressionProvider = null;
var hasSuppressionFixer =
considerSuppressionFixes &&
_suppressionProvidersMap.TryGetValue(document.Project.Language, out lazySuppressionProvider) &&
lazySuppressionProvider.Value != null;
if (!hasAnySharedFixer && !hasAnyProjectFixer && !hasSuppressionFixer)
{
return false;
}
var allFixers = ImmutableArray<CodeFixProvider>.Empty;
if (hasAnySharedFixer)
{
allFixers = workspaceFixers;
}
if (hasAnyProjectFixer)
{
allFixers = allFixers.AddRange(projectFixers);
}
var dx = await diagnostic.ToDiagnosticAsync(document.Project, cancellationToken).ConfigureAwait(false);
if (hasSuppressionFixer && lazySuppressionProvider.Value.CanBeSuppressedOrUnsuppressed(dx))
{
return true;
}
var fixes = new List<CodeFix>();
var context = new CodeFixContext(document, dx,
// TODO: Can we share code between similar lambdas that we pass to this API in BatchFixAllProvider.cs, CodeFixService.cs and CodeRefactoringService.cs?
(action, applicableDiagnostics) =>
{
// Serialize access for thread safety - we don't know what thread the fix provider will call this delegate from.
lock (fixes)
{
fixes.Add(new CodeFix(document.Project, action, applicableDiagnostics));
}
},
verifyArguments: false,
cancellationToken: cancellationToken);
var extensionManager = document.Project.Solution.Workspace.Services.GetService<IExtensionManager>();
// we do have fixer. now let's see whether it actually can fix it
foreach (var fixer in allFixers)
{
await extensionManager.PerformActionAsync(fixer, () => fixer.RegisterCodeFixesAsync(context) ?? SpecializedTasks.EmptyTask).ConfigureAwait(false);
if (!fixes.Any())
{
continue;
}
return true;
}
return false;
}