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

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out EnumDeclarationSyntax enumDeclaration))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Declare enum member with zero value",
                cancellationToken => DeclareEnumMemberWithZeroValueRefactoring.RefactorAsync(context.Document, enumDeclaration, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.DeclareEnumMemberWithZeroValue));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
예제 #2
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

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

            Debug.Assert(enumDeclaration != null, $"{enumDeclaration} is null");

            if (enumDeclaration == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Declare enum member with zero value",
                cancellationToken => DeclareEnumMemberWithZeroValueRefactoring.RefactorAsync(context.Document, enumDeclaration, cancellationToken),
                DiagnosticIdentifiers.DeclareEnumMemberWithZeroValue + BaseCodeFixProvider.EquivalenceKeySuffix);

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