public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out DestructorDeclarationSyntax destructor)) { return; } foreach (Diagnostic diagnostic in context.Diagnostics) { switch (diagnostic.Id) { case DiagnosticIdentifiers.RemoveEmptyDestructor: { CodeAction codeAction = CodeAction.Create( "Remove empty destructor", cancellationToken => RemoveEmptyDestructorRefactoring.RefactorAsync(context.Document, destructor, cancellationToken), GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); break; } } } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); DestructorDeclarationSyntax destructor = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <DestructorDeclarationSyntax>(); Debug.Assert(destructor != null, $"{nameof(destructor)} is null"); if (destructor == null) { return; } foreach (Diagnostic diagnostic in context.Diagnostics) { switch (diagnostic.Id) { case DiagnosticIdentifiers.RemoveEmptyDestructor: { CodeAction codeAction = CodeAction.Create( "Remove empty destructor", cancellationToken => RemoveEmptyDestructorRefactoring.RefactorAsync(context.Document, destructor, cancellationToken), diagnostic.Id + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, diagnostic); break; } } } }
public override void Initialize(AnalysisContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } base.Initialize(context); context.RegisterSyntaxNodeAction( f => RemoveEmptyDestructorRefactoring.AnalyzeDestructorDeclaration(f), SyntaxKind.DestructorDeclaration); }
private void AnalyzeAccessorList(SyntaxNodeAnalysisContext context) { var destructor = (DestructorDeclarationSyntax)context.Node; RemoveEmptyDestructorRefactoring.Analyze(context, destructor); }