From f9ea705e7743c43f22d8bf35cc3d273ef9ef5508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 16 Mar 2024 23:34:10 +0100 Subject: [PATCH] Enum extension for SetFlag and ClearFlag --- GlitchyEngine/src/Extension/System/Enum.bf | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 GlitchyEngine/src/Extension/System/Enum.bf 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); + } +}