I was searching SO, but simply could not get the result for this (I was probably using incorrect keywords).
I have these multiple simple Linq expression:
var items = ErrorList.Where(n => n.CompanyID == SelectedItem.CompanyID);
var items = ErrorList.Where(n => n.CompanyID == SelectedItem.CompanyID && n.TaxCode == SelectedItem.TaxCode);
and so on (more conditions are added to this linq statement).
Instead of current method (using multiple if statements) I want to be able to specify my Function once and retrieve items based on specified criteria. I have not done this before, but I believe it should be something like this?
private System.Collections.IEnumerable Result(Func<>)
...I don't know how to continue
P.S. I don't need to create separate IEnumerable, if there is a way how to specify your function in advance? e.g.
switch (sCase)
{
case 1:
sResult = (n => n.CompanyID == SelectedItem.CompanyID);
break;
case 2:
sResult = (n => n.CompanyID == SelectedItem.CompanyID && n.TaxCode == SelectedItem.TaxCode);
break;
}
var items = ErrorList.Where(sResult);