mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-25 15:35:22 +00:00
37 lines
998 B
C#
37 lines
998 B
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
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
|
|||
|
{
|
|||
|
int flagsValue = (int)(object)flags;
|
|||
|
int flagValue = (int)(object)flag;
|
|||
|
|
|||
|
return (flagsValue & flagValue) != 0;
|
|||
|
}
|
|||
|
|
|||
|
public static void Set<T>(ref T flags, T flag) where T : struct
|
|||
|
{
|
|||
|
int flagsValue = (int)(object)flags;
|
|||
|
int flagValue = (int)(object)flag;
|
|||
|
|
|||
|
flags = (T)(object)(flagsValue | flagValue);
|
|||
|
}
|
|||
|
|
|||
|
public static void Unset<T>(ref T flags, T flag) where T : struct
|
|||
|
{
|
|||
|
int flagsValue = (int)(object)flags;
|
|||
|
int flagValue = (int)(object)flag;
|
|||
|
|
|||
|
flags = (T)(object)(flagsValue & (~flagValue));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|