Browse Source

fix http://community.sharpdevelop.net/forums/t/13658.aspx - type was not found due to type forwarding

pull/263/merge
Siegfried Pammer 14 years ago
parent
commit
c0fe6d0173
  1. 23
      ILSpy.BamlDecompiler/CecilTypeResolver.cs

23
ILSpy.BamlDecompiler/CecilTypeResolver.cs

@ -48,15 +48,38 @@ namespace ILSpy.BamlDecompiler
string assemblyName = name.Substring(comma + 1).Trim(); string assemblyName = name.Substring(comma + 1).Trim();
var type = thisAssembly.MainModule.GetType(fullName); var type = thisAssembly.MainModule.GetType(fullName);
if (type == null) {
type = TryFindInExportedTypes(fullName, thisAssembly);
}
if (type == null) { if (type == null) {
var otherAssembly = resolver.Resolve(assemblyName); var otherAssembly = resolver.Resolve(assemblyName);
if (otherAssembly == null) if (otherAssembly == null)
throw new Exception("could not resolve '" + assemblyName + "'!"); throw new Exception("could not resolve '" + assemblyName + "'!");
type = otherAssembly.MainModule.GetType(fullName.Replace('+', '/')); type = otherAssembly.MainModule.GetType(fullName.Replace('+', '/'));
if (type == null) {
type = TryFindInExportedTypes(fullName, otherAssembly);
}
} }
if (type == null)
throw new Exception("could not resolve '" + name + "'!");
return new CecilType(type); return new CecilType(type);
} }
TypeDefinition TryFindInExportedTypes(string fullName, AssemblyDefinition asm)
{
foreach (var exportedType in asm.MainModule.ExportedTypes) {
if (exportedType.IsForwarder && exportedType.FullName == fullName) {
return exportedType.Resolve();
}
}
return null;
}
public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType) public IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType)
{ {

Loading…
Cancel
Save