private static void ConvertStringEmptyToEmptyStringLiteral(CodeRefactoringContext context, MemberAccessExpressionSyntax memberAccess, SemanticModel semanticModel) { if (StringEmptyRefactoring.CanConvertStringEmptyToEmptyStringLiteral(memberAccess, semanticModel, context.CancellationToken)) { context.RegisterRefactoring( "Convert to \"\"", cancellationToken => { return(StringEmptyRefactoring.ConvertStringEmptyToEmptyStringLiteralAsync( context.Document, memberAccess, cancellationToken)); }); } else { memberAccess = (MemberAccessExpressionSyntax)memberAccess .FirstAncestor(SyntaxKind.SimpleMemberAccessExpression); if (memberAccess != null) { ConvertStringEmptyToEmptyStringLiteral(context, memberAccess, semanticModel); } } }
private static async Task ConvertStringEmptyToEmptyStringLiteralAsync(RefactoringContext context, MemberAccessExpressionSyntax memberAccess) { if (ReplaceStringEmptyWithEmptyStringLiteralRefactoring.CanRefactor(memberAccess, await context.GetSemanticModelAsync().ConfigureAwait(false), context.CancellationToken)) { context.RegisterRefactoring( $"Replace '{memberAccess}' with \"\"", cancellationToken => { return(ReplaceStringEmptyWithEmptyStringLiteralRefactoring.RefactorAsync( context.Document, memberAccess, cancellationToken)); }); } else { memberAccess = (MemberAccessExpressionSyntax)memberAccess .FirstAncestor(SyntaxKind.SimpleMemberAccessExpression); if (memberAccess != null) { await ConvertStringEmptyToEmptyStringLiteralAsync(context, memberAccess).ConfigureAwait(false); } } }
private static void UseEmptyStringLiteralInsteadOfStringEmpty(RefactoringContext context, SemanticModel semanticModel, MemberAccessExpressionSyntax memberAccess) { while (memberAccess != null) { if (UseEmptyStringLiteralInsteadOfStringEmptyAnalysis.IsFixable(memberAccess, semanticModel, context.CancellationToken)) { context.RegisterRefactoring( $"Use \"\" instead of '{memberAccess}'", cancellationToken => { return(UseEmptyStringLiteralInsteadOfStringEmptyRefactoring.RefactorAsync( context.Document, memberAccess, cancellationToken)); }); break; } memberAccess = (MemberAccessExpressionSyntax)memberAccess.FirstAncestor(SyntaxKind.SimpleMemberAccessExpression); } }