@@ -24,34 +24,37 @@ public static class fsTypeCache {
2424 private static List < Assembly > _assembliesByIndex ;
2525
2626 static fsTypeCache ( ) {
27- // Setup assembly references so searching and the like resolves correctly.
28- _assembliesByName = new Dictionary < string , Assembly > ( ) ;
29- _assembliesByIndex = new List < Assembly > ( ) ;
27+ lock ( typeof ( fsTypeCache ) ) {
28+ // Setup assembly references so searching and the like resolves correctly.
29+ _assembliesByName = new Dictionary < string , Assembly > ( ) ;
30+ _assembliesByIndex = new List < Assembly > ( ) ;
3031
3132#if ( ! UNITY_EDITOR && UNITY_METRO && ! ENABLE_IL2CPP ) // no AppDomain on WinRT
32- var assembly = typeof ( object ) . GetTypeInfo ( ) . Assembly ;
33- _assembliesByName [ assembly . FullName ] = assembly ;
34- _assembliesByIndex . Add ( assembly ) ;
35- #else
36- foreach ( Assembly assembly in AppDomain . CurrentDomain . GetAssemblies ( ) ) {
33+ var assembly = typeof ( object ) . GetTypeInfo ( ) . Assembly ;
3734 _assembliesByName [ assembly . FullName ] = assembly ;
3835 _assembliesByIndex . Add ( assembly ) ;
39- }
36+ #else
37+ foreach ( Assembly assembly in AppDomain . CurrentDomain . GetAssemblies ( ) ) {
38+ _assembliesByName [ assembly . FullName ] = assembly ;
39+ _assembliesByIndex . Add ( assembly ) ;
40+ }
4041#endif
41-
42- _cachedTypes = new Dictionary < string , Type > ( ) ;
42+ _cachedTypes = new Dictionary < string , Type > ( ) ;
4343
4444#if ! ( UNITY_WP8 || UNITY_METRO ) // AssemblyLoad events are not supported on these platforms
45- AppDomain . CurrentDomain . AssemblyLoad += OnAssemblyLoaded ;
45+ AppDomain . CurrentDomain . AssemblyLoad += OnAssemblyLoaded ;
4646#endif
47+ }
4748 }
4849
4950#if ! ( UNITY_WP8 || UNITY_METRO ) // AssemblyLoad events are not supported on these platforms
5051 private static void OnAssemblyLoaded ( object sender , AssemblyLoadEventArgs args ) {
51- _assembliesByName [ args . LoadedAssembly . FullName ] = args . LoadedAssembly ;
52- _assembliesByIndex . Add ( args . LoadedAssembly ) ;
52+ lock ( typeof ( fsTypeCache ) ) {
53+ _assembliesByName [ args . LoadedAssembly . FullName ] = args . LoadedAssembly ;
54+ _assembliesByIndex . Add ( args . LoadedAssembly ) ;
5355
54- _cachedTypes = new Dictionary < string , Type > ( ) ;
56+ _cachedTypes = new Dictionary < string , Type > ( ) ;
57+ }
5558 }
5659#endif
5760
@@ -150,17 +153,19 @@ public static Type GetType(string name, string assemblyHint) {
150153 return null ;
151154 }
152155
153- Type type ;
154- if ( _cachedTypes . TryGetValue ( name , out type ) == false ) {
155- // if both the direct and indirect type lookups fail, then throw an exception
156- if ( TryDirectTypeLookup ( assemblyHint , name , out type ) == false &&
157- TryIndirectTypeLookup ( name , out type ) == false ) {
156+ lock ( typeof ( fsTypeCache ) ) {
157+ Type type ;
158+ if ( _cachedTypes . TryGetValue ( name , out type ) == false ) {
159+ // if both the direct and indirect type lookups fail, then throw an exception
160+ if ( TryDirectTypeLookup ( assemblyHint , name , out type ) == false &&
161+ TryIndirectTypeLookup ( name , out type ) == false ) {
162+ }
163+
164+ _cachedTypes [ name ] = type ;
158165 }
159166
160- _cachedTypes [ name ] = type ;
167+ return type ;
161168 }
162-
163- return type ;
164169 }
165170 }
166171}
0 commit comments