本文整理汇总了C#中Microsoft.CodeAnalysis.CodeFixes.FixAllContext.WithCancellationToken方法的典型用法代码示例。如果您正苦于以下问题:C# FixAllContext.WithCancellationToken方法的具体用法?C# FixAllContext.WithCancellationToken怎么用?C# FixAllContext.WithCancellationToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CodeFixes.FixAllContext
的用法示例。
在下文中一共展示了FixAllContext.WithCancellationToken方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFixAsync
public override Task<CodeAction> GetFixAsync(FixAllContext fixAllContext)
{
CodeAction fixAction;
switch (fixAllContext.Scope)
{
case FixAllScope.Document:
fixAction = CodeAction.Create(
this.CodeActionTitle,
cancellationToken => this.GetDocumentFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
nameof(DocumentBasedFixAllProvider));
break;
case FixAllScope.Project:
fixAction = CodeAction.Create(
this.CodeActionTitle,
cancellationToken => this.GetProjectFixesAsync(fixAllContext.WithCancellationToken(cancellationToken), fixAllContext.Project),
nameof(DocumentBasedFixAllProvider));
break;
case FixAllScope.Solution:
fixAction = CodeAction.Create(
this.CodeActionTitle,
cancellationToken => this.GetSolutionFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
nameof(DocumentBasedFixAllProvider));
break;
case FixAllScope.Custom:
default:
fixAction = null;
break;
}
return Task.FromResult(fixAction);
}
示例2: GetFixAsync
public override Task<CodeAction> GetFixAsync(FixAllContext fixAllContext)
{
switch (fixAllContext.Scope)
{
case FixAllScope.Document:
{
return Task.FromResult(CodeAction.Create(UseEmptyStringCodeFixProvider.MessageFormat,
async ct =>
{
var newFixAllContext = fixAllContext.WithCancellationToken(ct);
var diagnostics = await newFixAllContext.GetDocumentDiagnosticsAsync(newFixAllContext.Document).ConfigureAwait(false);
var root = await GetFixedDocumentAsync(newFixAllContext.Document, diagnostics, ct).ConfigureAwait(false);
return newFixAllContext.Document.WithSyntaxRoot(root);
}));
}
case FixAllScope.Project:
return Task.FromResult(CodeAction.Create(UseEmptyStringCodeFixProvider.MessageFormat,
ct =>
{
var newFixAllContext = fixAllContext.WithCancellationToken(ct);
return GetFixedProjectAsync(newFixAllContext, newFixAllContext.WithCancellationToken(ct).Project);
}));
case FixAllScope.Solution:
return Task.FromResult(CodeAction.Create(UseEmptyStringCodeFixProvider.MessageFormat,
ct => GetFixedSolutionAsync(fixAllContext.WithCancellationToken(ct))));
}
return null;
}
示例3: GetFixAllCodeAction
private CodeAction GetFixAllCodeAction(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllTitle, string waitDialogMessage, out bool userCancelled)
{
userCancelled = false;
// Compute fix all occurrences code fix for the given fix all context.
// Bring up a cancellable wait dialog.
CodeAction codeAction = null;
using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation, fixAllContext.CancellationToken))
{
var result = _waitIndicator.Wait(
fixAllTitle,
waitDialogMessage,
allowCancel: true,
action: waitContext =>
{
fixAllContext.CancellationToken.ThrowIfCancellationRequested();
using (var linkedCts =
CancellationTokenSource.CreateLinkedTokenSource(waitContext.CancellationToken, fixAllContext.CancellationToken))
{
try
{
var fixAllContextWithCancellation = fixAllContext.WithCancellationToken(linkedCts.Token);
var fixTask = fixAllProvider.GetFixAsync(fixAllContextWithCancellation);
if (fixTask != null)
{
codeAction = fixTask.WaitAndGetResult(linkedCts.Token);
}
}
catch (OperationCanceledException)
{
fixAllContext.CancellationToken.ThrowIfCancellationRequested();
}
}
});
userCancelled = result == WaitIndicatorResult.Canceled;
var cancelled = userCancelled || codeAction == null;
if (cancelled)
{
FixAllLogger.LogComputationResult(completed: false, timedOut: result != WaitIndicatorResult.Canceled);
return null;
}
}
FixAllLogger.LogComputationResult(completed: true);
return codeAction;
}
示例4: GetFixAsync
public override Task<CodeAction> GetFixAsync(FixAllContext fixAllContext)
{
string title = string.Format(MaintainabilityResources.SA1412CodeFix, fixAllContext.CodeActionEquivalenceKey.Substring(fixAllContext.CodeActionEquivalenceKey.IndexOf('.') + 1));
CodeAction fixAction;
switch (fixAllContext.Scope)
{
case FixAllScope.Document:
fixAction = CodeAction.Create(
title,
cancellationToken => GetDocumentFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
nameof(SA1412FixAllProvider));
break;
case FixAllScope.Project:
fixAction = CodeAction.Create(
title,
cancellationToken => GetProjectFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
nameof(SA1412FixAllProvider));
break;
case FixAllScope.Solution:
fixAction = CodeAction.Create(
title,
cancellationToken => GetSolutionFixesAsync(fixAllContext.WithCancellationToken(cancellationToken)),
nameof(SA1412FixAllProvider));
break;
case FixAllScope.Custom:
default:
fixAction = null;
break;
}
return Task.FromResult(fixAction);
}
示例5: GetFixAllOperationsAsync
public async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext)
{
// Compute fix all occurrences code fix for the given fix all context.
// Bring up a cancellable wait dialog.
CodeAction codeAction = null;
using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation, fixAllContext.CancellationToken))
{
var result = _waitIndicator.Wait(
EditorFeaturesResources.FixAllOccurrences,
EditorFeaturesResources.ComputingFixAllOccurrences,
allowCancel: true,
action: waitContext =>
{
fixAllContext.CancellationToken.ThrowIfCancellationRequested();
using (var linkedCts =
CancellationTokenSource.CreateLinkedTokenSource(waitContext.CancellationToken, fixAllContext.CancellationToken))
{
try
{
var fixAllContextWithCancellation = fixAllContext.WithCancellationToken(linkedCts.Token);
var fixTask = fixAllProvider.GetFixAsync(fixAllContextWithCancellation);
if (fixTask != null)
{
codeAction = fixTask.WaitAndGetResult(linkedCts.Token);
}
}
catch (OperationCanceledException)
{
fixAllContext.CancellationToken.ThrowIfCancellationRequested();
}
}
});
var cancelled = result == WaitIndicatorResult.Canceled || codeAction == null;
if (cancelled)
{
FixAllLogger.LogComputationResult(completed: false, timedOut: result != WaitIndicatorResult.Canceled);
return null;
}
}
FixAllLogger.LogComputationResult(completed: true);
return await GetFixAllOperationsAsync(codeAction, fixAllContext).ConfigureAwait(false);
}