Skip to content

Commit e164d40

Browse files
committed
fix(managed): Fix schema size
1 parent a636b2c commit e164d40

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

managed/src/SwiftlyS2.Shared/Modules/Schemas/SchemaSize.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@ public static class SchemaSize
88
{
99
private static readonly ConcurrentDictionary<Type, int> _sizeCache = new();
1010

11+
public static int GetSize<T>() where T : ISchemaClass<T>
12+
{
13+
return T.Size;
14+
}
1115
public static int Get<T>()
1216
{
1317
return _sizeCache.GetOrAdd(typeof(T), static type =>
1418
{
15-
foreach (var iface in type.GetInterfaces())
19+
var interfaces = type.GetInterfaces();
20+
foreach (var iface in interfaces)
1621
{
1722
if (iface.IsGenericType &&
1823
iface.GetGenericTypeDefinition() == typeof(ISchemaClass<>) &&
1924
iface.GetGenericArguments()[0] == type)
2025
{
21-
var sizeProperty = iface.GetProperty("Size",
22-
BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
23-
24-
if (sizeProperty != null)
26+
var method = typeof(SchemaSize).GetMethod(nameof(GetSize))?.MakeGenericMethod(type);
27+
if (method != null)
2528
{
26-
return (int)sizeProperty.GetValue(null)!;
29+
return (int)method.Invoke(null, null)!;
2730
}
2831
}
2932
}
3033

3134
return Unsafe.SizeOf<T>();
3235
});
33-
}
34-
}
36+
}}

0 commit comments

Comments
 (0)