hazzik / DelegateDecompiler

A library which is able to decompile a delegate or a method body to its lambda representation
MIT License
522 stars 62 forks source link

Decompiler does not remove transparent identifier expression on root level #167

Closed aradalvand closed 3 years ago

aradalvand commented 3 years ago

Hi again! I'm encountering another bug. I'm trying to decompile this method:

public static CommentDto ToCommentDto(this Comment comment)
{
    return new CommentDto
    {
        IsUserPurchaser = comment.Course.PurchaseItems.Any(pi => pi.Purchase.UserId == comment.UserId && pi.Purchase.IsFinalized),
    };
}

But surprisingly DelegateDecompiler gives me this:

comment => new CommentDto()
{
    IsUserPurchaser = new { comment = comment }.comment.Course.PurchaseItems.Any(pi => ((pi.Purchase.UserId == comment.UserId) && pi.Purchase.IsFinalized))
};

It's strange! Where is new { comment = comment } even coming from?!

hazzik commented 3 years ago

Where is new { comment = comment } even coming from?!

It is from the closure. Need a visitor to unwrap such closures.

hazzik commented 3 years ago

Should be fixed in 0.29.0