Skip to content

Commit

Permalink
Fix #3089: Add comment regarding .constraint prefix expressed as cast…
Browse files Browse the repository at this point in the history
… in C#
  • Loading branch information
siegfriedpammer committed Oct 6, 2024
1 parent 90946ae commit c6e3752
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ static ClassWithConstantAndStaticCtor()
public class MethodCallInCtorInit
{
public MethodCallInCtorInit(ConsoleKey key)
#if MCS5
: this(((int)key/*cast due to .constrained prefix*/).ToString())
#else
: this(((int)key).ToString())
#endif
{
}

Expand Down
4 changes: 4 additions & 0 deletions ICSharpCode.Decompiler/CSharp/CallBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ public ExpressionWithResolveResult Build(OpCode callOpCode, IMethod method,
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
{
Expand Down

0 comments on commit c6e3752

Please sign in to comment.