I have a List<Device>
. In the Device
class there are 4 properties, namely Name
, OperatingSystem
, Status
and LastLoggedInUser
. I need to write a method:
IQueryable<Device> FilterDeviceList(
List<Device> Devices,
List<string> filter,
string filterValue)
where filter
will contain options for filtering "name"
, "os"
to indicate the fields to include in the search. If "all"
is passed then all 4 fields need to be included.
filtervalue
will contain the value to be filtered like "windows"
, "Calvin"
.
Can anyone suggest a method to achieve this?
Edit:
If I was not clear, I am doing the filtering somewhat like this, it is the commented part for which I need the code.
if(filter.contains(name))
{
//filter with name
}
if( filter.contains(both name and os)
{
// I only need the filter value to contain in name or OS (only needed in any one of the field,not necessary to be in both)
}`
See Question&Answers more detail:os