public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); TypeSyntax type = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <TypeSyntax>(); Debug.Assert(type != null, $"{nameof(type)} is null"); if (type == null) { return; } SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); GenericNameSyntax newType = UseGenericEventHandlerRefactoring.CreateGenericEventHandler(type, semanticModel, context.CancellationToken); CodeAction codeAction = CodeAction.Create( $"Use '{newType}'", cancellationToken => UseGenericEventHandlerRefactoring.RefactorAsync(context.Document, type, cancellationToken), DiagnosticIdentifiers.UseGenericEventHandler + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out TypeSyntax type)) { return; } SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); GenericNameSyntax newType = UseGenericEventHandlerRefactoring.CreateGenericEventHandler(type, semanticModel, context.CancellationToken); CodeAction codeAction = CodeAction.Create( $"Use '{newType}'", cancellationToken => UseGenericEventHandlerRefactoring.RefactorAsync(context.Document, type, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.UseGenericEventHandler)); context.RegisterCodeFix(codeAction, context.Diagnostics); }