This kills me because I feel like I saw something around before, but my searches are empty, and I don’t have different patterns that have been stored in memory (for now).
Situation
I have a search grid that allows users to filter based on multiple attributes. Filters that users would like to receive are passed through NameValueCollectionand parsed.
Currently, our legacy application checks each potential filter in a separate if statement, and then runs its own code. And since cyclomatic complexity is simply not mine, 30 almost identical ifstatements torment me.
On the way to the best
Instead of continuing to check each element in a hard-coded way, I rewrote the parser so that now I can quickly get a list of all the filters that will be applied. I will also reorganize the filters myself into my classes.
So, I have a list of filters in string form ("Name", "BirthDate", etc.) and a set of classes ( NameFilter, BirthDateFilteretc.)
Question
What is a good standard way to take a list of strings representing filter names and turn them into a list of filter objects themselves?
I suppose I could do something like this FilterLocatorusing a method LocateFilter(string filterName), but it looks like this will result in one long switch statement and looks like blech.
I understand that this is aimed at some kind of IoC / DI solution, but I do not know enough about how to fully implement it.
!