Browse Source

Improvements in CollectNamespacesForDecompilation

pull/1108/head
Siegfried Pammer 7 years ago
parent
commit
e9d3f42695
  1. 17
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

17
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -525,9 +525,13 @@ namespace ICSharpCode.Decompiler.CSharp @@ -525,9 +525,13 @@ namespace ICSharpCode.Decompiler.CSharp
foreach (var ca in provider.CustomAttributes) {
CollectNamespacesForDecompilation(ca.AttributeType, namespaces, visited);
CollectNamespacesForDecompilation(ca.Constructor, namespaces, visited);
bool isAsyncStateMachine = ca.AttributeType.FullName == "System.Runtime.CompilerServices.AsyncStateMachineAttribute";
foreach (var val in ca.ConstructorArguments) {
if (val.Value is TypeReference tr)
if (val.Value is TypeReference tr) {
namespaces.Add(tr.Namespace);
if (isAsyncStateMachine)
CollectNamespacesForDecompilation(new[] { tr.ResolveWithinSameModule() }, namespaces, visited);
}
}
}
}
@ -664,6 +668,17 @@ namespace ICSharpCode.Decompiler.CSharp @@ -664,6 +668,17 @@ namespace ICSharpCode.Decompiler.CSharp
CollectNamespacesForDecompilation(p.ParameterType, namespaces, visited);
}
}
if (methodDef.HasGenericParameters) {
foreach (var gp in methodDef.GenericParameters) {
if (gp.HasConstraints) {
foreach (var constraint in gp.Constraints) {
// Avoid infinite recursion
if (!(constraint is GenericInstanceType git && git.ElementType == gp.Owner))
CollectNamespacesForDecompilation(constraint, namespaces, visited);
}
}
}
}
if (methodDef.HasBody) {
CollectNamespacesForDecompilation(methodDef.Body, namespaces, visited);
}

Loading…
Cancel
Save