2020-07-28 13:59:24 +00:00
|
|
|
|
namespace QSB.Utility
|
2020-07-27 23:13:43 +00:00
|
|
|
|
{
|
|
|
|
|
// Stolen from here : https://stackoverflow.com/questions/3261451/using-a-bitmask-in-c-sharp
|
|
|
|
|
|
|
|
|
|
public static class FlagsHelper
|
|
|
|
|
{
|
|
|
|
|
public static bool IsSet<T>(T flags, T flag) where T : struct
|
|
|
|
|
{
|
2020-07-28 13:59:24 +00:00
|
|
|
|
var flagsValue = (int)(object)flags;
|
|
|
|
|
var flagValue = (int)(object)flag;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
|
|
|
|
return (flagsValue & flagValue) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Set<T>(ref T flags, T flag) where T : struct
|
|
|
|
|
{
|
2020-07-28 13:59:24 +00:00
|
|
|
|
var flagsValue = (int)(object)flags;
|
|
|
|
|
var flagValue = (int)(object)flag;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
|
|
|
|
flags = (T)(object)(flagsValue | flagValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Unset<T>(ref T flags, T flag) where T : struct
|
|
|
|
|
{
|
2020-07-28 13:59:24 +00:00
|
|
|
|
var flagsValue = (int)(object)flags;
|
|
|
|
|
var flagValue = (int)(object)flag;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
|
|
|
|
flags = (T)(object)(flagsValue & (~flagValue));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|