I want to call a method like this:
signature: void Method(object a, object b, params LambdaExpression[] expressions);
call: Method(a, b, x => x.A, x => x.B)
Is it possible?
Let's assume that the type of 'x' is a constant type. For example, if x => x.A and y => y.B were Funcs, they'd be Func<TType,*>
, such that the params array always had the same type for TType
, but the return value's type *
could differ from element to element of the params array. That's why I had to choose something more generic like LambdaExpression as the type, but I don't know if that will work. I can unpack the expression within the method at runtime, but I'm having a hard time just trying to pass expressions to a method when one of their two generic type parameters differ.
It would be fine, even if I had to call it more like: Method(a, b, (Type x) => x.A, (Type x) => x.B)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…