Skip to content

Commit cde9b51

Browse files
committed
Reflect PR #38
1 parent c362816 commit cde9b51

File tree

2 files changed

+69
-54
lines changed

2 files changed

+69
-54
lines changed

src/runtime/classmanager.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ internal static Dictionary<ManagedType, InterDomainContext> RestoreRuntimeData(R
177177
/// <returns>A Borrowed reference to the ClassBase object</returns>
178178
internal static ClassBase GetClass(Type type)
179179
{
180-
ClassBase cb = null;
181-
cache.TryGetValue(type, out cb);
182-
if (cb != null)
180+
ClassBase cb;
181+
if (cache.TryGetValue(type, out cb))
183182
{
184183
return cb;
185184
}

src/runtime/genericutil.cs

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,51 @@ public static void Reset()
2727
/// <param name="t">A generic type definition (<c>t.IsGenericTypeDefinition</c> must be true)</param>
2828
internal static void Register(Type t)
2929
{
30-
if (null == t.Namespace || null == t.Name)
30+
lock (mapping)
3131
{
32-
return;
33-
}
32+
if (null == t.Namespace || null == t.Name)
33+
{
34+
return;
35+
}
3436

35-
Dictionary<string, List<string>> nsmap;
36-
if (!mapping.TryGetValue(t.Namespace, out nsmap))
37-
{
38-
nsmap = new Dictionary<string, List<string>>();
39-
mapping[t.Namespace] = nsmap;
40-
}
41-
string basename = GetBasename(t.Name);
42-
List<string> gnames;
43-
if (!nsmap.TryGetValue(basename, out gnames))
44-
{
45-
gnames = new List<string>();
46-
nsmap[basename] = gnames;
37+
Dictionary<string, List<string>> nsmap;
38+
if (!mapping.TryGetValue(t.Namespace, out nsmap))
39+
{
40+
nsmap = new Dictionary<string, List<string>>();
41+
mapping[t.Namespace] = nsmap;
42+
}
43+
44+
string basename = GetBasename(t.Name);
45+
List<string> gnames;
46+
if (!nsmap.TryGetValue(basename, out gnames))
47+
{
48+
gnames = new List<string>();
49+
nsmap[basename] = gnames;
50+
}
51+
52+
gnames.Add(t.Name);
4753
}
48-
gnames.Add(t.Name);
4954
}
5055

5156
/// <summary>
5257
/// xxx
5358
/// </summary>
5459
public static List<string> GetGenericBaseNames(string ns)
5560
{
56-
Dictionary<string, List<string>> nsmap;
57-
if (!mapping.TryGetValue(ns, out nsmap))
61+
lock (mapping)
5862
{
59-
return null;
60-
}
61-
var names = new List<string>();
62-
foreach (string key in nsmap.Keys)
63-
{
64-
names.Add(key);
63+
Dictionary<string, List<string>> nsmap;
64+
if (!mapping.TryGetValue(ns, out nsmap))
65+
{
66+
return null;
67+
}
68+
var names = new List<string>();
69+
foreach (string key in nsmap.Keys)
70+
{
71+
names.Add(key);
72+
}
73+
return names;
6574
}
66-
return names;
6775
}
6876

6977
/// <summary>
@@ -79,47 +87,55 @@ public static Type GenericForType(Type t, int paramCount)
7987
/// </summary>
8088
public static Type GenericByName(string ns, string basename, int paramCount)
8189
{
82-
Dictionary<string, List<string>> nsmap;
83-
if (!mapping.TryGetValue(ns, out nsmap))
90+
lock (mapping)
8491
{
85-
return null;
86-
}
92+
Dictionary<string, List<string>> nsmap;
93+
if (!mapping.TryGetValue(ns, out nsmap))
94+
{
95+
return null;
96+
}
8797

88-
List<string> names;
89-
if (!nsmap.TryGetValue(GetBasename(basename), out names))
90-
{
91-
return null;
92-
}
98+
List<string> names;
99+
if (!nsmap.TryGetValue(GetBasename(basename), out names))
100+
{
101+
return null;
102+
}
93103

94-
foreach (string name in names)
95-
{
96-
string qname = ns + "." + name;
97-
Type o = AssemblyManager.LookupTypes(qname).FirstOrDefault();
98-
if (o != null && o.GetGenericArguments().Length == paramCount)
104+
foreach (string name in names)
99105
{
100-
return o;
106+
string qname = ns + "." + name;
107+
Type o = AssemblyManager.LookupTypes(qname).FirstOrDefault();
108+
if (o != null && o.GetGenericArguments().Length == paramCount)
109+
{
110+
return o;
111+
}
101112
}
102-
}
103113

104-
return null;
114+
return null;
115+
}
105116
}
106117

107118
/// <summary>
108119
/// xxx
109120
/// </summary>
110121
public static string GenericNameForBaseName(string ns, string name)
111122
{
112-
Dictionary<string, List<string>> nsmap;
113-
if (!mapping.TryGetValue(ns, out nsmap))
123+
lock (mapping)
114124
{
115-
return null;
116-
}
117-
List<string> gnames;
118-
nsmap.TryGetValue(name, out gnames);
119-
if (gnames?.Count > 0)
120-
{
121-
return gnames[0];
125+
Dictionary<string, List<string>> nsmap;
126+
if (!mapping.TryGetValue(ns, out nsmap))
127+
{
128+
return null;
129+
}
130+
131+
List<string> gnames;
132+
nsmap.TryGetValue(name, out gnames);
133+
if (gnames?.Count > 0)
134+
{
135+
return gnames[0];
136+
}
122137
}
138+
123139
return null;
124140
}
125141

0 commit comments

Comments
 (0)