Skip to content

Instantly share code, notes, and snippets.

@wallymathieu
Created September 22, 2016 08:04
Show Gist options
  • Select an option

  • Save wallymathieu/7fbd57e3816f2431462a2220ce0dbceb to your computer and use it in GitHub Desktop.

Select an option

Save wallymathieu/7fbd57e3816f2431462a2220ce0dbceb to your computer and use it in GitHub Desktop.
decompose into flags
/// <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