G
Guest
Let's say I have an Enum:
[Flags]
public enum DaysOfTheWeek : short
{
Sunday = 0x1,
Monday = 0x2,
Tuesday = 0x4,
Wednesday = 0x8,
Thursday = 0x10,
Friday = 0x20,
Saturday = 0x40
}
and I want to create two functions:
public bool ContainsDayGet(int DayFromSundayZero)
public bool ContainsDaySet(int DayFromSundayZero, bool NewValue)
one will test the appropriate bit and return true if that bit is set (false
otherwise). The other will set the appropriate bit.
I want to figure out a way to do this in a more generic way by looking into
the way the enum was defined at runtime instead of having to write a
switch-case for each of the potential options. I guess this means that I want
to "index" my way into an enum. Can one do that?
Any help on the construction of these two functions in a generaic sense
would be most helpful.
Thanks.
Alex Maghen
[Flags]
public enum DaysOfTheWeek : short
{
Sunday = 0x1,
Monday = 0x2,
Tuesday = 0x4,
Wednesday = 0x8,
Thursday = 0x10,
Friday = 0x20,
Saturday = 0x40
}
and I want to create two functions:
public bool ContainsDayGet(int DayFromSundayZero)
public bool ContainsDaySet(int DayFromSundayZero, bool NewValue)
one will test the appropriate bit and return true if that bit is set (false
otherwise). The other will set the appropriate bit.
I want to figure out a way to do this in a more generic way by looking into
the way the enum was defined at runtime instead of having to write a
switch-case for each of the potential options. I guess this means that I want
to "index" my way into an enum. Can one do that?
Any help on the construction of these two functions in a generaic sense
would be most helpful.
Thanks.
Alex Maghen