diff --git a/GlitchyEngine/src/Extension/System/Enum.bf b/GlitchyEngine/src/Extension/System/Enum.bf new file mode 100644 index 0000000..f39a137 --- /dev/null +++ b/GlitchyEngine/src/Extension/System/Enum.bf @@ -0,0 +1,22 @@ +namespace System; + +extension Enum +{ + public static void SetFlag(ref T value, T flag) where T : enum + { + value = (T)(value.Underlying | flag.Underlying); + } + + public static void ClearFlag(ref T value, T flag) where T : enum + { + value = (T)(value.Underlying & ~flag.Underlying); + } + + public static void SetFlagConditionally(ref T value, T flag, bool setFlag) where T : enum + { + if (setFlag) + SetFlag(ref value, flag); + else + ClearFlag(ref value, flag); + } +}