I'm using Reflection to read types inside an assembly (to generate code). I can see that some enumerations should have been marked with the [Flags]
attribute but whoever wrote those enums forgot to add this attribute.
Is there any reliable way of detecting when an enum can be considered a "Flags" enum?
My strategy at the moment is to read the enum in descending order, and checking if the value of element(last -1) * 2 == element(last).
That works great in most cases, except when I have enums with 0, 1, and 2 values (which could be flags or not).
edit:
Example of an enum that I'd like to detect as being flags:
public enum EnumIsFlag1
{
ItemA = 2,
ItemB = 4,
ItemC = ItemA + ItemB,
ItemD = 32,
ItemE = 64,
}
edit: My question is not a duplicate... The moderator clearly didn't read my question