Last active
February 16, 2016 11:31
-
-
Save sphingu/1728aca323c1b4f93ea5 to your computer and use it in GitHub Desktop.
Enum Extension
This file contains 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
[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