diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 8edfbe4da..3f514ba73 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -2791,17 +2791,19 @@ namespace ICSharpCode.Decompiler.CSharp // needs to be consistent with logic in ILReader.CreateILVariable pd.Name = "P_" + i; } + if (settings.AnonymousTypes && parameter.Type.ContainsAnonymousType()) anyAnonymousType = true; + result.Add(pd); i++; } + // An anonymous type cannot be named, so a lambda with such a parameter must be implicitly typed. // C# also requires all lambda parameters to use the same form (CS0748). Drop every type when the // remaining parameter syntax permits it; otherwise keep the converted declarations as a // best-effort fallback for an unrepresentable signature. - if (anyAnonymousType && result.All(p => p.ParameterModifier == ReferenceKind.None - && !p.IsParams && !p.IsScopedRef && p.Attributes.Count == 0 && p.DefaultExpression is null)) + if (anyAnonymousType && result.All(p => p is { ParameterModifier: ReferenceKind.None, IsParams: false, IsScopedRef: false, Attributes.Count: 0, DefaultExpression: null })) { foreach (var pd in result) pd.Type = null;