diff --git a/ILSpy/AssemblyListTreeNode.cs b/ILSpy/AssemblyListTreeNode.cs
index 8bf3c8f3e..5e79209be 100644
--- a/ILSpy/AssemblyListTreeNode.cs
+++ b/ILSpy/AssemblyListTreeNode.cs
@@ -54,6 +54,8 @@ namespace ICSharpCode.ILSpy
{
if (data.GetDataPresent(AssemblyTreeNode.DataFormat))
return DropEffect.Move;
+ else if (data.GetDataPresent(DataFormats.FileDrop))
+ return DropEffect.Move;
else
return DropEffect.None;
}
@@ -61,8 +63,11 @@ namespace ICSharpCode.ILSpy
public override void Drop(IDataObject data, int index, DropEffect finalEffect)
{
string[] files = data.GetData(AssemblyTreeNode.DataFormat) as string[];
+ if (files == null)
+ files = data.GetData(DataFormats.FileDrop) as string[];
if (files != null) {
var nodes = (from file in files
+ where file != null
select OpenAssembly(file) into node
where node != null
select node).Distinct().ToList();
diff --git a/ILSpy/Decompiler/CSharpLanguage.cs b/ILSpy/Decompiler/CSharpLanguage.cs
new file mode 100644
index 000000000..db67dfda8
--- /dev/null
+++ b/ILSpy/Decompiler/CSharpLanguage.cs
@@ -0,0 +1,37 @@
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+using System;
+using Mono.Cecil;
+
+namespace ICSharpCode.ILSpy.Decompiler
+{
+ ///
+ /// Decompiler logic for C#.
+ ///
+ public class CSharpLanguage : Language
+ {
+ public override string Name {
+ get { return "C#"; }
+ }
+
+ public override void Decompile(MethodDefinition methodDefinition, ITextOutput output)
+ {
+ }
+ }
+}
diff --git a/ILSpy/EventTreeNode.cs b/ILSpy/EventTreeNode.cs
index e64595daa..fb08bd1be 100644
--- a/ILSpy/EventTreeNode.cs
+++ b/ILSpy/EventTreeNode.cs
@@ -1,5 +1,20 @@
-// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
-// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.TreeView;
diff --git a/ILSpy/Fusion.cs b/ILSpy/Fusion.cs
index d7c38081b..fc61d1375 100644
--- a/ILSpy/Fusion.cs
+++ b/ILSpy/Fusion.cs
@@ -1,5 +1,20 @@
-// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
-// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
diff --git a/ILSpy/IDecompilableNode.cs b/ILSpy/IDecompilableNode.cs
new file mode 100644
index 000000000..3d22e27f1
--- /dev/null
+++ b/ILSpy/IDecompilableNode.cs
@@ -0,0 +1,30 @@
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+using System;
+
+namespace ICSharpCode.ILSpy
+{
+ ///
+ /// Interface for decompilable tree nodes.
+ ///
+ public interface IDecompilableNode
+ {
+ void Decompile(Language language, ITextOutput output);
+ }
+}
diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj
index 0ec838ec5..4293e52aa 100644
--- a/ILSpy/ILSpy.csproj
+++ b/ILSpy/ILSpy.csproj
@@ -72,11 +72,14 @@
+
+
+
@@ -136,6 +139,7 @@
+
diff --git a/ILSpy/ITextOutput.cs b/ILSpy/ITextOutput.cs
new file mode 100644
index 000000000..dd6a4d241
--- /dev/null
+++ b/ILSpy/ITextOutput.cs
@@ -0,0 +1,104 @@
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+using System;
+using System.Text;
+using ICSharpCode.AvalonEdit.Document;
+
+namespace ICSharpCode.ILSpy
+{
+ public interface ITextOutput
+ {
+ void Indent();
+ void Unindent();
+ void Write(char ch);
+ void Write(string text);
+ void WriteComment(string comment);
+ void WriteLine();
+ void WriteDefinition(string text, object definition);
+ void WriteReference(string text, object definition);
+ }
+
+ sealed class SmartTextOutput : ITextOutput
+ {
+ readonly StringBuilder b = new StringBuilder();
+ int indent;
+ bool needsIndent;
+
+ public override string ToString()
+ {
+ return b.ToString();
+ }
+
+ public void Indent()
+ {
+ indent++;
+ }
+
+ public void Unindent()
+ {
+ indent--;
+ }
+
+ void WriteIndent()
+ {
+ if (needsIndent) {
+ needsIndent = false;
+ for (int i = 0; i < indent; i++) {
+ b.Append('\t');
+ }
+ }
+ }
+
+ public void Write(char ch)
+ {
+ WriteIndent();
+ b.Append(ch);
+ }
+
+ public void Write(string text)
+ {
+ WriteIndent();
+ b.Append(text);
+ }
+
+ public void WriteComment(string comment)
+ {
+ WriteIndent();
+ b.Append(comment);
+ }
+
+ public void WriteLine()
+ {
+ b.AppendLine();
+ needsIndent = true;
+ }
+
+ public void WriteDefinition(string text, object definition)
+ {
+ WriteIndent();
+ b.Append(text);
+ }
+
+ public void WriteReference(string text, object definition)
+ {
+ WriteIndent();
+ b.Append(text);
+ }
+ }
+}
diff --git a/ILSpy/Language.cs b/ILSpy/Language.cs
index 2c0848c78..b25863bc8 100644
--- a/ILSpy/Language.cs
+++ b/ILSpy/Language.cs
@@ -1,5 +1,20 @@
-// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
-// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
using System;
using Mono.Cecil;
@@ -11,20 +26,37 @@ namespace ICSharpCode.ILSpy
///
public abstract class Language
{
- public static readonly Language Current = Languages.IL;
+ public static readonly Language Current = new Decompiler.CSharpLanguage();
- public virtual string TypeToString(TypeReference t)
+ public abstract string Name { get; }
+
+ public virtual ICSharpCode.AvalonEdit.Highlighting.IHighlightingDefinition SyntaxHighlighting {
+ get { return ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinition(this.Name); }
+ }
+
+ public virtual void Decompile(MethodDefinition method, ITextOutput output)
{
- return t.Name;
}
- }
-
- public static class Languages
- {
- public static readonly Language IL = new ILLanguage();
- class ILLanguage : Language
+ public virtual void Decompile(PropertyDefinition property, ITextOutput output)
{
}
+
+ public virtual void Decompile(FieldDefinition field, ITextOutput output)
+ {
+ }
+
+ public virtual void Decompile(EventDefinition ev, ITextOutput output)
+ {
+ }
+
+ public virtual void Decompile(TypeDefinition type, ITextOutput output)
+ {
+ }
+
+ public string TypeToString(TypeReference t)
+ {
+ return t.Name;
+ }
}
}
diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs
index 393e65105..11ae89d64 100644
--- a/ILSpy/MainWindow.xaml.cs
+++ b/ILSpy/MainWindow.xaml.cs
@@ -22,7 +22,9 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
+using System.Windows.Controls;
using System.Windows.Input;
+
using ICSharpCode.TreeView;
using Microsoft.Win32;
@@ -67,6 +69,10 @@ namespace ICSharpCode.ILSpy
foreach (Assembly asm in initialAssemblies)
assemblyList.OpenAssembly(asm.Location);
+ string[] args = Environment.GetCommandLineArgs();
+ for (int i = 1; i < args.Length; i++) {
+ assemblyList.OpenAssembly(args[i]);
+ }
}
void OpenCommandExecuted(object sender, ExecutedRoutedEventArgs e)
@@ -116,5 +122,20 @@ namespace ICSharpCode.ILSpy
OpenFiles(dlg.SelectedFileNames);
}
}
+
+ void TreeView_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ try {
+ textEditor.SyntaxHighlighting = ILSpy.Language.Current.SyntaxHighlighting;
+ SmartTextOutput textOutput = new SmartTextOutput();
+ foreach (var node in treeView.SelectedItems.OfType()) {
+ node.Decompile(ILSpy.Language.Current, textOutput);
+ }
+ textEditor.Text = textOutput.ToString();
+ } catch (Exception ex) {
+ textEditor.SyntaxHighlighting = null;
+ textEditor.Text = ex.ToString();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/ILSpy/MethodTreeNode.cs b/ILSpy/MethodTreeNode.cs
index 2b34d2f87..117bdd597 100644
--- a/ILSpy/MethodTreeNode.cs
+++ b/ILSpy/MethodTreeNode.cs
@@ -26,7 +26,7 @@ namespace ICSharpCode.ILSpy
///
/// Tree Node representing a field, method, property, or event.
///
- public sealed class MethodTreeNode : SharpTreeNode
+ sealed class MethodTreeNode : SharpTreeNode, IDecompilableNode
{
MethodDefinition method;
@@ -65,5 +65,10 @@ namespace ICSharpCode.ILSpy
return Images.Method;
}
}
+
+ public void Decompile(Language language, ITextOutput output)
+ {
+ language.Decompile(method, output);
+ }
}
}
diff --git a/ILSpy/OpenFromGacDialog.xaml.cs b/ILSpy/OpenFromGacDialog.xaml.cs
index 92f30b68a..ac11c2e8e 100644
--- a/ILSpy/OpenFromGacDialog.xaml.cs
+++ b/ILSpy/OpenFromGacDialog.xaml.cs
@@ -1,5 +1,20 @@
-// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
-// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
diff --git a/ILSpy/PropertyTreeNode.cs b/ILSpy/PropertyTreeNode.cs
index a01349375..f88639d9c 100644
--- a/ILSpy/PropertyTreeNode.cs
+++ b/ILSpy/PropertyTreeNode.cs
@@ -1,5 +1,20 @@
-// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
-// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.TreeView;
diff --git a/ILSpy/ReferenceFolderTreeNode.cs b/ILSpy/ReferenceFolderTreeNode.cs
index 7fdcf4881..dd7bfe5cf 100644
--- a/ILSpy/ReferenceFolderTreeNode.cs
+++ b/ILSpy/ReferenceFolderTreeNode.cs
@@ -1,5 +1,20 @@
-// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
-// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
+// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.TreeView;