Browse Source

Merge pull request #1763 from yyjdelete/patch1762

Fix issue #1762
pull/1769/head
Siegfried Pammer 6 years ago committed by GitHub
parent
commit
d6edcaa469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 40
      ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs
  3. 3
      ILSpy/LoadedAssembly.cs

1
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -783,6 +783,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -783,6 +783,7 @@ namespace ICSharpCode.Decompiler.CSharp
syntaxTree = new SyntaxTree();
foreach (var type in types) {
CancellationToken.ThrowIfCancellationRequested();
if (type.IsNil)
throw new ArgumentException("types contains null element");
RequiredNamespaceCollector.CollectNamespaces(type, module, decompileRun.Namespaces);

40
ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs

@ -55,10 +55,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -55,10 +55,10 @@ namespace ICSharpCode.Decompiler.CSharp
{
if (entity == null || entity.MetadataToken.IsNil)
return;
if (mappingInfo == null)
mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentModule.PEFile, entity.MetadataToken);
switch (entity) {
case ITypeDefinition td:
if (mappingInfo == null)
mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentModule.PEFile, entity.MetadataToken);
namespaces.Add(td.Namespace);
HandleAttributes(td.GetAttributes());
HandleTypeParameters(td.TypeParameters);
@ -100,35 +100,31 @@ namespace ICSharpCode.Decompiler.CSharp @@ -100,35 +100,31 @@ namespace ICSharpCode.Decompiler.CSharp
CollectNamespacesForTypeReference(param.Type);
}
HandleTypeParameters(method.TypeParameters);
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);
var methodDef = module.metadata.GetMethodDefinition(part);
if (method.HasBody) {
MethodBodyBlock body;
try {
body = reader.GetMethodBody(methodDef.RelativeVirtualAddress);
} catch (BadImageFormatException) {
continue;
}
CollectNamespacesFromMethodBody(body, module);
var reader = module.PEFile.Reader;
var parts = mappingInfo.GetMethodParts((MethodDefinitionHandle)method.MetadataToken).ToList();
foreach (var part in parts) {
HandleOverrides(part.GetMethodImplementations(module.metadata), module);
var methodDef = module.metadata.GetMethodDefinition(part);
if (method.HasBody) {
MethodBodyBlock body;
try {
body = reader.GetMethodBody(methodDef.RelativeVirtualAddress);
} catch (BadImageFormatException) {
continue;
}
CollectNamespacesFromMethodBody(body, module);
}
}
break;
case IProperty property:
HandleAttributes(property.GetAttributes());
CollectNamespaces(property.Getter, module);
CollectNamespaces(property.Setter, module);
CollectNamespaces(property.Getter, module, mappingInfo);
CollectNamespaces(property.Setter, module, mappingInfo);
break;
case IEvent @event:
HandleAttributes(@event.GetAttributes());
CollectNamespaces(@event.AddAccessor, module);
CollectNamespaces(@event.RemoveAccessor, module);
CollectNamespaces(@event.AddAccessor, module, mappingInfo);
CollectNamespaces(@event.RemoveAccessor, module, mappingInfo);
break;
}
}

3
ILSpy/LoadedAssembly.cs

@ -156,7 +156,8 @@ namespace ICSharpCode.ILSpy @@ -156,7 +156,8 @@ namespace ICSharpCode.ILSpy
// runs on background thread
if (state is Stream stream) {
// Read the module from a precrafted stream
module = new PEFile(fileName, stream, metadataOptions: options);
var streamOptions = stream is MemoryStream ? PEStreamOptions.PrefetchEntireImage : PEStreamOptions.Default;
module = new PEFile(fileName, stream, streamOptions, metadataOptions: options);
} else {
// Read the module from disk (by default)
stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

Loading…
Cancel
Save