How to pass Type dynamically to TKey in a method in c#?

116 Points
5 Posts

I have following generic method sygnature:

public Result<MyAction> Search<TKey>(PageRequest request, Expression<Func<MyAction, bool>> whereExpression = null, Expression<Func<MyAction, TKey>> orderBy = null, bool isAsc = true)

Here I'm facing challenge to pass TKey during sorting as:

//sorting with datetime type
var myAction = _applicationUnitOfWork.MyAction.Search<DateTime>(pageRequest, filter, s => s.FromDate, isAsc);

//sorting with int type
var myAction = _applicationUnitOfWork.MyAction.Search<int>(pageRequest, filter, s =>, isAsc);

//sorting with string type
var myAction = _applicationUnitOfWork.MyAction.Search<string>(pageRequest, filter, s =>, isAsc);

Here in above, I'm passing TKey on the basis of type of sorting field. Is there any way to pass it dynamically?

Views: 106
Total Answered: 0
Total Marked As Answer: 0
Posted On: 30-Oct-2023 01:49

Share:   fb twitter linkedin
 Log In to Chat