I have this method:
private static List<ObjectA> ListItemsToShow(IEnumerable<ObjectA> listObjectB,
string _rarity,
string _type,
string _color,
int? _quantity,
int? _sold,
string _quantitySymbol,
string _soldSymbol)
{
List<ObjectA> listToReturn = (from item in listObjectB
where _rarity == "All" || item.rarity == _rarity
where _type == "All" || item.Type.Contains(_type)
where _color == "All" || item.Color.Contains(_color)
where _quantity == null || item.NbInStock == (int)_quantity
where _sold == null || item.QtySold == (int)_sold
select item).ToList();
return listToReturn;
}
Up to now it does it job: based on a static List of objects, it returns what can be filtered from the list of original objects.
Now I want to add a dynamic parameter: the quantitySymbol and soldSymbol. Each would be one of those choices:
- >
- <
- >=
- <=
So that I may get, for example, all items which NbInStock is <, >, <= or >= than those retained in the original list. The same would apply for the QtySold property.
I have a bit of trouble figuring how I could do it in a linq statement, I'd need help to make this out.