未验证 提交 bf71ef42 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #42714 from YairHalberstadt/unique-name-replace-method-with-property

GenerateUniqueName for ReplaceMethodWithProperty
...@@ -2335,6 +2335,30 @@ int GetGoo() ...@@ -2335,6 +2335,30 @@ int GetGoo()
}"); }");
} }
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)]
[WorkItem(42699, "https://github.com/dotnet/roslyn/issues/42699")]
public async Task TestSameNameMemberAsProperty()
{
await TestInRegularAndScript1Async(
@"class C
{
int Goo;
[||]int GetGoo()
{
}
}",
@"class C
{
int Goo;
int Goo1
{
get
{
}
}
}");
}
private async Task TestWithAllCodeStyleOff( private async Task TestWithAllCodeStyleOff(
string initialMarkup, string expectedMarkup, string initialMarkup, string expectedMarkup,
ParseOptions parseOptions = null, int index = 0) ParseOptions parseOptions = null, int index = 0)
......
...@@ -911,5 +911,41 @@ end class") ...@@ -911,5 +911,41 @@ end class")
End Function End Function
end class") end class")
End Function End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)>
<WorkItem(42699, "https://github.com/dotnet/roslyn/issues/42699")>
Public Async Function TestSameNameMemberAsProperty() As Task
Await TestInRegularAndScriptAsync(
"class C
Public Goo as integer
function [||]GetGoo() as integer
End function
End class",
"class C
Public Goo as integer
ReadOnly Property Goo1 as integer
Get
End Get
End Property
End class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)>
<WorkItem(42699, "https://github.com/dotnet/roslyn/issues/42699")>
Public Async Function TestSameNameMemberAsPropertyDifferentCase() As Task
Await TestInRegularAndScriptAsync(
"class C
Public goo as integer
function [||]GetGoo() as integer
End function
End class",
"class C
Public goo as integer
ReadOnly Property Goo1 as integer
Get
End Get
End Property
End class")
End Function
End Class End Class
End Namespace End Namespace
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Roslyn.Utilities; using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.ReplaceMethodWithProperty namespace Microsoft.CodeAnalysis.ReplaceMethodWithProperty
...@@ -58,7 +59,9 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte ...@@ -58,7 +59,9 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var hasGetPrefix = HasGetPrefix(methodName); var hasGetPrefix = HasGetPrefix(methodName);
var propertyName = hasGetPrefix var propertyName = hasGetPrefix
? methodName.Substring(GetPrefix.Length) ? NameGenerator.GenerateUniqueName(
methodName.Substring(GetPrefix.Length),
n => !methodSymbol.ContainingType.GetMembers(n).Any())
: methodName; : methodName;
var nameChanged = hasGetPrefix; var nameChanged = hasGetPrefix;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册