Extract input parameter name from lambda expression

dynamic-linq expression-trees linq linq-to-nhibernate

Question

I'm using nhibernate linq and system.linq.dynamic.core. I now wish to call a method with two dynamic Linq expressions. One for a linked kid list and one for the parent table. Both expressions' input parameters are randomly chosen, hence an expression might be

"x = Wick when x.Name == "Wick" "

Or

The statement "k => k.FirstName = "John""

I now know that string expressions can be converted to LambdaExpressions using dynamic linq.

There must be an alias for the connected table if I want to establish a join. I want to take the "x" or the "k" out of the phrase. Can this be done?

1
1
11/13/2017 7:11:30 PM

Accepted Answer

LambdaExpression has a Parameters property, which you can use to obtain details on the characteristics of lambda. That in your situation could resemble:

string GetParameterName(LambdaExpression expression) => expression.Parameters.Single().Name;
4
11/13/2017 7:34:13 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow