DelegateDecompiler icon indicating copy to clipboard operation
DelegateDecompiler copied to clipboard

Assignment expression not converted properly

Open Bretttt opened this issue 9 months ago • 1 comments

class MyClass
{
    public string MyProperty {get; set;}
}

Func<MyClass, string> func = v => v.MyProperty = "I wish to assign this value";
LambdaExpression decompiled = DecompileExtensions.Decompile(func);

Expected body: Binary expression (node type Assign) with Left = {v.MyProperty}, Right = Constant("I wish to assign this value")

Actual body:

Block expression containing two expressions:

  1. Binary expression (node type Assign) with Left = {v.MyProperty}, Right = Constant("I wish to assign this value")
  2. constant("I wish to assign this value")

Bretttt avatar Mar 21 '25 17:03 Bretttt

The decompiled expression is correct, but not optimal. There is no canonical way to write Func<MyClass, string> func = v => v.MyProperty = "I wish to assign this value"; as an expression, unfortunately, because it is not permitted by the language.

I would say that this would fall into optimization.

hazzik avatar Aug 04 '25 03:08 hazzik