diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs index a184131d35..7e23cea1a8 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs @@ -129,11 +129,6 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring return newVariableDeclarationStatement; } - List scopeContainers = new List() { - typeof (MethodDeclaration), - typeof (Accessor) - }; - AstNode FindCurrentScopeEntryNode(Statement startNode) { // Start one node up in the tree, otherwise we may stop at the BlockStatement @@ -143,9 +138,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring do { lastNode = currentNode; currentNode = currentNode.Parent; - if (scopeContainers.Contains(currentNode.GetType())) + if (currentNode == null) return null; - } while (currentNode.GetType() != typeof(BlockStatement)); + } while (!(currentNode is BlockStatement)); return lastNode; } #endregion diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs index fcfe2d9ed0..a43fa33cfe 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs @@ -136,6 +136,19 @@ class A }); "); } + + [Test] + public void IgnoresDeclarationDirectlyInConstructorBody() + { + TestWrongContext(@" +class A +{ + public A() + { + int $i = 2; + } +}"); + } } }