From 4d05fdbb017a3ca320aafdceb253c839cb94ea66 Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Mon, 18 Apr 2011 23:33:20 +0300 Subject: [PATCH] Add the OnDecompileFinished for method, property, event, field, assembly, namespace - this will be used when decompile a single method/property/event will be possible. --- ILSpy/CSharpLanguage.cs | 6 +++++- ILSpy/ILLanguage.cs | 15 ++++++++++++--- ILSpy/TextView/DecompilerTextView.cs | 11 ++++++++++- ILSpy/TreeNodes/MethodTreeNode.cs | 1 - ILSpy/TreeNodes/PropertyTreeNode.cs | 1 - 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/ILSpy/CSharpLanguage.cs b/ILSpy/CSharpLanguage.cs index 74c92f9ea..67ba3d078 100644 --- a/ILSpy/CSharpLanguage.cs +++ b/ILSpy/CSharpLanguage.cs @@ -92,6 +92,7 @@ namespace ICSharpCode.ILSpy codeDomBuilder.AddMethod(method); codeDomBuilder.RunTransformations(transformAbortCondition); codeDomBuilder.GenerateCode(output); + OnDecompilationFinished(new DecompileEventArgs { CodeMappings = codeDomBuilder.CodeMappings, LocalVariables = codeDomBuilder.LocalVariables }); } public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options) @@ -101,6 +102,7 @@ namespace ICSharpCode.ILSpy codeDomBuilder.AddProperty(property); codeDomBuilder.RunTransformations(transformAbortCondition); codeDomBuilder.GenerateCode(output); + OnDecompilationFinished(new DecompileEventArgs { CodeMappings = codeDomBuilder.CodeMappings, LocalVariables = codeDomBuilder.LocalVariables }); } public override void DecompileField(FieldDefinition field, ITextOutput output, DecompilationOptions options) @@ -110,6 +112,7 @@ namespace ICSharpCode.ILSpy codeDomBuilder.AddField(field); codeDomBuilder.RunTransformations(transformAbortCondition); codeDomBuilder.GenerateCode(output); + OnDecompilationFinished(null); } public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options) @@ -119,6 +122,7 @@ namespace ICSharpCode.ILSpy codeDomBuilder.AddEvent(ev); codeDomBuilder.RunTransformations(transformAbortCondition); codeDomBuilder.GenerateCode(output); + OnDecompilationFinished(new DecompileEventArgs { CodeMappings = codeDomBuilder.CodeMappings, LocalVariables = codeDomBuilder.LocalVariables }); } public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options) @@ -127,7 +131,6 @@ namespace ICSharpCode.ILSpy codeDomBuilder.AddType(type); codeDomBuilder.RunTransformations(transformAbortCondition); codeDomBuilder.GenerateCode(output); - OnDecompilationFinished(new DecompileEventArgs { CodeMappings = codeDomBuilder.CodeMappings, LocalVariables = codeDomBuilder.LocalVariables }); } @@ -148,6 +151,7 @@ namespace ICSharpCode.ILSpy codeDomBuilder.GenerateCode(output); } } + OnDecompilationFinished(null); } #region WriteProjectFile diff --git a/ILSpy/ILLanguage.cs b/ILSpy/ILLanguage.cs index 4bd5d77a9..ae503d23c 100644 --- a/ILSpy/ILLanguage.cs +++ b/ILSpy/ILLanguage.cs @@ -53,22 +53,29 @@ namespace ICSharpCode.ILSpy public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options) { - new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).DisassembleMethod(method); + var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + dis.DisassembleMethod(method); + OnDecompilationFinished(new DecompileEventArgs { CodeMappings = dis.CodeMappings }); } public override void DecompileField(FieldDefinition field, ITextOutput output, DecompilationOptions options) { new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).DisassembleField(field); + OnDecompilationFinished(null); } public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options) { - new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).DisassembleProperty(property); + var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + dis.DisassembleProperty(property); + OnDecompilationFinished(new DecompileEventArgs { CodeMappings = dis.CodeMappings }); } public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options) { - new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).DisassembleEvent(ev); + var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken); + dis.DisassembleEvent(ev); + OnDecompilationFinished(new DecompileEventArgs { CodeMappings = dis.CodeMappings }); } public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options) @@ -82,6 +89,7 @@ namespace ICSharpCode.ILSpy public override void DecompileNamespace(string nameSpace, IEnumerable types, ITextOutput output, DecompilationOptions options) { new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).DisassembleNamespace(nameSpace, types); + OnDecompilationFinished(null); } public override void DecompileAssembly(AssemblyDefinition assembly, string fileName, ITextOutput output, DecompilationOptions options) @@ -90,6 +98,7 @@ namespace ICSharpCode.ILSpy output.WriteLine(); new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).WriteAssemblyHeader(assembly); + OnDecompilationFinished(null); } public override string TypeToString(TypeReference t, bool includeNamespace, ICustomAttributeProvider attributeProvider) diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index 6a14bdb95..c07d657a8 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -449,17 +449,26 @@ namespace ICSharpCode.ILSpy.TextView static void DecompileNodes(DecompilationContext context, ITextOutput textOutput) { var nodes = context.TreeNodes; + context.Language.DecompileFinished += Language_DecompileFinished; for (int i = 0; i < nodes.Length; i++) { if (i > 0) textOutput.WriteLine(); - context.Language.DecompileFinished += (s, e) => { DebugData.CodeMappings = e.CodeMappings; DebugData.LocalVariables = e.LocalVariables; }; if (nodes[i] is IMemberTreeNode) { DebugData.CurrentMemberReference = (nodes[i] as IMemberTreeNode).Member; } context.Options.CancellationToken.ThrowIfCancellationRequested(); nodes[i].Decompile(context.Language, textOutput, context.Options); } + context.Language.DecompileFinished -= Language_DecompileFinished; + } + + static void Language_DecompileFinished(object sender, DecompileEventArgs e) + { + if (e != null) { + DebugData.CodeMappings = e.CodeMappings; + DebugData.LocalVariables = e.LocalVariables; + } } #endregion diff --git a/ILSpy/TreeNodes/MethodTreeNode.cs b/ILSpy/TreeNodes/MethodTreeNode.cs index 47f79c1ed..cc3d7864c 100644 --- a/ILSpy/TreeNodes/MethodTreeNode.cs +++ b/ILSpy/TreeNodes/MethodTreeNode.cs @@ -124,7 +124,6 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - DebugData.CurrentMemberReference = method; language.DecompileMethod(method, output, options); } diff --git a/ILSpy/TreeNodes/PropertyTreeNode.cs b/ILSpy/TreeNodes/PropertyTreeNode.cs index a59598648..5f6333485 100644 --- a/ILSpy/TreeNodes/PropertyTreeNode.cs +++ b/ILSpy/TreeNodes/PropertyTreeNode.cs @@ -147,7 +147,6 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - DebugData.CurrentMemberReference = property; language.DecompileProperty(property, output, options); }