Use pattern expression instead

This commit is contained in:
Sebastien Lebreton
2026-08-16 08:38:07 +02:00
committed by Daniel Grunwald
parent b1e5163873
commit e7bed9c78e
@@ -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;