From 336618c55d8586a737b5c417c6e183c3a60a9769 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sat, 26 Apr 2025 23:06:14 -0700 Subject: [PATCH] Use Descendants and Linq instead of recursion --- .../OutputVisitor/InsertParenthesesVisitor.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs index 2c67b55a5..4d3f2143d 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs @@ -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 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