I have a small problem. This is a simplified version of my problem.
I have a class that has a list of buttons with its names (New,Edit,Delete) as well a object of type "Type"
class test
{
private List<Button> buttons; //
private Type type;
public test(Type t)
{
this.type = t;
/* some code to create the buttons from the enum.
got this already covered but "Restore" does not get created by intention*/
}
public void setButtons(int i)
{
}
}
the type is an enum with the flags attribute
[Flags] enum EnumTest{None=0, New=1, Edit=2, Delete=4, Restore=8}
What I would like to do is to have the "setButtons" method to create an instance of "type", set the value from "int i" to the flags values, go through the list of buttons and set the "Enabled" property of the button depending on if the flag is raised, where the buttons "Name" property is depending on the Flags Name in the Enum (EnumTest or any other)
I tried several stuff like
var enu = Enum.ToObject(type, i);
But I cannot set the flags, or I don't know how. I was thinking of using reflection while creating it. seems like the "ToObject" method does not play well with the flags attribute. "TryParse" seems to do, but I have no Idea how to make it load dynamically from "Type".
Please, take into consideration that this is a highly simplified version of my problem, but where it would keep the meaning.