using System.Numerics; static public class bit { public static unsafe TInt ByPointers_DirectInt(TEnum enumValue) where TInt : IBinaryInteger where TEnum : unmanaged, System.Enum { #pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type return *(TInt*)(&enumValue); #pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type } static public bool On( T bitfield, E e ) where T: IBinaryInteger where E: unmanaged, System.Enum { var eInt = ByPointers_DirectInt( e ); return (eInt & bitfield) == eInt; } }