Lets say i have the enum below:
[Flags]
public enum NotifyType
{
None = 0,
Window = 1 << 0,
Sound = 1 << 1,
Flash = 1 << 2,
MobileSound = 1 << 3,
MobilePush = 1 << 4
}
Considering two enums:
var myenums = Window | Sound | Flash;
//var possibleUpdate = Window | MobilePush;
void UpdateMyEnums(NotifyType possibleUpdate)
{
//Does myenums contain all the flags in 'possibleUpdate'? If not add
//the missing flags to myenums
}
How is it possible to determine that the myenums variable does not contain the NotifyType.MobilePush value in comparison to the possibleUpdate? Do i have to test each flag in possibleUpdate against myenums?
I am using C# on .NET 4.0
if (myenums & possibleUpdate != possibleUpdate)
//not a possible update
To get the flags needed not in myenums:
NotifyType missing = (~(myenums ^ wanted) ^ wanted) & (myenums | wanted);
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