Say I have a method called GetCatsByColor which takes a color as a string, a method GetCatsByName which takes a name as a string, and GetCatsByBirthDate which takes two DateTimes acting as a range of time.
Now say I have a CatFilter class which holds a List of names, List of colors, and two DateTimes, representing the “from” date and the “to” date of a timespan. What I am trying to do is create a GetFilteredCats method that takes one of these Filter objects and returns a collection of Cats that meet the specifications of the given Filter.
I’m having a hard time coming up with an efficient way of getting the desired results, ideally using LINQ/lambda expressions.
What is the best way to go about doing this sort of join? What extension methods should I be looking at? Modifying a collection in a foreach loop generally isn’t advisable/possible, so what should my strategy be?
What i normally do is to put a check in the where clause which checks if the filter is needed before doing the actual filter. When the runtime needs to evaluate the filter, it is skipped entirely if it isn’t needed.
And then calling it like this