Browse Source

Use Descendants and Linq instead of recursion

pull/3463/head
ds5678 2 months ago committed by Siegfried Pammer
parent
commit
336618c55d
  1. 15
      ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs

15
ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using ICSharpCode.Decompiler.CSharp.Syntax;
@ -392,21 +393,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -392,21 +393,9 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public override void VisitInterpolation(Interpolation interpolation)
{
// If an interpolation contains global::, we need to parenthesize the expression.
if (IsThisOrChildMemberTypeWithDoubleColon(interpolation))
if (interpolation.Descendants.Any(n => n is MemberType { IsDoubleColon: true }))
Parenthesize(interpolation.Expression);
base.VisitInterpolation(interpolation);
static bool IsThisOrChildMemberTypeWithDoubleColon(AstNode node)
{
if (node is MemberType { IsDoubleColon: true })
return true;
foreach (var child in node.Children)
{
if (IsThisOrChildMemberTypeWithDoubleColon(child))
return true;
}
return false;
}
}
// Conditional operator

Loading…
Cancel
Save