com.wallstop-studios.dxmessaging 2.0.0-rc26.7 → 2.0.0-rc26.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,29 +9,36 @@ namespace DxMessaging.Core.Extensions
|
|
|
9
9
|
internal static bool HasFlagNoAlloc<T>(this T value, T flag)
|
|
10
10
|
where T : unmanaged, Enum
|
|
11
11
|
{
|
|
12
|
-
ulong valueUnderlying = GetUInt64(value);
|
|
13
|
-
ulong flagUnderlying = GetUInt64(flag);
|
|
14
|
-
|
|
12
|
+
ulong? valueUnderlying = GetUInt64(value);
|
|
13
|
+
ulong? flagUnderlying = GetUInt64(flag);
|
|
14
|
+
if (valueUnderlying == null || flagUnderlying == null)
|
|
15
|
+
{
|
|
16
|
+
// Fallback for unsupported enum sizes
|
|
17
|
+
return value.HasFlag(flag);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (valueUnderlying.Value & flagUnderlying.Value) == flagUnderlying.Value;
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
18
|
-
private static
|
|
24
|
+
private static ulong? GetUInt64<T>(T value)
|
|
19
25
|
where T : unmanaged
|
|
20
26
|
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
try
|
|
28
|
+
{
|
|
29
|
+
return Unsafe.SizeOf<T>() switch
|
|
30
|
+
{
|
|
31
|
+
1 => Unsafe.As<T, byte>(ref value),
|
|
32
|
+
2 => Unsafe.As<T, ushort>(ref value),
|
|
33
|
+
4 => Unsafe.As<T, uint>(ref value),
|
|
34
|
+
8 => Unsafe.As<T, ulong>(ref value),
|
|
35
|
+
_ => null,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch
|
|
26
39
|
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
4 => *(uint*)&value,
|
|
30
|
-
8 => *(ulong*)&value,
|
|
31
|
-
_ => throw new ArgumentException(
|
|
32
|
-
$"Unsupported enum size: {sizeof(T)} for type {typeof(T)}"
|
|
33
|
-
),
|
|
34
|
-
};
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
35
42
|
}
|
|
36
43
|
}
|
|
37
44
|
}
|
package/package.json
CHANGED