Skip to content

Instantly share code, notes, and snippets.

@sphingu
Last active February 16, 2016 11:31
Show Gist options
  • Save sphingu/1728aca323c1b4f93ea5 to your computer and use it in GitHub Desktop.
Save sphingu/1728aca323c1b4f93ea5 to your computer and use it in GitHub Desktop.
Enum Extension
[Flags]
public enum Status
{
Success = 1<<0, //1
Fail = 1<<1, //2
Unknown = 1<<2, //4
isNotFail = Success | Unknown
}
public static bool HasFlag(this int status, int flag)
{
return (status & flag) == flag;
}
public static int SetFlag(this int flags, int flag, bool value)
{
if (value)
flags |= flag;
else
flags &= ~flag;
return flags;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment