c# - Determining which flags are missing from enum -
lets have enum below:
[flags] public enum notifytype { none = 0, window = 1 << 0, sound = 1 << 1, flash = 1 << 2, mobilesound = 1 << 3, mobilepush = 1 << 4 } considering 2 enums:
var myenums = window | sound | flash; //var possibleupdate = window | mobilepush; void updatemyenums(notifytype possibleupdate) { //does myenums contain flags in 'possibleupdate'? if not add //the missing flags myenums } how possible determine myenums variable not contain notifytype.mobilepush value in comparison possibleupdate? have test each flag in possibleupdate against myenums?
i using c# on .net 4.0
there no need figure out 1 missing, need bit-wise or between myenums , possibleupdate , assign value back.
//does myenums contain flags in 'possibleupdate'? if (myenums & possibleupdate != possibleupdate) //if not add missing flags myenums myenums = myenums | possibleupdate;
Comments
Post a Comment