public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); EnumMemberDeclarationSyntax enumMemberDeclaration = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <EnumMemberDeclarationSyntax>(); if (enumMemberDeclaration == null) { return; } CodeAction codeAction = CodeAction.Create( "Declare explicit value", cancellationToken => EnumMemberShouldDeclareExplicitValueRefactoring.RefactorAsync(context.Document, enumMemberDeclaration, cancellationToken), DiagnosticIdentifiers.EnumMemberShouldDeclareExplicitValue + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); EnumMemberDeclarationSyntax enumMemberDeclaration = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <EnumMemberDeclarationSyntax>(); if (enumMemberDeclaration == null) { return; } foreach (Diagnostic diagnostic in context.Diagnostics) { switch (diagnostic.Id) { case DiagnosticIdentifiers.EnumMemberShouldDeclareExplicitValue: { CodeAction codeAction = CodeAction.Create( "Declare explicit value", cancellationToken => EnumMemberShouldDeclareExplicitValueRefactoring.RefactorAsync(context.Document, enumMemberDeclaration, cancellationToken), diagnostic.Id + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, diagnostic); break; } case DiagnosticIdentifiers.DeclareEnumValueAsCombinationOfNames: { CodeAction codeAction = CodeAction.Create( "Declare value as combination of names", cancellationToken => DeclareEnumValueAsCombinationOfNamesRefactoring.RefactorAsync(context.Document, enumMemberDeclaration, cancellationToken), diagnostic.Id + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, diagnostic); break; } } } }