Skip to content

Commit

Permalink
Add support for nested types to CecilAssembly.
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys authored and workgroupengineering committed Jun 10, 2024
1 parent 14fed0c commit b396661
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/XamlX.IL.Cecil/CecilAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,36 @@ public CecilAssembly(CecilTypeSystem typeSystem, AssemblyDefinition assembly)
{
if (_typeCache.TryGetValue(fullName, out var rv))
return rv;
var lastDot = fullName.LastIndexOf(".", StringComparison.Ordinal);
var asmRef = new AssemblyNameReference(Assembly.Name.Name, Assembly.Name.Version);
var tref = (lastDot == -1)
? new TypeReference(null, fullName, Assembly.MainModule, asmRef)
: new TypeReference(fullName.Substring(0, lastDot),
fullName.Substring(lastDot + 1), Assembly.MainModule, asmRef);
var resolved = tref.Resolve();
var lastDot = fullName.LastIndexOf('.');
var ns = string.Empty;

if (lastDot != -1)
{
ns = fullName.Substring(0, lastDot);
fullName = fullName.Substring(lastDot + 1);
}

TypeReference? tref = null;
var plus = fullName.IndexOf('+');

while (true)
{
var typeName = plus != -1 ? fullName.Substring(0, plus) : fullName;
var t = new TypeReference(ns, typeName, Assembly.MainModule, asmRef);

t.DeclaringType = tref;
tref = t;

if (plus == -1)
break;

ns = null;
fullName = fullName.Substring(plus + 1);
plus = fullName.IndexOf('+');
}

var resolved = tref?.Resolve();
if (resolved != null)
return _typeCache[fullName] = TypeSystem.RootTypeResolveContext.Resolve(resolved);

Expand Down

0 comments on commit b396661

Please sign in to comment.