提交 aa2dd71f 编写于 作者: D Dustin Campbell

Simplification should remove parentheses around the expression of an expression-bodied member

上级 8caf6101
......@@ -1185,6 +1185,58 @@ class Program
int i = (x?.Count).GetValueOrDefault();
}
}
</code>
Await TestAsync(input, expected)
End Function
<WorkItem(12600, "https://github.com/dotnet/roslyn/issues/12600")>
<Fact, Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestCSharp_RemoveParensInExpressionBodiedProperty() As Task
Dim input =
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class C
{
object Value => {|Simplify:(new object())|};
}
</Document>
</Project>
</Workspace>
Dim expected =
<code>
class C
{
object Value => new object();
}
</code>
Await TestAsync(input, expected)
End Function
<WorkItem(12600, "https://github.com/dotnet/roslyn/issues/12600")>
<Fact, Trait(Traits.Feature, Traits.Features.Simplification)>
Public Async Function TestCSharp_RemoveParensInExpressionBodiedMethod() As Task
Dim input =
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class C
{
object GetValue() => {|Simplify:(new object())|};
}
</Document>
</Project>
</Workspace>
Dim expected =
<code>
class C
{
object GetValue() => new object();
}
</code>
Await TestAsync(input, expected)
......
......@@ -29,6 +29,12 @@ public static bool CanRemoveParentheses(this ParenthesizedExpressionSyntax node,
return true;
}
// int Prop => (x); -> int Prop => x;
if (node.Parent is ArrowExpressionClauseSyntax arrowExpressionClause && arrowExpressionClause.Expression == node)
{
return true;
}
// Don't change (x?.Count).GetValueOrDefault() to x?.Count.GetValueOrDefault()
if (expression.IsKind(SyntaxKind.ConditionalAccessExpression) && parentExpression is MemberAccessExpressionSyntax)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册