I would like to have an extension method on my flags to know if they have a certain flag in them or not.
The problem is that the HasAFlagOf code allocates garbage and I just use flags too much to allow this. How can I not allocate garbage and use a method that works for my flags?
public static class EnumExt{
public static bool HasAFlagOf<T>(this T value, T flag) where T : struct // allocates garbage
{
return (Convert.ToInt64(value) & Convert.ToInt64(flag)) != 0;
}
public static bool HasAFlagNoGarbage(this SH_UberFx.XY value, SH_UberFx.XY flags) // NO garbage allocated but I must create many different variations of these because it is type dependant
{
return (value & flags) != 0;
}
public static bool HasAFlagNoGarbage(this SH_UberFx.MainTex value, SH_UberFx.MainTex flags)// NO garbage allocated but I must create many different variations of these because it is type dependant
{
return (value & flags) != 0;
}
}
Hereās how I create all my flags ( I just need the method to work with that kind of flag enum ):
[System.Flags]
public enum VegetationBitmaskEnum
{
Wind = 1 << 0,
Ondulation = 1 << 1,
Rotation = 1 << 2,
Scale = 1 << 3,
//All = Wind | Ondulation | Rotation | Scale
}