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


C# FixAllContext.WithCancellationToken方法代码示例

本文整理汇总了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);
        }
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:34,代码来源:DocumentBasedFixAllProvider.cs

示例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;
        }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:29,代码来源:UseEmptyStringCodeFixProviderAll.cs

示例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;
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:49,代码来源:FixAllGetFixesService.cs

示例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);
        }
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:36,代码来源:SA1412FixAllProvider.cs

示例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);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:46,代码来源:FixAllGetFixesService.cs


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