From 30f070558f6776ab892e68982c13143e13bf54f5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 17 Jun 2026 19:05:25 +0200 Subject: [PATCH] Remove redundant AnonymousMethodExpression.HasParameterList The decompiler never emits "delegate () {}" (an explicit empty parameter list) -- it produces "delegate {}" when there are no parameters and "delegate (...) {}" when there are -- so HasParameterList always equalled Parameters.Any(). Drop the property, its backing field and the two setter calls, and read Parameters.Any() directly at the printer and the resolve-result builder. Assisted-by: Claude:claude-opus-4-8:Claude Code --- ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs | 4 +--- .../CSharp/OutputVisitor/CSharpOutputVisitor.cs | 3 ++- .../Syntax/Expressions/AnonymousMethodExpression.cs | 8 -------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 9680c50f0..41ed4ba6b 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -2428,7 +2428,6 @@ namespace ICSharpCode.Decompiler.CSharp AnonymousMethodExpression ame = new AnonymousMethodExpression(); ame.IsAsync = function.IsAsync; ame.Parameters.AddRange(MakeParameters(function.Parameters, function)); - ame.HasParameterList = ame.Parameters.Count > 0; var builder = new StatementBuilder( typeSystem, this.decompilationContext, @@ -2493,7 +2492,6 @@ namespace ICSharpCode.Decompiler.CSharp if (!isLambda && !parameterReferencingIdentifiers.Any()) { ame.Parameters.Clear(); - ame.HasParameterList = false; } Expression replacement; @@ -2530,7 +2528,7 @@ namespace ICSharpCode.Decompiler.CSharp var rr = new DecompiledLambdaResolveResult( function, delegateType, inferredReturnType, - hasParameterList: isLambda || ame.HasParameterList, + hasParameterList: isLambda || ame.Parameters.Any(), isAnonymousMethod: !isLambda, isImplicitlyTyped: ame.Parameters.Any(p => p.Type is null)); diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs index 6303f79f0..7aa2c46b9 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs @@ -561,7 +561,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor Space(); } WriteKeyword(AnonymousMethodExpression.DelegateKeyword); - if (anonymousMethodExpression.HasParameterList) + // No parameters -> "delegate {}" (omit the list); with parameters -> "delegate (...) {}". + if (anonymousMethodExpression.Parameters.Any()) { Space(policy.SpaceBeforeAnonymousMethodParentheses); WriteCommaSeparatedListInParenthesis(anonymousMethodExpression.Parameters, policy.SpaceWithinAnonymousMethodParentheses); diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs index ae9b53220..3760bc7e7 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs @@ -41,14 +41,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public bool IsAsync { get; set; } - // used to tell the difference between delegate {} and delegate () {} - bool hasParameterList; - - public bool HasParameterList { - get { return hasParameterList || Parameters.Any(); } - set { hasParameterList = value; } - } - [Slot("Roles.Parameter")] public partial AstNodeCollection Parameters { get; }