This is what I am trying to accomplish:
public static Expression<Func<object, object>>[] Expressions()
=> new Expression<Func<object, object>>[]
{
(Type1 t1) => t1.t1Field,
(Type2 t2) => t2.t2Field,
...
(TypeN tN) => tN.tNField
};
The compiler does not like the Type[i] part: Cannot convert lambda expression to delegate type 'Expression<Func<object, object>>' because the parameter types do not match the delegate parameter.
I have tried using dynamic instead of object, but it didn't work.
I have also tried to achieve something like this, without success:
public static Expression<Func<object, object>> Cast<T>(Expression<Func<T, object>> expression)
Delegate? Relying on the statically typedFunc<T, T1, ...>assumes you know those types at compile-time. What you seem to want is providing the corect types at runtime. Apart from this even if you could store different expressions into a single list, how would you compile them and call the appropriate delegate? They´re just of typeFunc<object, object>which would allow to pass an instance ofType2to the first element as well.memberExpr.ToString(). I am not experienced enough to know if this could work with delegates.