示例#1
0
        private void AnalyzeBlock(SyntaxNodeAnalysisContext context)
        {
            var block = (BlockSyntax)context.Node;

            FormatEachStatementOnSeparateLineRefactoring.Analyze(context, block);

            FormatEmptyBlockRefactoring.Analyze(context, block);
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out BlockSyntax block))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Format braces",
                cancellationToken => FormatEmptyBlockRefactoring.RefactorAsync(context.Document, block, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.FormatEmptyBlock));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            BlockSyntax block = root
                                .FindNode(context.Span, getInnermostNodeForTie: true)?
                                .FirstAncestorOrSelf <BlockSyntax>();

            if (block == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Format braces",
                cancellationToken => FormatEmptyBlockRefactoring.RefactorAsync(context.Document, block, cancellationToken),
                DiagnosticIdentifiers.FormatEmptyBlock + EquivalenceKeySuffix);

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }