32 lines
909 B
C#
Raw Normal View History

2020-09-06 09:07:31 +01:00
namespace QSB.Utility
{
// 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 15:59:24 +02:00
var flagsValue = (int)(object)flags;
var flagValue = (int)(object)flag;
return (flagsValue & flagValue) != 0;
}
public static void Set<T>(ref T flags, T flag) where T : struct
{
2020-07-28 15:59:24 +02:00
var flagsValue = (int)(object)flags;
var flagValue = (int)(object)flag;
flags = (T)(object)(flagsValue | flagValue);
}
public static void Unset<T>(ref T flags, T flag) where T : struct
{
2020-07-28 15:59:24 +02:00
var flagsValue = (int)(object)flags;
var flagValue = (int)(object)flag;
2020-09-07 20:27:56 +02:00
flags = (T)(object)(flagsValue & ~flagValue);
}
}
}