views:

40

answers:

1

I have a webpage that is a Search page. There are a few pre-defined searches that need to be in place. The method I have taken to handle this, along with normal searches, is to have the QueryString force the search. There is a search querystring, currently about 10 or so different "searches".

I then have a ProcessSearch method with a switch it in the setup and perform each search:

    switch (QueryString)
    {
        case "person":
            SearchPerson();
            break;

        case "firstname":
            firstNameText = inputtedValue;
            SearchPerson();
            break;
        .
        .
        .
    }

You get the idea, I hope. Is there a better way to do this. Just seems like I might be missing a simplier, easier to read solution.

One last edit:

Does making the strings Enums buy me anything?

+1  A: 

This seems like a solid, readable solution to your problem. There are other ways to do it but I think what you have is fine.

Andrew Hare
What are the other ways? Just curious.
Martin
Switch statements like this can often be refactored into a Dictionary<String,Delegate> if there are many of them. Without knowing more of your application it is difficult to say if this would be a good idea :)
Andrew Hare