hazzik / DelegateDecompiler

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

Only last simple assignment gets decompiled in `x => {x.Val1 = 1; x.Val2 = 2;}` #122

Closed mycroes closed 2 years ago

mycroes commented 6 years ago

This is somewhat of a followup to #117. Support for simple assignments was added to 0.24.0, unfortunately it only works for the last assignment. The following sample results in the decompiled expression d => (d.Val2 = 2).

public class AssignmentTest
{
    public static void Test()
    {
        Set<Data>(d =>
        {
            d.Val1 = 1;
            d.Val2 = 2;
        });
    }

    public class Data
    {
        public int Val1 { get; set; }
        public int Val2 { get; set; }
    }

    public static void Set<T>(Action<T> setter)
    {
        var d = setter.Decompile();
    }
}

I would expect this to generate a BlockExpression with two assignments, not sure if that's anything already in DelegateDecompiler that supports this. Would be willing to dive into this issue myself.

magicmoux commented 6 years ago

Hi @mycroes,

may I ask you what you want to achieve here, and what do you expect or need DelegateDecompiler for ?(not meaning to be offensive)

To get to the point, I just stumbled across DD to work around third-parties' caveats (not naming EF) and I think I've found some outstanding ground here (all my POCs being verified, in my humble perspective, of course) because I needed to apply complex dynamic-shares/multitenant business-logic in my DbContext queries without resorting to translate all clauses into ugly lambdas - been there done that - when native .NET implementations and in-memory LinqProvider do the job.

As far as I see, DD is a great library to get as QueryDSLProvider-agnostic as possible in the (lin)Query-ing area but it won't ever be able to address any underlying provider's intrinsic procedural limitations.

I think that if we want DD to have any real value or usefulness, we need to decide what querying using different providers really means.

@hazzik, any opinion/insight about this ?

Best regards, Max

hazzik commented 6 years ago

@magicmoux the DD was also used in (i think now dead/dormant) KnockoutMVC. It can be useful there. But I'm not sure if it does support assignments.

mycroes commented 6 years ago

I want to use DelegateDecompiler to decompile state update Actions. It's not related to database access in any way. To be more specific, I'd want to use it as part of our emulator infrastructure where PLC state is simulated.

magicmoux commented 5 years ago

Since I'm lately following the somewhat same track as you were last year, I had a look back on this issue.

@mycroes, I seem to have lately solved the problem based on your proposal (had to start from scratch). You can review my changes at : https://github.com/magicmoux/DelegateDecompiler/commit/f5173f8330e1869cd9ca019bce5c8651798a4b83 please tell me if any of your tests goes awry. Currently it satisfy mines/

@hazzik, tell me whether this solution acceptable so I can submit a PR

Best regards, Max.

mycroes commented 5 years ago

Hi @magicmoux,

I'm a bit time-constrained at the moment, not sure when I'll be able to test. The case I've detailed in the issue is about as complicated as it gets for me, perhaps with nested paths to properties in worst case, so if that works it should be good enough for me. Thanks for your effort.

Regards, Michael

magicmoux commented 5 years ago

Hi Michael, no problem.

I had at last (since January) some free time to define my needs and to work on this issue, so I totally understand.

I'm still working about it toward completion

Regards, Max

hazzik commented 2 years ago

This has been released in 0.31.0. Please consider ❤️ supporting the project.