Add Enum method to remove not defined flags. #18190
Labels
api-needs-work
API needs work before it is approved, it is NOT ready for implementation
area-System.Runtime
design-discussion
Ongoing discussion about design without consensus
Milestone
Suppose I have an enum type defined by
FlagsAttribute
and has an enum value that is outside the limit of the enum type. I then want to hace a way to easily remove the flags that are not defined.This can be useful if I eg get an enum value from an external API, and all the flags are not defined in the internal enum type. I would then want clear the unsupported flags.
Alternative solution proposals:
Alternative 1
If you set the the new boolena value to
true
, unknown flags is removed. This should only be valid for enum types that are defined withFlagsAttribute
, or else the function throw a exception. (By the way, why are notToObject
generic to avoid having to cast like #14083 ?)Alternative 2
It returns a bit mask that can be used like this:
var cleanedEnumValue = myEnumValue & myEnumValue.BitMask;
Alternative 3
It returns a enum where the undefined flags have been masked away. Or if the enum is not defined with
FlagsAttribute
, it throw a exception.The text was updated successfully, but these errors were encountered: