Combine two Expression Func [Answered]
I have two
Expression<Func<A,A>>
. I want to combine them into a single Expression<Func<A,A>>
that runs the output of the first through the second. How can I do that?13 Replies
Couldn't you create a new expression which is the equivalent of
(x) => b(a(x))
?I would like to combine the expressions programatically as opposed to writing the combo by hand. @thinker227
hold on
Maaaybe this?
Can't compile ahead of time that's done later in the process
This eventually becomes SQL. Needs to stay as a proper expression.
Never mind then.
This works
Testing
My case is actually A->B and B->B so I need to adapt it slightly
Okay able to run yours as is. thanks you!
Working on modifying now
@thinker227 any idea what I might being doing wrong here?
System.ArgumentException: Expression of type 'System.Collections.Generic.List`1[System.Int32]' cannot be used for parameter of type 'System.Int32'
I think you only need one param
The lambda you're expecting is a
Func<List<int>, int>
so you can't pass in a parameter of type int
Replace param
with listParam
and it should work™️Isn't the param when you call b different ?
Since B accepts an int vs A accepting a List<int>
oh, yeah
Right you have to do it in the reverse order, swap
a
and b
Okay sec testing
Got it
You are right we only need one param
$ 10
Thank you for the help!
Now I just gotta convert this to my real types haha should be ez
✅ This post has been marked as answered!