I have the following enum
[Flags]
public enum WeekDays
{
Monday = 1,
Tuesday = 2,
Wednesday = 4,
Thursday = 8,
Friday = 16,
Saturday = 32,
Sunday = 64
}
In the UI, user can select ceratain days: Monday, Tuesday, Wednesday for example. The user selection of Monday, Tuesday, Wednesday is 7. This values is saved in the databse in a column called Days.
Now if I have a class:
public class Week
{
public bool Monday { get; set; }
public bool Tuesday { get; set; }
public bool Wednesday { get; set; }
public bool Thursday { get; set; }
public bool Friday { get; set; }
public bool Saturday { get; set; }
public bool Sunday { get; set; }
}
How can I bind that value 7 and make the appropriate properties true or false. Example: 7 is equivalent for Monday, Tuesday, Wednesday enum. If I convert the value 7 to my class Week, the result will be properties: Monday, Tuesday, Wednesday are true, and the rest false.
If instead I have a class week where properties: Monday, Tuesday, Wednesday are true, and convert that into an enum WeekDays the result will be 7.
How can I do that?