提交 db95b5a2 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #16213 from CyrusNajmabadi/convertPropIssue

Fix issue with 'Convert Prop to Method' with member bindings.
Fixes #16157
......@@ -966,7 +966,7 @@ public void SetProp1(object value)
public abstract void SetProp(dynamic i);
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)]
public async Task TestTrivia1()
{
......@@ -1140,7 +1140,39 @@ void M()
{
SetProp(GetProp() * (GetProp() + 1));
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)]
[WorkItem(16157, "https://github.com/dotnet/roslyn/issues/16157")]
public async Task TestWithConditionalBinding1()
{
await TestAsync(
@"public class Foo
{
public bool [||]Any { get; } // Replace 'Any' with method
public static void Bar()
{
var foo = new Foo();
bool f = foo?.Any == true;
}
}",
@"public class Foo
{
private readonly bool any;
public bool GetAny()
{
return any;
}
public static void Bar()
{
var foo = new Foo();
bool f = foo?.GetAny() == true;
}
}");
}
}
}
}
\ No newline at end of file
......@@ -3552,23 +3552,24 @@ internal override SyntaxNode MemberBindingExpression(SyntaxNode name)
internal override SyntaxNode ElementBindingExpression(SyntaxNode argumentList)
=> SyntaxFactory.ElementBindingExpression((BracketedArgumentListSyntax)argumentList);
// parenthesize the left hand size of a member access, invocation or element access expression
/// <summary>
/// Parenthesize the left hand size of a member access, invocation or element access expression
/// </summary>
private ExpressionSyntax ParenthesizeLeft(ExpressionSyntax expression)
{
if (expression is TypeSyntax
|| expression.IsKind(SyntaxKind.ThisExpression)
|| expression.IsKind(SyntaxKind.BaseExpression)
|| expression.IsKind(SyntaxKind.ParenthesizedExpression)
|| expression.IsKind(SyntaxKind.SimpleMemberAccessExpression)
|| expression.IsKind(SyntaxKind.InvocationExpression)
|| expression.IsKind(SyntaxKind.ElementAccessExpression))
if (expression is TypeSyntax ||
expression.IsKind(SyntaxKind.ThisExpression) ||
expression.IsKind(SyntaxKind.BaseExpression) ||
expression.IsKind(SyntaxKind.ParenthesizedExpression) ||
expression.IsKind(SyntaxKind.SimpleMemberAccessExpression) ||
expression.IsKind(SyntaxKind.InvocationExpression) ||
expression.IsKind(SyntaxKind.ElementAccessExpression) ||
expression.IsKind(SyntaxKind.MemberBindingExpression))
{
return expression;
}
else
{
return this.Parenthesize(expression);
}
return this.Parenthesize(expression);
}
private SeparatedSyntaxList<ExpressionSyntax> AsExpressionList(IEnumerable<SyntaxNode> expressions)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册