Skip to content

IsValidBitmask Method ​

Definition ​

  • Namespace: JASE.Extensions
  • Assembly: JASE.Primitives.dll

bool IsValidBitmask(bool allowMaxEqualAll = null, bool allowZero = null) ​

csharp
bool IsValidBitmask(bool allowMaxEqualAll = null, bool allowZero = null)

Determines whether the specified enum type represents a valid bitmask structure, where each value (excluding any explicitly defined "All" value) is a power of two.

Type parameters ​

NameDescription
TThe enum type to inspect. Must be a value type implementing Enum and IConvertible.

Parameters ​

NameDescription
allowMaxEqualAllIf true, allows the presence of MaxValue or MaxValue to represent a valid "All" value. This is useful for legacy enums that treat max int/long as a shortcut for "all flags".
allowZeroIf true, a 0 value for an enum value will be allowed

Returns ​

True if all values (excluding an "All" value, if permitted) are distinct powers of two, making the enum a valid bitmask; otherwise, false.

Remarks ​

A valid bitmask enum should define values like 1, 2, 4, 8, 16, etc., with each representing a distinct bit position. This check helps enforce [Flags]-style conventions and identify misuse of aggregate or non-power-of-two constants.