diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateOverloadWithoutParameterAction.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateOverloadWithoutParameterAction.cs index 9dbd124cab..6ca79fca39 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateOverloadWithoutParameterAction.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateOverloadWithoutParameterAction.cs @@ -66,15 +66,15 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring Expression argExpr; if (node.ParameterModifier == ParameterModifier.Ref) { body.Add (new VariableDeclarationStatement (node.Type.Clone (), node.Name, defaultExpr)); - argExpr = new DirectionExpression (FieldDirection.Ref, new IdentifierExpression (node.Name)); + argExpr = GetArgumentExpression (node); } else if (node.ParameterModifier == ParameterModifier.Out) { body.Add (new VariableDeclarationStatement (node.Type.Clone (), node.Name)); - argExpr = new DirectionExpression (FieldDirection.Out, new IdentifierExpression (node.Name)); + argExpr = GetArgumentExpression (node); } else { argExpr = defaultExpr; } body.Add (new InvocationExpression (new IdentifierExpression (methodDecl.Name), - methodDecl.Parameters.Select (param => param == node ? argExpr : new IdentifierExpression (param.Name)))); + methodDecl.Parameters.Select (param => param == node ? argExpr : GetArgumentExpression(param)))); var decl = (MethodDeclaration)methodDecl.Clone (); decl.Parameters.Remove (decl.Parameters.First (param => param.Name == node.Name)); @@ -87,6 +87,18 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring }); } + static Expression GetArgumentExpression(ParameterDeclaration parameter) + { + var identifierExpr = new IdentifierExpression(parameter.Name); + switch (parameter.ParameterModifier) { + case ParameterModifier.Out: + return new DirectionExpression (FieldDirection.Out, identifierExpr); + case ParameterModifier.Ref: + return new DirectionExpression (FieldDirection.Ref, identifierExpr); + } + return identifierExpr; + } + static Expression GetDefaultValueExpression (RefactoringContext context, AstType astType) { var type = context.ResolveType (astType); diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateOverloadWithoutParameterTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateOverloadWithoutParameterTests.cs index e1286790e2..ff23a3435b 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateOverloadWithoutParameterTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateOverloadWithoutParameterTests.cs @@ -203,6 +203,29 @@ class Test : ITest void ITest.Test (int a, int $b) { } +}"); + } + + [Test] + public void TestGenereatedCall () + { + Test ( + @"class Test +{ + void TestMethod (ref int $i, ref int j, out int k) + { + } +}", + @"class Test +{ + void TestMethod (ref int j, out int k) + { + int i = 0; + TestMethod (ref i, ref j, out k); + } + void TestMethod (ref int i, ref int j, out int k) + { + } }"); } }