Browse Source

Fix #1329: AssertionFailedException: Should not insert using declaration for namespace that is missing from the superset: System.Windows.Markup

pull/1347/head
Siegfried Pammer 7 years ago
parent
commit
f43e26f87c
  1. 15
      ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs

15
ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs

@ -86,13 +86,15 @@ namespace ICSharpCode.Decompiler.CSharp @@ -86,13 +86,15 @@ namespace ICSharpCode.Decompiler.CSharp
CollectNamespacesForTypeReference(param.Type, namespaces);
}
HandleTypeParameters(method.TypeParameters, namespaces);
if (!method.MetadataToken.IsNil && method.HasBody) {
if (!method.MetadataToken.IsNil) {
if (mappingInfo == null)
mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentModule.PEFile, entity.MetadataToken);
var reader = module.PEFile.Reader;
var parts = mappingInfo.GetMethodParts((MethodDefinitionHandle)method.MetadataToken).ToList();
foreach (var part in parts) {
HandleOverrides(part.GetMethodImplementations(module.metadata), module, namespaces);
var methodDef = module.metadata.GetMethodDefinition(part);
if (method.HasBody) {
MethodBodyBlock body;
try {
body = reader.GetMethodBody(methodDef.RelativeVirtualAddress);
@ -102,6 +104,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -102,6 +104,7 @@ namespace ICSharpCode.Decompiler.CSharp
CollectNamespacesFromMethodBody(body, module, namespaces);
}
}
}
break;
case IProperty property:
HandleAttributes(property.GetAttributes(), namespaces);
@ -116,6 +119,16 @@ namespace ICSharpCode.Decompiler.CSharp @@ -116,6 +119,16 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
static void HandleOverrides(ImmutableArray<MethodImplementationHandle> immutableArray, MetadataModule module, HashSet<string> namespaces)
{
foreach (var h in immutableArray) {
var methodImpl = module.metadata.GetMethodImplementation(h);
CollectNamespacesForTypeReference(module.ResolveType(methodImpl.Type, genericContext), namespaces);
CollectNamespacesForMemberReference(module.ResolveMethod(methodImpl.MethodBody, genericContext), module, namespaces);
CollectNamespacesForMemberReference(module.ResolveMethod(methodImpl.MethodDeclaration, genericContext), module, namespaces);
}
}
static void CollectNamespacesForTypeReference(IType type, HashSet<string> namespaces)
{
switch (type) {

Loading…
Cancel
Save