Browse Source

Fix decompilation of assembly into single file.

pull/100/head
Daniel Grunwald 15 years ago
parent
commit
7eedd1b7ab
  1. 10
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 23
      ILSpy/CSharpLanguage.cs

10
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -91,14 +91,14 @@ namespace ICSharpCode.Decompiler.Ast
{ {
ConvertCustomAttributes(astCompileUnit, assemblyDefinition, AttributeTarget.Assembly); ConvertCustomAttributes(astCompileUnit, assemblyDefinition, AttributeTarget.Assembly);
ConvertCustomAttributes(astCompileUnit, assemblyDefinition.MainModule, AttributeTarget.Module); ConvertCustomAttributes(astCompileUnit, assemblyDefinition.MainModule, AttributeTarget.Module);
if (!onlyAssemblyLevel) { if (!onlyAssemblyLevel) {
foreach (TypeDefinition typeDef in assemblyDefinition.MainModule.Types) foreach (TypeDefinition typeDef in assemblyDefinition.MainModule.Types) {
{
// Skip nested types - they will be added by the parent type
if (typeDef.DeclaringType != null) continue;
// Skip the <Module> class // Skip the <Module> class
if (typeDef.Name == "<Module>") continue; if (typeDef.Name == "<Module>") continue;
// Skip any hidden types
if (AstBuilder.MemberIsHidden(typeDef, context.Settings))
continue;
AddType(typeDef); AddType(typeDef);
} }

23
ILSpy/CSharpLanguage.cs

@ -117,26 +117,15 @@ namespace ICSharpCode.ILSpy
public override void DecompileAssembly(AssemblyDefinition assembly, string fileName, ITextOutput output, DecompilationOptions options) public override void DecompileAssembly(AssemblyDefinition assembly, string fileName, ITextOutput output, DecompilationOptions options)
{ {
if (options.FullDecompilation) { if (options.FullDecompilation && options.SaveAsProjectDirectory != null) {
if (options.SaveAsProjectDirectory != null) { HashSet<string> directories = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
HashSet<string> directories = new HashSet<string>(StringComparer.OrdinalIgnoreCase); var files = WriteCodeFilesInProject(assembly, options, directories).ToList();
var files = WriteCodeFilesInProject(assembly, options, directories).ToList(); files.AddRange(WriteResourceFilesInProject(assembly, fileName, options, directories));
files.AddRange(WriteResourceFilesInProject(assembly, fileName, options, directories)); WriteProjectFile(new TextOutputWriter(output), files, assembly.MainModule);
WriteProjectFile(new TextOutputWriter(output), files, assembly.MainModule);
} else {
foreach (TypeDefinition type in assembly.MainModule.Types) {
if (AstBuilder.MemberIsHidden(type, options.DecompilerSettings))
continue;
AstBuilder codeDomBuilder = CreateAstBuilder(options, type);
codeDomBuilder.AddType(type);
codeDomBuilder.GenerateCode(output, transformAbortCondition);
output.WriteLine();
}
}
} else { } else {
base.DecompileAssembly(assembly, fileName, output, options); base.DecompileAssembly(assembly, fileName, output, options);
AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: null); AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: null);
codeDomBuilder.AddAssembly(assembly, onlyAssemblyLevel: true); codeDomBuilder.AddAssembly(assembly, onlyAssemblyLevel: !options.FullDecompilation);
codeDomBuilder.GenerateCode(output, transformAbortCondition); codeDomBuilder.GenerateCode(output, transformAbortCondition);
} }
} }

Loading…
Cancel
Save