Created
September 22, 2016 08:04
-
-
Save wallymathieu/7fbd57e3816f2431462a2220ce0dbceb to your computer and use it in GitHub Desktop.
decompose into flags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Decompose a flags enum value into the individual flags. | |
| /// </summary> | |
| public static T[] DeComposeFlags<T>(Enum value) | |
| { | |
| var defaultV = default(T); | |
| return Enum.GetValues(typeof(T)) | |
| .Cast<Enum>() | |
| .Where(e=> !defaultV.Equals(e) && value.HasFlag(e)) | |
| .Cast<T>() | |
| .ToArray(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment