Related Topics:
Create Expression<Func<T, TKey>>
dynamically
I searched on the internet but all samples explain Expression<Func<
. How I can dynamically create a Func<T, TKey>
from T
?
Thanks
Edit 1)
The T
type in my code determine in runtime and for example I want to sort my list with Name
. Now How I can create this : Func<T, TKey> = o=>o.Name;
Edit 2)
Please consider this:
public abstract class MyClass<T> where T : class
{
public virtual List<T> GetAll(Expression<Func<T, bool>> exp, string orderByProperty)
{
repository.Get(exp).OrderBy(?);
}
}
The problem is create a Func<T, TKey>
for using in OrderBy
argument. How can I sort the list using Name
property?
Thanks