Created
June 21, 2023 07:07
-
-
Save guitarrapc/173b9bb030c608f1f341e61b199b7374 to your computer and use it in GitHub Desktop.
C# bool is not Blittable. Instead, use byte or wrap byte to offer BlittableBool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct BlittableBool | |
{ | |
public readonly byte Value; | |
public BlittableBool(byte value) | |
{ | |
Value = value; | |
} | |
public BlittableBool(bool value) | |
{ | |
Value = value ? (byte)1 : (byte)0; | |
} | |
public static implicit operator bool(BlittableBool bb) | |
{ | |
return bb.Value != 0; | |
} | |
public static implicit operator BlittableBool(bool b) | |
{ | |
return new BlittableBool(b); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment