Given a Type T and a list of strings that are propertynames in T like {"prop1", "prop2"}
I would like to generate an expression like below that is a dynamic object:
Expression<Func<T, object>> in the format: x => new {x.prop1, x.prop2}
I am able to create a single property accessor, but cant figure out the dynamic type for the expression.
private Func<T, int> BuildChildSelectorLambda(string idPropertyName) {
ParameterExpression argParam = Expression.Parameter(typeof(T), "x");
Expression selector = Expression.Property(argParam, typeof(T).GetProperty(idPropertyName));
return Expression.Lambda<Func<T,int>>(selector, argParam).Compile();
//TODO: CACHE EXPRESSIONS
}