quantum-space-buddies/QSB/Utility/FlagsHelper.cs
AmazingAlek 18a520bc78
cleanup (#99)
* cleanup
2020-07-28 14:59:24 +01:00

32 lines
911 B
C#

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
{
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
{
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
{
var flagsValue = (int)(object)flags;
var flagValue = (int)(object)flag;
flags = (T)(object)(flagsValue & (~flagValue));
}
}
}