diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs index e794d4c805..3378d6411a 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs @@ -195,11 +195,25 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring if (state != null && (state.CurrentMember.ReturnType is ParameterizedType)) { var pt = (ParameterizedType)state.CurrentMember.ReturnType; if (pt.FullName == "System.Collections.Generic.IEnumerable") { - return new [] { pt.TypeArguments.First () }; + return new [] { pt.TypeArguments.First() }; } } } + if (expr.Parent is UnaryOperatorExpression) { + var uop = (UnaryOperatorExpression)expr.Parent; + switch (uop.Operator) { + case UnaryOperatorType.Not: + return new [] { context.Compilation.FindType(KnownTypeCode.Boolean) }; + case UnaryOperatorType.Minus: + case UnaryOperatorType.Plus: + case UnaryOperatorType.Increment: + case UnaryOperatorType.Decrement: + case UnaryOperatorType.PostIncrement: + case UnaryOperatorType.PostDecrement: + return new [] { context.Compilation.FindType(KnownTypeCode.Int32) }; + } + } return Enumerable.Empty(); } static readonly IType[] emptyTypes = new IType[0]; diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs index a2684c764b..b928a304e4 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs @@ -200,20 +200,41 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions [Test()] - public void TestWrongContext1 () + public void TestWrongContext1() { // May be syntactically possible, but very unlikely. - TestWrongContext ( + TestWrongContext( "using System;" + Environment.NewLine + - "class TestClass" + Environment.NewLine + - "{" + Environment.NewLine + - " void Test ()" + Environment.NewLine + - " {" + Environment.NewLine + - " $foo();" + Environment.NewLine + - " }" + Environment.NewLine + - "}" + "class TestClass" + Environment.NewLine + + "{" + Environment.NewLine + + " void Test ()" + Environment.NewLine + + " {" + Environment.NewLine + + " $foo();" + Environment.NewLine + + " }" + Environment.NewLine + + "}" ); } + [Test()] + public void TestBool() + { + Test( +@"class TestClass +{ + void Test () + { + object o = !$foo; + } +}", +@"class TestClass +{ + void Test () + { + bool foo; + object o = !foo; + } +}"); + } + } } \ No newline at end of file