From c6e37529771dc55d29d26c8a9026bbf0f911ff03 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 6 Oct 2024 22:25:10 +0200 Subject: [PATCH] Fix #3089: Add comment regarding .constraint prefix expressed as cast in C# --- .../TestCases/Pretty/ConstructorInitializers.cs | 4 ++++ ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs index 5b08837a0..7e8650ff6 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs @@ -60,7 +60,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public class MethodCallInCtorInit { public MethodCallInCtorInit(ConsoleKey key) +#if MCS5 + : this(((int)key/*cast due to .constrained prefix*/).ToString()) +#else : this(((int)key).ToString()) +#endif { } diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index 56f420e07..fb46b12ea 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -507,6 +507,10 @@ namespace ICSharpCode.Decompiler.CSharp targetExpr = new MemberReferenceExpression(castExpression, methodName); typeArgumentList = ((MemberReferenceExpression)targetExpr).TypeArguments; } + if (constrainedTo != null && targetExpr is MemberReferenceExpression { Target: CastExpression cast }) + { + cast.AddChild(new Comment("cast due to .constrained prefix", CommentType.MultiLine), Roles.Comment); + } } else {