I have some items in database. Each of'em can have many tags, like Browsable, or IsInMenu and so on. A friend of mine suggested to use enums with Flags attribute to create an extensible solution. So, I created a field in DB which takes an integer value, then I created this enum:
[Flags]
public enum ItemTags { Browsable = 2, IsInMenu = 4}
Now I'd like to be able to semantically get the list of some items this way:
public List<Item> GetItems(ItemTags tags)
{
/*
Code to get data from DB, something like,
return repository.GetList(tags);
*/
}
and in UI, I'd like to call:
List<Item> items = GetItems(ItemTags.Browsable | ItemTags.IsInMneu);
But I don't get the desired result. Am I going the right way?
By desired result, I mean this:
Values stored in database could be one of the 0, 2, 4, 6 values now. 0 means that the item is not in Menu and also not Browsable. 2 Means that item is Browable, but not in Menu. 4 means item is in Menu, but not Browsable. 6 means item is both Browsable and IsInMenu. Now when I call GetItems
function, I don't get all the items which are browsable, in menu, or both browsable and in menu.