From 73a28011ed0c05317d1ffa240389a166123d407b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Nov 2015 15:06:21 -0500 Subject: [PATCH] Allow the 'replace method with property' refactoring to work with get/set methods, not just Get/Set methods. --- .../ReplaceMethodWithPropertyTests.cs | 9 +++++++++ ...ReplaceMethodWithPropertyCodeRefactoringProvider.cs | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs index 7e1c3ed6bac24..94e4e9564b9bd 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs @@ -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); } } diff --git a/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs b/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs index b5ec421eb48f3..ff81eb4d16a97 100644 --- a/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ReplaceMethodWithProperty/ReplaceMethodWithPropertyCodeRefactoringProvider.cs @@ -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() + .Where(m => setMethodName.Equals(m.Name, StringComparison.OrdinalIgnoreCase)) .Where(m => IsValidSetMethod(m, getMethod)) .FirstOrDefault();