private void AnalyzeSimpleMemberAccessExpression(SyntaxNodeAnalysisContext context) { var memberAccess = (MemberAccessExpressionSyntax)context.Node; UsePredefinedTypeRefactoring.Analyze(context, memberAccess); if (ReplaceStringEmptyWithEmptyStringLiteralRefactoring.CanRefactor(memberAccess, context.SemanticModel, context.CancellationToken)) { context.ReportDiagnostic(DiagnosticDescriptors.ReplaceStringEmptyWithEmptyStringLiteral, memberAccess.GetLocation()); } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context .Document .GetSyntaxRootAsync(context.CancellationToken) .ConfigureAwait(false); MemberAccessExpressionSyntax memberAccess = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <MemberAccessExpressionSyntax>(); CodeAction codeAction = CodeAction.Create( $"Replace '{memberAccess}' with \"\"", cancellationToken => { return(ReplaceStringEmptyWithEmptyStringLiteralRefactoring.RefactorAsync( context.Document, memberAccess, cancellationToken)); }, DiagnosticIdentifiers.ReplaceStringEmptyWithEmptyStringLiteral + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }