提交 18858a39 编写于 作者: C CyrusNajmabadi

Fix issue with chained calls in Replace-Method-With-Property.

上级 3281d6b1
......@@ -598,6 +598,33 @@ void Test()
{
var y = GetFoo(out int i);
}
}");
}
[WorkItem(14327, "https://github.com/dotnet/roslyn/issues/14327")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)]
public async Task TestUpdateChainedGet1()
{
await TestAsync(
@"
public class Foo
{
public Foo()
{
Foo value = GetValue().GetValue();
}
public Foo [||]GetValue() { return this; }
}",
@"
public class Foo
{
public Foo()
{
Foo value = Value.Value;
}
public Foo Value { get { return this; } }
}");
}
}
......
......@@ -207,8 +207,17 @@ public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node)
}
}
// We use the callback form if "ReplaceNode" here because we want to see the
// invocation expression after any rewrites we already did when rewriting previous
// 'get' references.
private static Action<SyntaxEditor, InvocationExpressionSyntax, SimpleNameSyntax, SimpleNameSyntax> s_replaceGetReferenceInvocation =
(editor, invocation, nameNode, newName) => editor.ReplaceNode(invocation, invocation.Expression.ReplaceNode(nameNode, newName));
(editor, invocation, nameNode, newName) => editor.ReplaceNode(invocation, (i, g) =>
{
var currentInvocation = (InvocationExpressionSyntax)i;
var currentName = currentInvocation.Expression.GetRightmostName();
return currentInvocation.Expression.ReplaceNode(currentName, newName);
});
private static Action<SyntaxEditor, InvocationExpressionSyntax, SimpleNameSyntax, SimpleNameSyntax> s_replaceSetReferenceInvocation =
(editor, invocation, nameNode, newName) =>
......@@ -300,4 +309,4 @@ private static bool IsInvocationName(IdentifierNameSyntax nameNode, ExpressionSy
return false;
}
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册