lundi 7 décembre 2015

Strategy for detecting (via Reflection) if Enum is of type "Flags" in C#

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) * element(last -1) == 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).





Aucun commentaire:

Enregistrer un commentaire