I'm plan to make a page that displays info about user's in the form of a table. Each column will be a property of the table. I want someone viewing the table to be able to choose ways to filter the users. There will be two check boxes: 1 for reported users and 1 for creation date. I'm planning to make an enum called UserFilter like so:
public enum UserFilter
{
None = 0,
Date = 1,
Reported = 2
}
If I need to add another type it's value will be set to 4 so that I can tell which enums are selected through a bitwise or (3 would be both 1 and 2). The problem I'm having is with reading in an enum from the query string. I guess I could do something like posting back with an int (0 for none, 1 for date, 2 for report, 3 for both) but I would like to try posting back with the actual string. I'm not sure how I would parse "Date|Reported" into an enum value that doesn't exist in UserFilter.
In a nutshell: Is there a clean way to parse "Date|Reported" into the value 3 without adding another value to my enum?
You could try something like
I would however recomend that you change your enum to
as if you have it your way
None|Date
is the same asDate
, because0 + 1 => 1
EDIT
As @ScottSelby stated, this would also work