Skip to content

Instantly share code, notes, and snippets.

@rpbeukes
Created June 23, 2022 04:40
Show Gist options
  • Save rpbeukes/da3366089df03be3d1d2f269ab82519e to your computer and use it in GitHub Desktop.
Save rpbeukes/da3366089df03be3d1d2f269ab82519e to your computer and use it in GitHub Desktop.
Foreach over an Enum value
public class Enum<EnumT> where EnumT : Enum
{
public static void ForEach(Action<EnumT> action)
{
foreach (EnumT status in Enum.GetValues(typeof(EnumT)))
action(status);
}
}
@rpbeukes
Copy link
Author

Useage

Enum<TransactionStatus>.ForEach((status) =>
{

          if (status == TransactionStatus.InProgress) 
          { /* do stuff*/ }

       // do more stuff
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment