From e1760a55d0d710402f8c31f54b540ffc95580cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Mon, 15 Oct 2012 10:24:28 +0200 Subject: [PATCH] [CodeAction] Fixed bug in create property code action. --- .../CodeActions/CreatePropertyAction.cs | 4 +++- .../CSharp/CodeActions/CreatePropertyTests.cs | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreatePropertyAction.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreatePropertyAction.cs index 2c8fa4ec9b..64f786193c 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreatePropertyAction.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreatePropertyAction.cs @@ -75,7 +75,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring } else { if (state.CurrentMember == null) yield break; - isStatic |= state.CurrentMember.IsStatic || state.CurrentTypeDefinition.IsStatic; + isStatic |= state.CurrentTypeDefinition.IsStatic; + if (targetResolveResult == null) + isStatic |= state.CurrentMember.IsStatic; } // var service = (NamingConventionService)context.GetService(typeof(NamingConventionService)); diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreatePropertyTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreatePropertyTests.cs index f1dfb1176d..21a304c73c 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreatePropertyTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreatePropertyTests.cs @@ -307,5 +307,27 @@ class Foo } "); } + + [Test()] + public void TestNonStaticPropertyInStaticMethod () + { + TestCreateProperty (@"class TestClass +{ + static void Foo () + { + new TestClass ().$NonExistantProperty = 5; + } +}", @"class TestClass +{ + int NonExistantProperty { + get; + set; + } + static void Foo () + { + new TestClass ().NonExistantProperty = 5; + } +}"); + } } } \ No newline at end of file