public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out AnonymousMethodExpressionSyntax anonymousMethod)) { return; } CodeAction codeAction = CodeAction.Create( "Use lambda expression instead of anonymous method", cancellationToken => UseLambdaExpressionInsteadOfAnonymousMethodRefactoring.RefactorAsync(context.Document, anonymousMethod, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.UseLambdaExpressionInsteadOfAnonymousMethod)); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); AnonymousMethodExpressionSyntax anonymousMethod = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <AnonymousMethodExpressionSyntax>(); if (anonymousMethod == null) { return; } CodeAction codeAction = CodeAction.Create( "Use lambda expression instead of anonymous method", cancellationToken => UseLambdaExpressionInsteadOfAnonymousMethodRefactoring.RefactorAsync(context.Document, anonymousMethod, cancellationToken), DiagnosticIdentifiers.UseLambdaExpressionInsteadOfAnonymousMethod + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }