30 lines
692 B
C#
30 lines
692 B
C#
|
|
|
|
using System.Numerics;
|
|
|
|
static public class bit
|
|
{
|
|
|
|
public static unsafe TInt ByPointers_DirectInt<TInt, TEnum>( TEnum enumValue )
|
|
where TInt : IBinaryInteger<TInt>
|
|
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, E>( T bitfield, E e )
|
|
where T : IBinaryInteger<T>
|
|
where E : unmanaged, System.Enum
|
|
{
|
|
var eInt = ByPointers_DirectInt<T, E>( e );
|
|
|
|
return ( eInt & bitfield ) == eInt;
|
|
}
|
|
|
|
|
|
}
|