using System.Numerics; namespace KamiToolKit.Classes; public static class FlagHelper { public static bool ReadFlag(ref T flagsField, int flag) where T : struct, IBinaryInteger => (flagsField & T.One << BitOperations.Log2((uint)flag)) != T.Zero; public static void SetFlag(ref T flagsField, int flag) where T : struct, IBinaryInteger => flagsField |= T.One << BitOperations.Log2((uint)flag); public static void ClearFlag(ref T flagsField, int flag) where T : struct, IBinaryInteger => flagsField &= ~(T.One << BitOperations.Log2((uint)flag)); public static void UpdateFlag(ref T flagsField, int flag, bool enable) where T : struct, IBinaryInteger { if (enable) { SetFlag(ref flagsField, flag); } else { ClearFlag(ref flagsField, flag); } } }