public static void ComputeRefactoring(RefactoringContext context, UsingDirectiveSyntax usingDirective) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveUsingAliasDirective)) { NameEqualsSyntax alias = usingDirective.Alias; if (alias != null) { IdentifierNameSyntax name = alias.Name; if (name != null && context.Span.IsContainedInSpanOrBetweenSpans(name)) { context.RegisterRefactoring( "Inline alias expression", cancellationToken => { return(RemoveUsingAliasDirectiveRefactoring.RefactorAsync( context.Document, usingDirective, cancellationToken)); }); } } } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); UsingDirectiveSyntax usingDirective = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <UsingDirectiveSyntax>(); if (usingDirective == null) { return; } string name = usingDirective.Alias.Name.Identifier.ValueText; CodeAction codeAction = CodeAction.Create( "Inline alias expression", cancellationToken => RemoveUsingAliasDirectiveRefactoring.RefactorAsync(context.Document, usingDirective, cancellationToken), DiagnosticIdentifiers.AvoidUsageOfUsingAliasDirective + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }