File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
managed/src/SwiftlyS2.Shared/Modules/Schemas Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff 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+ } }
You can’t perform that action at this time.
0 commit comments