提交 bdb8ff07 编写于 作者: C CyrusNajmabadi

Merge pull request #6799 from CyrusNajmabadi/replaceMethodCaseInsensitive

Allow the 'replace method with property' refactoring to work with get/set methods, not just Get/Set methods.

Fixes #6718
......@@ -409,6 +409,15 @@ public void TestWithPartialClasses()
Test(
@"partial class C { int [||]GetFoo() { } } partial class C { void SetFoo(int i) { } }",
@"partial class C { int Foo { get { } set { } } } partial class C { }",
index: 1);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)]
public void TestUpdateGetSetCaseInsensitive()
{
Test(
@"using System; class C { int [||]getFoo() { } void setFoo(int i) { } }",
@"using System; class C { int Foo { get { } set { } } }",
index: 1);
}
}
......
......@@ -95,14 +95,20 @@ private static bool HasGetPrefix(SyntaxToken identifier)
private static bool HasGetPrefix(string text)
{
return text.StartsWith(GetPrefix) && text.Length > GetPrefix.Length && !char.IsLower(text[GetPrefix.Length]);
return HasPrefix(text, GetPrefix);
}
private static bool HasPrefix(string text, string prefix)
{
return text.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) && text.Length > prefix.Length && !char.IsLower(text[prefix.Length]);
}
private IMethodSymbol FindSetMethod(IMethodSymbol getMethod)
{
var containingType = getMethod.ContainingType;
var setMethod = containingType.GetMembers("Set" + getMethod.Name.Substring(GetPrefix.Length))
var setMethodName = "Set" + getMethod.Name.Substring(GetPrefix.Length);
var setMethod = containingType.GetMembers()
.OfType<IMethodSymbol>()
.Where(m => setMethodName.Equals(m.Name, StringComparison.OrdinalIgnoreCase))
.Where(m => IsValidSetMethod(m, getMethod))
.FirstOrDefault();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册