Does any have a more elegant way of doing this?
[Flags]
public enum SomeFlaggedEnum
{
Value1 = 1,
Value2 = 2,
Value3 = 4
}
private SomeFlaggedEnum _myFlags;
public bool EnabledValue1
{
set
{
if (value)
{
_myFlags |= SomeFlaggedEnum.Value1;
}
else
{
_myFlags &= ~SomeFlaggedEnum.Value1;
}
}
}
I know there is probably a simple answer and I'm just way over thinking it...
EDIT: The enum was incorrect as pointed out in one of the answers. This was only in this example and not in the actual code.
I mean, you could do:
_myFlags = value ? myFlags | SomeFlaggedEnum.Value1 : myFlags & ~SomeFlaggedEnum.Value1;
But I think your solution is fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With