Skip to content

EnumFlagExtensions Class

Extension methods for [Flags] enum values that complement the BCL surface. Named with the Flag qualifier so it does not collide with the very common EnumExtensions class name used by other libraries (e.g. Fido2NetLib.EnumExtensions), which would surface as CS0104 in any consumer that imports both namespaces.

C#
public static class EnumFlagExtensions

Inheritance System.Object → EnumFlagExtensions

Methods

EnumFlagExtensions.HasAnyFlag<T>(this T, T) Method

Returns true when at least one flag in mask is set in value. The OR-counterpart to System.Enum.HasFlag(System.Enum): HasFlag(mask) requires every bit of mask to be set, while this method is satisfied by any single bit. Callers should build the mask inline by OR-ing the individual flags they want to test for, rather than reusing a named composite enum member whose semantics may match System.Enum.HasFlag(System.Enum) (all-of) instead of any-of.

C#
public static bool HasAnyFlag<T>(this T value, T mask)
    where T : struct, System.Enum;

Type parameters

T

A [Flags] enum type.

Parameters

value T

The flag value to inspect.

mask T

An OR of the flags to test for.

Returns

System.Boolean
true when any flag in mask is set in value; otherwise false.