Here's the code I'm working on (I found some of it online) and I'm trying to return a List<>
of the flags that are active. Here's the code:
public static class BitMask {
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));
}
public static List<T> GetActiveMasks<T>(ref T flags) where T : struct {
List<T> returned = new List<T>();
foreach(T value in flags)
if(IsSet(flags, value))
returned.Add(value);
return returned;
}
}
However, I'm running into this issue:
foreach statement cannot operate on variables of type 'T' because 'T' does not contain a public definition for 'GetEnumerator' (CS1579) - C:\Users\Christian\Documents\SharpDevelop Projects\OblivionScripts\OblivionScripts\Common\BitMask.cs:36,4
Could someone please nudge me in the right direction as I'm still new to C#.