From 9b0e3a16052f0fa21a5560ee243901b7e8769b6c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 20 Sep 2025 20:54:39 +0200 Subject: [PATCH] Fix folding of local functions, if "Fold all braces" is disabled. --- ICSharpCode.Decompiler/Output/TextTokenWriter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs index 4429a103b..b65dc95f4 100644 --- a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs +++ b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs @@ -22,12 +22,12 @@ using System.Linq; using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.CSharp.OutputVisitor; -using ICSharpCode.Decompiler.CSharp.Resolver; using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.IL; using ICSharpCode.Decompiler.Semantics; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem.Implementation; +using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler { @@ -255,7 +255,7 @@ namespace ICSharpCode.Decompiler } if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration) braceLevelWithinType++; - if (nodeStack.OfType().Count() <= 1 || settings.FoldBraces) + if (nodeStack.PeekOrDefault() is TypeDeclaration or BlockStatement { Parent: EntityDeclaration or LocalFunctionDeclarationStatement or AnonymousMethodExpression or LambdaExpression } || settings.FoldBraces) { output.MarkFoldStart(defaultCollapsed: !settings.ExpandMemberDefinitions && braceLevelWithinType == 1, isDefinition: braceLevelWithinType == 1); } @@ -265,7 +265,7 @@ namespace ICSharpCode.Decompiler output.Write('}'); if (role != Roles.RBrace) break; - if (nodeStack.OfType().Count() <= 1 || settings.FoldBraces) + if (nodeStack.PeekOrDefault() is TypeDeclaration or BlockStatement { Parent: EntityDeclaration or LocalFunctionDeclarationStatement or AnonymousMethodExpression or LambdaExpression } || settings.FoldBraces) output.MarkFoldEnd(); if (braceLevelWithinType >= 0) braceLevelWithinType--;