... and I have no idea what to do here.
Well, sorry.
What do you have? A List<ReportSort> is called sorts .
What you need? Action<Whatever> .
You have already taken the first step: you have created a method that takes what you have and returns what you need. Great first step.
Action<DataSourceSortDescriptorFactory<TModel>> expression;
And you caused that you do not know how to do it. This is a good technique.
Start by filling in what compiles but does not work properly.
Action<DataSourceSortDescriptorFactory<TModel>> expression = sort => { sort.Add("LastName").Ascending(); sort.Add("FirstName").Ascending(); }; return expression;
Fine. Now you have a compilation program, which means that you can run your tests and verify that if this case is expected, the test will pass, and if something else is expected, the test will fail.
Now think what I got? I have a list of things and I am doing Action . This means that there is a side effect, possibly involving each item in the list. So there is foreach somewhere:
Action<DataSourceSortDescriptorFactory<TModel>> expression = sort => { sort.Add("LastName").Ascending(); sort.Add("FirstName").Ascending(); foreach(var sort in sorts) {
Compile it. It fails. Ah, we confuse the sort that we add to the new view that we add. Fix the problem.
Action<DataSourceSortDescriptorFactory<TModel>> expression = existingSort => { existingSort.Add("LastName").Ascending(); existingSort.Add("FirstName").Ascending(); foreach(var newSort in sorts) {
Great, now we can compile and run the tests again.
The pattern here should be clear. Keep it compiled, continue to run tests, gradually make your program more correct, discussing the actions that you can perform on the values ββthat you have.
Can you finish it?