Skip to content

Commit

Permalink
Reflect PR #38
Browse files Browse the repository at this point in the history
  • Loading branch information
C-SELLERS committed Feb 24, 2021
1 parent 7e1d2ea commit 3c90195
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 54 deletions.
5 changes: 2 additions & 3 deletions src/runtime/classmanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ internal static Dictionary<ManagedType, InterDomainContext> RestoreRuntimeData(R
/// <returns>A Borrowed reference to the ClassBase object</returns>
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;
}
Expand Down
118 changes: 67 additions & 51 deletions src/runtime/genericutil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,51 @@ public static void Reset()
/// <param name="t">A generic type definition (<c>t.IsGenericTypeDefinition</c> must be true)</param>
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<string, List<string>> nsmap;
if (!mapping.TryGetValue(t.Namespace, out nsmap))
{
nsmap = new Dictionary<string, List<string>>();
mapping[t.Namespace] = nsmap;
}
string basename = GetBasename(t.Name);
List<string> gnames;
if (!nsmap.TryGetValue(basename, out gnames))
{
gnames = new List<string>();
nsmap[basename] = gnames;
Dictionary<string, List<string>> nsmap;
if (!mapping.TryGetValue(t.Namespace, out nsmap))
{
nsmap = new Dictionary<string, List<string>>();
mapping[t.Namespace] = nsmap;
}

string basename = GetBasename(t.Name);
List<string> gnames;
if (!nsmap.TryGetValue(basename, out gnames))
{
gnames = new List<string>();
nsmap[basename] = gnames;
}

gnames.Add(t.Name);
}
gnames.Add(t.Name);
}

/// <summary>
/// xxx
/// </summary>
public static List<string> GetGenericBaseNames(string ns)
{
Dictionary<string, List<string>> nsmap;
if (!mapping.TryGetValue(ns, out nsmap))
lock (mapping)
{
return null;
}
var names = new List<string>();
foreach (string key in nsmap.Keys)
{
names.Add(key);
Dictionary<string, List<string>> nsmap;
if (!mapping.TryGetValue(ns, out nsmap))
{
return null;
}
var names = new List<string>();
foreach (string key in nsmap.Keys)
{
names.Add(key);
}
return names;
}
return names;
}

/// <summary>
Expand All @@ -79,47 +87,55 @@ public static Type GenericForType(Type t, int paramCount)
/// </summary>
public static Type GenericByName(string ns, string basename, int paramCount)
{
Dictionary<string, List<string>> nsmap;
if (!mapping.TryGetValue(ns, out nsmap))
lock (mapping)
{
return null;
}
Dictionary<string, List<string>> nsmap;
if (!mapping.TryGetValue(ns, out nsmap))
{
return null;
}

List<string> names;
if (!nsmap.TryGetValue(GetBasename(basename), out names))
{
return null;
}
List<string> 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;
}
}

/// <summary>
/// xxx
/// </summary>
public static string GenericNameForBaseName(string ns, string name)
{
Dictionary<string, List<string>> nsmap;
if (!mapping.TryGetValue(ns, out nsmap))
lock (mapping)
{
return null;
}
List<string> gnames;
nsmap.TryGetValue(name, out gnames);
if (gnames?.Count > 0)
{
return gnames[0];
Dictionary<string, List<string>> nsmap;
if (!mapping.TryGetValue(ns, out nsmap))
{
return null;
}

List<string> gnames;
nsmap.TryGetValue(name, out gnames);
if (gnames?.Count > 0)
{
return gnames[0];
}
}

return null;
}

Expand Down

0 comments on commit 3c90195

Please sign in to comment.