diff --git a/src/runtime/classmanager.cs b/src/runtime/classmanager.cs index 1ee06e682..1d6647723 100644 --- a/src/runtime/classmanager.cs +++ b/src/runtime/classmanager.cs @@ -177,9 +177,8 @@ internal static Dictionary RestoreRuntimeData(R /// A Borrowed reference to the ClassBase object internal static ClassBase GetClass(Type type) { - ClassBase cb = null; - cache.TryGetValue(type, out cb); - if (cb != null) + ClassBase cb; + if (cache.TryGetValue(type, out cb)) { return cb; } diff --git a/src/runtime/genericutil.cs b/src/runtime/genericutil.cs index 92b847e98..de00b2550 100644 --- a/src/runtime/genericutil.cs +++ b/src/runtime/genericutil.cs @@ -27,25 +27,30 @@ public static void Reset() /// A generic type definition (t.IsGenericTypeDefinition must be true) internal static void Register(Type t) { - if (null == t.Namespace || null == t.Name) + lock (mapping) { - return; - } + if (null == t.Namespace || null == t.Name) + { + return; + } - Dictionary> nsmap; - if (!mapping.TryGetValue(t.Namespace, out nsmap)) - { - nsmap = new Dictionary>(); - mapping[t.Namespace] = nsmap; - } - string basename = GetBasename(t.Name); - List gnames; - if (!nsmap.TryGetValue(basename, out gnames)) - { - gnames = new List(); - nsmap[basename] = gnames; + Dictionary> nsmap; + if (!mapping.TryGetValue(t.Namespace, out nsmap)) + { + nsmap = new Dictionary>(); + mapping[t.Namespace] = nsmap; + } + + string basename = GetBasename(t.Name); + List gnames; + if (!nsmap.TryGetValue(basename, out gnames)) + { + gnames = new List(); + nsmap[basename] = gnames; + } + + gnames.Add(t.Name); } - gnames.Add(t.Name); } /// @@ -53,17 +58,20 @@ internal static void Register(Type t) /// public static List GetGenericBaseNames(string ns) { - Dictionary> nsmap; - if (!mapping.TryGetValue(ns, out nsmap)) + lock (mapping) { - return null; - } - var names = new List(); - foreach (string key in nsmap.Keys) - { - names.Add(key); + Dictionary> nsmap; + if (!mapping.TryGetValue(ns, out nsmap)) + { + return null; + } + var names = new List(); + foreach (string key in nsmap.Keys) + { + names.Add(key); + } + return names; } - return names; } /// @@ -79,29 +87,32 @@ public static Type GenericForType(Type t, int paramCount) /// public static Type GenericByName(string ns, string basename, int paramCount) { - Dictionary> nsmap; - if (!mapping.TryGetValue(ns, out nsmap)) + lock (mapping) { - return null; - } + Dictionary> nsmap; + if (!mapping.TryGetValue(ns, out nsmap)) + { + return null; + } - List names; - if (!nsmap.TryGetValue(GetBasename(basename), out names)) - { - return null; - } + List names; + if (!nsmap.TryGetValue(GetBasename(basename), out names)) + { + return null; + } - foreach (string name in names) - { - string qname = ns + "." + name; - Type o = AssemblyManager.LookupTypes(qname).FirstOrDefault(); - if (o != null && o.GetGenericArguments().Length == paramCount) + foreach (string name in names) { - return o; + string qname = ns + "." + name; + Type o = AssemblyManager.LookupTypes(qname).FirstOrDefault(); + if (o != null && o.GetGenericArguments().Length == paramCount) + { + return o; + } } - } - return null; + return null; + } } /// @@ -109,17 +120,22 @@ public static Type GenericByName(string ns, string basename, int paramCount) /// public static string GenericNameForBaseName(string ns, string name) { - Dictionary> nsmap; - if (!mapping.TryGetValue(ns, out nsmap)) + lock (mapping) { - return null; - } - List gnames; - nsmap.TryGetValue(name, out gnames); - if (gnames?.Count > 0) - { - return gnames[0]; + Dictionary> nsmap; + if (!mapping.TryGetValue(ns, out nsmap)) + { + return null; + } + + List gnames; + nsmap.TryGetValue(name, out gnames); + if (gnames?.Count > 0) + { + return gnames[0]; + } } + return null; }