Skip to content

Commit 61f0098

Browse files
committed
Fixed failing test
1 parent 8086ca4 commit 61f0098

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/NamingRules/RenameToLowerCaseCodeFixProvider.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
6161

6262
baseName = char.ToLower(baseName[0]) + baseName.Substring(1);
6363
int underscoreCount = originalName.Length - baseName.Length;
64-
var newName = originalName.Substring(0, underscoreCount) + baseName;
64+
6565
var memberSyntax = RenameHelper.GetParentDeclaration(token);
6666

6767
SemanticModel semanticModel = await document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
@@ -72,11 +72,15 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
7272
continue;
7373
}
7474

75+
// preserve the underscores, but only for fields.
76+
var prefix = declaredSymbol.Kind == SymbolKind.Field ? originalName.Substring(0, underscoreCount) : string.Empty;
77+
var newName = prefix + baseName;
78+
7579
int index = 0;
7680
while (!await RenameHelper.IsValidNewMemberNameAsync(semanticModel, declaredSymbol, newName, context.CancellationToken).ConfigureAwait(false))
7781
{
7882
index++;
79-
newName = originalName.Substring(0, underscoreCount) + baseName + index;
83+
newName = prefix + baseName + index;
8084
}
8185

8286
context.RegisterCodeFix(

0 commit comments

Comments
 (0)