Browse Source

fix #557 - Missing namespaces when decompiling only a method

pull/569/head
Siegfried Pammer 11 years ago
parent
commit
5bb6e4b85b
  1. 5
      ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs

5
ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs

@ -38,14 +38,12 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
public void Run(AstNode compilationUnit) public void Run(AstNode compilationUnit)
{ {
if (!context.Settings.UsingDeclarations)
return;
// First determine all the namespaces that need to be imported: // First determine all the namespaces that need to be imported:
compilationUnit.AcceptVisitor(new FindRequiredImports(this), null); compilationUnit.AcceptVisitor(new FindRequiredImports(this), null);
importedNamespaces.Add("System"); // always import System, even when not necessary importedNamespaces.Add("System"); // always import System, even when not necessary
if (context.Settings.UsingDeclarations) {
// Now add using declarations for those namespaces: // Now add using declarations for those namespaces:
foreach (string ns in importedNamespaces.OrderByDescending(n => n)) { foreach (string ns in importedNamespaces.OrderByDescending(n => n)) {
// we go backwards (OrderByDescending) through the list of namespaces because we insert them backwards // we go backwards (OrderByDescending) through the list of namespaces because we insert them backwards
@ -57,6 +55,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
} }
compilationUnit.InsertChildAfter(null, new UsingDeclaration { Import = nsType }, SyntaxTree.MemberRole); compilationUnit.InsertChildAfter(null, new UsingDeclaration { Import = nsType }, SyntaxTree.MemberRole);
} }
}
if (!context.Settings.FullyQualifyAmbiguousTypeNames) if (!context.Settings.FullyQualifyAmbiguousTypeNames)
return; return;

Loading…
Cancel
Save