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