From ba93ec6a4e9c2de62b571da76b59f1023c8a8141 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Fri, 27 May 2016 16:18:17 -0700 Subject: [PATCH] Produce better names for backing fields. --- .../ReplacePropertyWithMethodsTests.cs | 13 +++++++++++++ .../CSharpReplacePropertyWithMethodsService.cs | 2 +- ...acePropertyWithMethodsCodeRefactoringProvider.cs | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs index 0e8ddf4c67e..20cdf871286 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs @@ -395,6 +395,19 @@ public async Task TestAutoProperty5() private int prop; private readonly int prop1 = 1; public int GetProp() { return this.prop1; } +}"); + } + + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)] + public async Task TestAutoProperty6() + { + await TestAsync( +@"class C { + public int [||]PascalCase { get; } +}", +@"class C { + private readonly int pascalCase; + public int GetPascalCase() { return this.pascalCase; } }"); } } diff --git a/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs b/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs index da963001986..cc5a8717169 100644 --- a/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs +++ b/src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs @@ -29,7 +29,7 @@ public override SyntaxNode GetPropertyDeclaration(SyntaxToken token) ? containingProperty.AttributeLists.Last().GetLastToken().GetNextToken().SpanStart : containingProperty.SpanStart; - // Offer this refactoring anywhere in the signature of the method. + // Offer this refactoring anywhere in the signature of the property. var position = token.SpanStart; if (position < start || position > containingProperty.Identifier.Span.End) { diff --git a/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs b/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs index 2ac5b64533f..7e83f210191 100644 --- a/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs @@ -153,7 +153,7 @@ private static IFieldSymbol GetBackingField(IPropertySymbol property) // the case for C# where we have mangled names for the backing field and need something // actually usable in code. var uniqueName = NameGenerator.GenerateUniqueName( - property.Name.ToLowerInvariant(), + property.Name.ToCamelCase(), n => !property.ContainingType.GetMembers(n).Any()); return CodeGenerationSymbolFactory.CreateFieldSymbol( -- GitLab