Browse Source

更新Enum扩展方法

HerobrineXia 2 months ago
parent
commit
5a6dce8b96
1 changed files with 3 additions and 0 deletions
  1. 3 0
      Shared/Utils/EnumUtils.cs

+ 3 - 0
Shared/Utils/EnumUtils.cs

@@ -24,6 +24,9 @@ public static class EnumUtils {
         }
     }
 
+    public static bool HasFlagF<T>(this T value, T flag) where T : struct, Enum
+        => value.HasFlag(flag) && !EqualityComparer<T>.Default.Equals(flag, default);
+
     /// <summary>
     /// 对于具有 <see cref="FlagsAttribute"/> 的枚举,返回其所有 Flag 值。
     /// 建议仅对没有极端值的正数枚举使用。