This repository was archived by the owner on May 9, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -22,15 +22,19 @@ public class ReflectionHelpers
22
22
public static ILType ComponentType => Il2CppType . Of < Component > ( ) ;
23
23
public static ILType BehaviourType => Il2CppType . Of < Behaviour > ( ) ;
24
24
25
- private static readonly MethodInfo m_tryCastMethodInfo = typeof ( Il2CppObjectBase ) . GetMethod ( "TryCast" ) ;
25
+ private static readonly MethodInfo tryCastMethodInfo = typeof ( Il2CppObjectBase ) . GetMethod ( "TryCast" ) ;
26
+ private static readonly Dictionary < Type , MethodInfo > cachedTryCastMethods = new Dictionary < Type , MethodInfo > ( ) ;
26
27
27
28
public static object Il2CppCast ( object obj , Type castTo )
28
29
{
29
30
if ( ! typeof ( Il2CppSystem . Object ) . IsAssignableFrom ( castTo ) ) return obj ;
30
31
31
- return m_tryCastMethodInfo
32
- . MakeGenericMethod ( castTo )
33
- . Invoke ( obj , null ) ;
32
+ if ( ! cachedTryCastMethods . ContainsKey ( castTo ) )
33
+ {
34
+ cachedTryCastMethods . Add ( castTo , tryCastMethodInfo . MakeGenericMethod ( castTo ) ) ;
35
+ }
36
+
37
+ return cachedTryCastMethods [ castTo ] . Invoke ( obj , null ) ;
34
38
}
35
39
36
40
public static bool IsEnumerable ( Type t )
You can’t perform that action at this time.
0 commit comments