Browse Source

Merge branch 'master' of git://github.com/icsharpcode/ILSpy into Iconbar

pull/219/head
Eusebiu Marcu 15 years ago
parent
commit
fda1482469
  1. 57
      ILSpy.BamlDecompiler/BamlResourceEntryNode.cs
  2. 10
      ILSpy.BamlDecompiler/CecilType.cs
  3. 25
      ILSpy.BamlDecompiler/CecilTypeResolver.cs
  4. 22
      ILSpy.BamlDecompiler/Extensions.cs
  5. 2
      ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj
  6. 3
      ILSpy.BamlDecompiler/Properties/AssemblyInfo.cs
  7. 11
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/AppDomainTypeResolver.cs
  8. 6
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/DotNetType.cs
  9. 3
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IType.cs
  10. 2
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/ITypeResolver.cs
  11. 36
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KnownInfo.cs
  12. 58
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs
  13. 34
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlSimpleProperty.cs
  14. 3
      ILSpy.BamlDecompiler/Tests/Cases/Simple.xaml
  15. 26
      ILSpy.BamlDecompiler/Tests/Cases/Simple.xaml.cs
  16. 1
      ILSpy.BamlDecompiler/Tests/Cases/SimpleDictionary.xaml
  17. 112
      ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj
  18. 31
      ILSpy.BamlDecompiler/Tests/Properties/AssemblyInfo.cs
  19. 73
      ILSpy.BamlDecompiler/Tests/TestRunner.cs
  20. 12
      ILSpy.sln
  21. 36
      ILSpy/AnalyzerTreeView.cs
  22. 178
      ILSpy/Commands.cs
  23. 32
      ILSpy/Commands/BrowseBackCommand.cs
  24. 32
      ILSpy/Commands/BrowseForwardCommand.cs
  25. 58
      ILSpy/Commands/CommandWrapper.cs
  26. 69
      ILSpy/Commands/DecompileAllCommand.cs
  27. 31
      ILSpy/Commands/ExitCommand.cs
  28. 0
      ILSpy/Commands/ExportCommandAttribute.cs
  29. 33
      ILSpy/Commands/OpenCommand.cs
  30. 34
      ILSpy/Commands/OpenFromGacCommand.cs
  31. 33
      ILSpy/Commands/RefreshCommand.cs
  32. 32
      ILSpy/Commands/SaveCommand.cs
  33. 31
      ILSpy/Commands/ShowAnalyzerCommand.cs
  34. 39
      ILSpy/Commands/SimpleCommand.cs
  35. 28
      ILSpy/ILSpy.csproj
  36. 27
      ILSpy/IPane.cs
  37. BIN
      ILSpy/Images/Delete.png
  38. BIN
      ILSpy/Images/OverlayInternal.png
  39. BIN
      ILSpy/Images/OverlayProtected.png
  40. BIN
      ILSpy/Images/OverlayProtectedInternal.png
  41. 0
      ILSpy/Languages/CSharpLanguage.cs
  42. 0
      ILSpy/Languages/ILAstLanguage.cs
  43. 0
      ILSpy/Languages/ILLanguage.cs
  44. 40
      ILSpy/Languages/Language.cs
  45. 60
      ILSpy/Languages/Languages.cs
  46. 5
      ILSpy/LoadedAssembly.cs
  47. 8
      ILSpy/SearchPane.cs
  48. 6
      ILSpy/TreeNodes/Analyzer/AnalyzedEventFiredByTreeNode.cs
  49. 8
      ILSpy/TreeNodes/Analyzer/AnalyzedEventOverridesTreeNode.cs
  50. 11
      ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessTreeNode.cs
  51. 15
      ILSpy/TreeNodes/Analyzer/AnalyzedInterfaceEventImplementedByTreeNode.cs
  52. 15
      ILSpy/TreeNodes/Analyzer/AnalyzedInterfaceMethodImplementedByTreeNode.cs
  53. 15
      ILSpy/TreeNodes/Analyzer/AnalyzedInterfacePropertyImplementedByTreeNode.cs
  54. 10
      ILSpy/TreeNodes/Analyzer/AnalyzedMethodOverridesTreeNode.cs
  55. 7
      ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsedByTreeNode.cs
  56. 17
      ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsesTreeNode.cs
  57. 8
      ILSpy/TreeNodes/Analyzer/AnalyzedPropertyOverridesTreeNode.cs
  58. 33
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeExposedByTreeNode.cs
  59. 8
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeExtensionMethodsTreeNode.cs
  60. 11
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeInstantiationsTreeNode.cs
  61. 13
      ILSpy/TreeNodes/Analyzer/AnalyzedVirtualMethodUsedByTreeNode.cs
  62. 104
      ILSpy/TreeNodes/BaseTypesEntryNode.cs
  63. 96
      ILSpy/TreeNodes/BaseTypesTreeNode.cs
  64. 111
      ILSpy/TreeNodes/DerivedTypesEntryNode.cs
  65. 81
      ILSpy/TreeNodes/DerivedTypesTreeNode.cs
  66. 40
      ILSpy/TreeNodes/FilterResult.cs
  67. 58
      ILSpy/TreeNodes/ILSpyTreeNode.cs
  68. 3
      Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb.csproj

57
ILSpy.BamlDecompiler/BamlResourceEntryNode.cs

@ -3,14 +3,17 @@ @@ -3,14 +3,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.ILSpy;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
using Mono.Cecil;
using Ricciolo.StylesExplorer.MarkupReflection;
namespace ILSpy.BamlDecompiler
@ -45,17 +48,55 @@ namespace ILSpy.BamlDecompiler @@ -45,17 +48,55 @@ namespace ILSpy.BamlDecompiler
bool LoadBaml(AvalonEditTextOutput output)
{
var asm = this.Ancestors().OfType<AssemblyTreeNode>().FirstOrDefault().LoadedAssembly;
MemoryStream bamlStream = new MemoryStream();
Data.Position = 0;
Data.CopyTo(bamlStream);
bamlStream.Position = 0;
XDocument xamlDocument = LoadIntoDocument(asm.GetAssemblyResolver(), asm.AssemblyDefinition, Data);
output.Write(xamlDocument.ToString());
return true;
}
internal static XDocument LoadIntoDocument(IAssemblyResolver resolver, AssemblyDefinition asm, Stream stream)
{
XDocument xamlDocument;
using (XmlBamlReader reader = new XmlBamlReader(bamlStream, new CecilTypeResolver(asm)))
using (XmlBamlReader reader = new XmlBamlReader(stream, new CecilTypeResolver(resolver, asm)))
xamlDocument = XDocument.Load(reader);
ConvertToEmptyElements(xamlDocument.Root);
MoveNamespacesToRoot(xamlDocument);
return xamlDocument;
}
static void MoveNamespacesToRoot(XDocument xamlDocument)
{
var additionalXmlns = new List<XAttribute> {
new XAttribute("xmlns", XmlBamlReader.DefaultWPFNamespace),
new XAttribute(XName.Get("x", XNamespace.Xmlns.NamespaceName), XmlBamlReader.XWPFNamespace)
};
output.Write(xamlDocument.ToString());
return true;
foreach (var element in xamlDocument.Root.DescendantsAndSelf()) {
if (element.Name.NamespaceName != XmlBamlReader.DefaultWPFNamespace && !additionalXmlns.Any(ka => ka.Value == element.Name.NamespaceName)) {
string newPrefix = new string(element.Name.LocalName.Where(c => char.IsUpper(c)).ToArray()).ToLowerInvariant();
int current = additionalXmlns.Count(ka => ka.Name.Namespace == XNamespace.Xmlns && ka.Name.LocalName.TrimEnd(ch => char.IsNumber(ch)) == newPrefix);
if (current > 0)
newPrefix += (current + 1).ToString();
XName defaultXmlns = XName.Get(newPrefix, XNamespace.Xmlns.NamespaceName);
if (element.Name.NamespaceName != XmlBamlReader.DefaultWPFNamespace)
additionalXmlns.Add(new XAttribute(defaultXmlns, element.Name.NamespaceName));
}
}
foreach (var xmlns in additionalXmlns.Except(xamlDocument.Root.Attributes())) {
xamlDocument.Root.Add(xmlns);
}
}
static void ConvertToEmptyElements(XElement element)
{
foreach (var el in element.Elements()) {
if (!el.IsEmpty && !el.HasElements && el.Value == "") {
el.RemoveNodes();
continue;
}
ConvertToEmptyElements(el);
}
}
}
}

10
ILSpy.BamlDecompiler/CecilType.cs

@ -67,5 +67,15 @@ namespace ILSpy.BamlDecompiler @@ -67,5 +67,15 @@ namespace ILSpy.BamlDecompiler
{
return string.Format("[CecilType Type={0}]", type);
}
public IType BaseType {
get {
TypeDefinition td = type.BaseType.Resolve();
if (td == null)
throw new Exception("could not resolve '" + type.BaseType.FullName + "'!");
return new CecilType(td);
}
}
}
}

25
ILSpy.BamlDecompiler/CecilTypeResolver.cs

@ -14,11 +14,18 @@ namespace ILSpy.BamlDecompiler @@ -14,11 +14,18 @@ namespace ILSpy.BamlDecompiler
/// </summary>
public class CecilTypeResolver : ITypeResolver
{
LoadedAssembly assembly;
IAssemblyResolver resolver;
AssemblyDefinition thisAssembly;
public CecilTypeResolver(LoadedAssembly assembly)
public CecilTypeResolver(IAssemblyResolver resolver, AssemblyDefinition asm)
{
this.assembly = assembly;
this.resolver = resolver;
this.thisAssembly = asm;
}
public bool IsLocalAssembly(string name)
{
return name == this.thisAssembly.Name.Name;
}
public IType GetTypeByAssemblyQualifiedName(string name)
@ -31,12 +38,12 @@ namespace ILSpy.BamlDecompiler @@ -31,12 +38,12 @@ namespace ILSpy.BamlDecompiler
string fullName = name.Substring(0, comma);
string assemblyName = name.Substring(comma + 1).Trim();
var type = assembly.AssemblyDefinition.MainModule.GetType(fullName);
var type = thisAssembly.MainModule.GetType(fullName);
if (type == null) {
var otherAssembly = assembly.LookupReferencedAssembly(assemblyName);
var otherAssembly = resolver.Resolve(assemblyName);
if (otherAssembly == null)
throw new Exception("could not resolve '" + assemblyName + "'!");
type = otherAssembly.AssemblyDefinition.MainModule.GetType(fullName);
type = otherAssembly.MainModule.GetType(fullName);
}
return new CecilType(type);
@ -49,5 +56,11 @@ namespace ILSpy.BamlDecompiler @@ -49,5 +56,11 @@ namespace ILSpy.BamlDecompiler
return new CecilDependencyPropertyDescriptor(name, ((CecilType)ownerType).type);
}
public string RuntimeVersion {
get {
return thisAssembly.MainModule.Runtime.ToString();
}
}
}
}

22
ILSpy.BamlDecompiler/Extensions.cs

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Linq;
namespace ILSpy.BamlDecompiler
{
public static class Extensions
{
public static string TrimEnd(this string target, Func<char, bool> predicate)
{
if (target == null)
throw new ArgumentNullException("target");
while (predicate(target.LastOrDefault()))
target = target.Remove(target.Length - 1);
return target;
}
}
}

2
ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj

@ -77,6 +77,7 @@ @@ -77,6 +77,7 @@
<Compile Include="CecilDependencyPropertyDescriptor.cs" />
<Compile Include="CecilType.cs" />
<Compile Include="CecilTypeResolver.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\AppDomainTypeResolver.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\BamlAssembly.cs" />
@ -97,6 +98,7 @@ @@ -97,6 +98,7 @@
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlProperty.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlPropertyElement.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlReader.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlSimpleProperty.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlBamlText.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlNamespace.cs" />
<Compile Include="Ricciolo.StylesExplorer.MarkupReflection\XmlPIMapping.cs" />

3
ILSpy.BamlDecompiler/Properties/AssemblyInfo.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
#endregion
@ -22,6 +23,8 @@ using System.Runtime.InteropServices; @@ -22,6 +23,8 @@ using System.Runtime.InteropServices;
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
[assembly: InternalsVisibleTo("ILSpy.BamlDecompiler.Tests")]
// The assembly version has following format :
//
// Major.Minor.Build.Revision

11
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/AppDomainTypeResolver.cs

@ -131,6 +131,17 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -131,6 +131,17 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
return null;
}
}
public bool IsLocalAssembly(string name)
{
return false;
}
public string RuntimeVersion {
get {
throw new NotImplementedException();
}
}
#endregion

6
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/DotNetType.cs

@ -42,6 +42,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -42,6 +42,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
if (_type == null) return false;
return this._type.Equals(((DotNetType)type).Type);
}
public IType BaseType {
get {
return new DotNetType(this._type.BaseType.AssemblyQualifiedName);
}
}
#endregion

3
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/IType.cs

@ -8,10 +8,11 @@ using System.Text; @@ -8,10 +8,11 @@ using System.Text;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
/// <summary>
/// Interface rappresenting a DotNet type
/// Interface representing a DotNet type
/// </summary>
public interface IType
{
IType BaseType { get; }
string AssemblyQualifiedName { get; }
bool IsSubclassOf(IType type);
bool Equals(IType type);

2
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/ITypeResolver.cs

@ -9,6 +9,8 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -9,6 +9,8 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{
public interface ITypeResolver
{
string RuntimeVersion { get; }
bool IsLocalAssembly(string name);
IType GetTypeByAssemblyQualifiedName(string name);
IDependencyPropertyDescriptor GetDependencyPropertyDescriptor(string name, IType ownerType, IType targetType);
}

36
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/KnownInfo.cs

@ -34,12 +34,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -34,12 +34,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
public KnownInfo(ITypeResolver resolver)
{
KnownAssemblyTable = new string[5];
KnownAssemblyTable[0] = "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[1] = "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[2] = "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[3] = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[4] = "WindowBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
switch (resolver.RuntimeVersion) {
case "Net_2_0":
LoadKnownAssemblies30();
break;
case "Net_4_0":
LoadKnownAssemblies40();
break;
default:
throw new NotSupportedException();
}
KnownTypeTable = new TypeDeclaration[760];
KnownTypeTable[0] = new TypeDeclaration(resolver, string.Empty, string.Empty, 0);
@ -1305,6 +1309,26 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -1305,6 +1309,26 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
KnownResourceTable.Add(0xa9, new ResourceName("SystemParameters.WorkArea"));
}
void LoadKnownAssemblies30()
{
KnownAssemblyTable = new string[5];
KnownAssemblyTable[0] = "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[1] = "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[2] = "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[3] = "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[4] = "WindowBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
}
void LoadKnownAssemblies40()
{
KnownAssemblyTable = new string[5];
KnownAssemblyTable[0] = "PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[1] = "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
KnownAssemblyTable[2] = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[3] = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
KnownAssemblyTable[4] = "WindowBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
}
#endregion
public bool IsKnownType(string type)

58
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

@ -8,6 +8,7 @@ using System.ComponentModel; @@ -8,6 +8,7 @@ using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
@ -54,6 +55,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -54,6 +55,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
private readonly TypeDeclaration XamlTypeDeclaration;
private readonly XmlNameTable _nameTable = new NameTable();
private IDictionary<string, string> _rootNamespaces;
public const string XWPFNamespace = "http://schemas.microsoft.com/winfx/2006/xaml";
public const string DefaultWPFNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
#endregion
@ -159,7 +163,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -159,7 +163,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
public override bool MoveToFirstAttribute()
{
intoAttribute = false;
if (nodes.Count > 0 && nodes.Peek() is XmlBamlProperty)
if (nodes.Count > 0 && (nodes.Peek() is XmlBamlProperty || nodes.Peek() is XmlBamlSimpleProperty))
{
_currentNode = nodes.Dequeue();
return true;
@ -178,7 +182,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -178,7 +182,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
public override bool MoveToNextAttribute()
{
intoAttribute = false;
if (nodes.Count > 0 && nodes.Peek() is XmlBamlProperty)
if (nodes.Count > 0 && (nodes.Peek() is XmlBamlProperty || nodes.Peek() is XmlBamlSimpleProperty))
{
_currentNode = nodes.Dequeue();
return true;
@ -196,7 +200,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -196,7 +200,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
///
public override bool MoveToElement()
{
while (nodes.Peek() is XmlBamlProperty)
while (nodes.Peek() is XmlBamlProperty || nodes.Peek() is XmlBamlSimpleProperty)
{
nodes.Dequeue();
}
@ -284,13 +288,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -284,13 +288,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
else
currentType = (BamlRecordType)type;
if (currentType.ToString().EndsWith("End"))
Debug.Unindent();
Debug.WriteLine(currentType);
if (currentType.ToString().StartsWith("Start"))
Debug.Indent();
// Debug.WriteLine(currentType);
}
private bool SetNextNode()
@ -300,6 +298,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -300,6 +298,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
_currentNode = nodes.Dequeue();
if ((_currentNode is XmlBamlProperty)) continue;
if ((_currentNode is XmlBamlSimpleProperty)) continue;
if (this.NodeType == XmlNodeType.EndElement)
{
@ -451,7 +450,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -451,7 +450,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
break;
default:
throw new NotImplementedException("UnsupportedNode: " + currentType);
break;
}
}
@ -586,7 +584,10 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -586,7 +584,10 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
String localName = String.Empty;
XmlBamlNode node = this.CurrentNode;
if (node is XmlBamlProperty)
if (node is XmlBamlSimpleProperty) {
var simpleNode = (XmlBamlSimpleProperty)node;
localName = simpleNode.LocalName;
} else if (node is XmlBamlProperty)
{
PropertyDeclaration pd = ((XmlBamlProperty)node).PropertyDeclaration;
localName = FormatPropertyDeclaration(pd, false, true, true);
@ -1057,9 +1058,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -1057,9 +1058,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
private void ReadPropertyComplexEnd()
{
if (!(elements.Peek() is XmlBamlPropertyElement))
throw new InvalidCastException();
XmlBamlPropertyElement propertyElement = (XmlBamlPropertyElement) elements.Peek();
CloseElement();
@ -1191,10 +1189,22 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -1191,10 +1189,22 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
}
else
element = new XmlBamlElement();
// the type is defined in the local assembly, i.e., the main assembly
// and this is the root element
TypeDeclaration oldDeclaration = null;
if (_resolver.IsLocalAssembly(declaration.Assembly) && parentElement == null) {
oldDeclaration = declaration;
declaration = GetKnownTypeDeclarationByName(declaration.Type.BaseType.AssemblyQualifiedName);
}
element.TypeDeclaration = declaration;
elements.Push(element);
nodes.Enqueue(element);
if (oldDeclaration != null) {
nodes.Enqueue(new XmlBamlSimpleProperty(XWPFNamespace, "Class", string.Format("{0}.{1}", oldDeclaration.Namespace, oldDeclaration.Name)));
}
if (parentElement != null && complexPropertyOpened == 0)
{
@ -1572,6 +1582,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -1572,6 +1582,16 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
return declaration;
}
TypeDeclaration GetKnownTypeDeclarationByName(string name)
{
foreach (var type in KnownInfo.KnownTypeTable) {
if (name == string.Format("{0}.{1}, {2}", type.Namespace, type.Name, type.Assembly))
return type;
}
throw new NotSupportedException();
}
internal string GetAssembly(short identifier)
{
@ -1602,7 +1622,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -1602,7 +1622,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
TypeDeclaration declaration;
XmlBamlNode node = this.CurrentNode;
if (node is XmlBamlProperty)
if (node is XmlBamlSimpleProperty)
return ((XmlBamlSimpleProperty)node).NamespaceName;
else if (node is XmlBamlProperty)
{
declaration = ((XmlBamlProperty)node).PropertyDeclaration.DeclaringType;
TypeDeclaration elementDeclaration = this.readingElements.Peek().TypeDeclaration;
@ -1678,7 +1700,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -1678,7 +1700,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
get
{
XmlBamlNode node = this.CurrentNode;
if (node is XmlBamlProperty)
if (node is XmlBamlSimpleProperty)
return ((XmlBamlSimpleProperty)node).Value;
else if (node is XmlBamlProperty)
return ((XmlBamlProperty)node).Value.ToString();
else if (node is XmlBamlText)
return ((XmlBamlText)node).Text;

34
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlSimpleProperty.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Ricciolo.StylesExplorer.MarkupReflection
{
class XmlBamlSimpleProperty : XmlBamlNode
{
public string NamespaceName { get; private set; }
public string LocalName { get; private set; }
public string Value { get; private set; }
public XmlBamlSimpleProperty(string namespaceName, string localName, string value)
{
if (string.IsNullOrWhiteSpace(namespaceName))
throw new ArgumentException("namespaceName");
if (string.IsNullOrWhiteSpace(localName))
throw new ArgumentException("localName");
if (value == null)
throw new ArgumentNullException("value");
this.NamespaceName = namespaceName;
this.LocalName = localName;
this.Value = value;
}
public override XmlNodeType NodeType {
get { return XmlNodeType.Attribute; }
}
}
}

3
ILSpy.BamlDecompiler/Tests/Cases/Simple.xaml

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
<Window x:Class="ILSpy.BamlDecompiler.Tests.Cases.Simple" Title="ILSpy.BamlDecompiler.Tests.Cases" Height="300" Width="300" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid />
</Window>

26
ILSpy.BamlDecompiler/Tests/Cases/Simple.xaml.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace ILSpy.BamlDecompiler.Tests.Cases
{
/// <summary>
/// Interaction logic for Simple.xaml
/// </summary>
public partial class Simple : Window
{
public Simple()
{
InitializeComponent();
}
}
}

1
ILSpy.BamlDecompiler/Tests/Cases/SimpleDictionary.xaml

@ -0,0 +1 @@ @@ -0,0 +1 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"></ResourceDictionary>

112
ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj

@ -0,0 +1,112 @@ @@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{1169E6D1-1899-43D4-A500-07CE4235B388}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ILSpy.BamlDecompiler.Tests</RootNamespace>
<AssemblyName>ILSpy.BamlDecompiler.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>..\bin\Debug\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\bin\Release\</OutputPath>
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="DiffLib">
<HintPath>..\..\packages\DiffLib.1.0.0.55\lib\net35-Client\DiffLib.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\..\ICSharpCode.Decompiler\Tests\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework" />
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Cases\Simple.xaml.cs">
<DependentUpon>Simple.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestRunner.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ICSharpCode.Decompiler\Tests\ICSharpCode.Decompiler.Tests.csproj">
<Project>{FEC0DA52-C4A6-4710-BE36-B484A20C5E22}</Project>
<Name>ICSharpCode.Decompiler.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\..\ILSpy\ILSpy.csproj">
<Project>{1E85EFF9-E370-4683-83E4-8A3D063FF791}</Project>
<Name>ILSpy</Name>
</ProjectReference>
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\..\SharpTreeView\ICSharpCode.TreeView.csproj">
<Project>{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}</Project>
<Name>ICSharpCode.TreeView</Name>
</ProjectReference>
<ProjectReference Include="..\ILSpy.BamlDecompiler.csproj">
<Project>{A6BAD2BA-76BA-461C-8B6D-418607591247}</Project>
<Name>ILSpy.BamlDecompiler</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Cases" />
<Folder Include="Properties" />
</ItemGroup>
<ItemGroup>
<Page Include="Cases\Simple.xaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Page>
<Page Include="Cases\SimpleDictionary.xaml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

31
ILSpy.BamlDecompiler/Tests/Properties/AssemblyInfo.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
#region Using directives
using System;
using System.Reflection;
using System.Runtime.InteropServices;
#endregion
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ILSpy.BamlDecompiler.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ILSpy.BamlDecompiler.Tests")]
[assembly: AssemblyCopyright("Copyright 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]

73
ILSpy.BamlDecompiler/Tests/TestRunner.cs

@ -0,0 +1,73 @@ @@ -0,0 +1,73 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Resources;
using System.Xml.Linq;
using ICSharpCode.Decompiler.Tests.Helpers;
using ICSharpCode.ILSpy;
using Mono.Cecil;
using NUnit.Framework;
using Ricciolo.StylesExplorer.MarkupReflection;
namespace ILSpy.BamlDecompiler.Tests
{
[TestFixture]
public class TestRunner
{
[Test]
public void Simple()
{
RunTest("cases/simple");
}
[Test]
public void SimpleDictionary()
{
RunTest("cases/simpledictionary");
}
void RunTest(string name)
{
string asmPath = typeof(TestRunner).Assembly.Location;
var assembly = AssemblyDefinition.ReadAssembly(asmPath);
Resource res = assembly.MainModule.Resources.First();
Stream bamlStream = LoadBaml(res, name + ".baml");
Assert.IsNotNull(bamlStream);
XDocument document = BamlResourceEntryNode.LoadIntoDocument(new DefaultAssemblyResolver(), assembly, bamlStream);
string path = Path.Combine("..\\..\\Tests", name + ".xaml");
CodeAssert.AreEqual(document.ToString(), File.ReadAllText(path));
}
Stream LoadBaml(Resource res, string name)
{
EmbeddedResource er = res as EmbeddedResource;
if (er != null) {
Stream s = er.GetResourceStream();
s.Position = 0;
ResourceReader reader;
try {
reader = new ResourceReader(s);
}
catch (ArgumentException) {
return null;
}
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) {
if (entry.Key.ToString() == name) {
if (entry.Value is Stream)
return (Stream)entry.Value;
if (entry.Value is byte[])
return new MemoryStream((byte[])entry.Value);
}
}
}
return null;
}
}
}

12
ILSpy.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.1.7146
# SharpDevelop 4.1.0.7466-alpha
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{F45DB999-7E72-4000-B5AD-3A7B485A0896}"
ProjectSection(SolutionItems) = postProject
doc\Command Line.txt = doc\Command Line.txt
@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Pdb", "Mono.Ceci @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Pdb", "Mono.Ceci
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.BamlDecompiler", "ILSpy.BamlDecompiler\ILSpy.BamlDecompiler.csproj", "{A6BAD2BA-76BA-461C-8B6D-418607591247}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.BamlDecompiler.Tests", "ILSpy.BamlDecompiler\Tests\ILSpy.BamlDecompiler.Tests.csproj", "{1169E6D1-1899-43D4-A500-07CE4235B388}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -115,6 +117,14 @@ Global @@ -115,6 +117,14 @@ Global
{A6BAD2BA-76BA-461C-8B6D-418607591247}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6BAD2BA-76BA-461C-8B6D-418607591247}.Release|x86.Build.0 = Release|x86
{A6BAD2BA-76BA-461C-8B6D-418607591247}.Release|x86.ActiveCfg = Release|x86
{1169E6D1-1899-43D4-A500-07CE4235B388}.Debug|Any CPU.Build.0 = Debug|x86
{1169E6D1-1899-43D4-A500-07CE4235B388}.Debug|Any CPU.ActiveCfg = Debug|x86
{1169E6D1-1899-43D4-A500-07CE4235B388}.Debug|x86.Build.0 = Debug|x86
{1169E6D1-1899-43D4-A500-07CE4235B388}.Debug|x86.ActiveCfg = Debug|x86
{1169E6D1-1899-43D4-A500-07CE4235B388}.Release|Any CPU.Build.0 = Release|x86
{1169E6D1-1899-43D4-A500-07CE4235B388}.Release|Any CPU.ActiveCfg = Release|x86
{1169E6D1-1899-43D4-A500-07CE4235B388}.Release|x86.Build.0 = Release|x86
{1169E6D1-1899-43D4-A500-07CE4235B388}.Release|x86.ActiveCfg = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

36
ILSpy/AnalyzerTreeView.cs

@ -17,15 +17,6 @@ @@ -17,15 +17,6 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.ILSpy.TreeNodes.Analyzer;
using ICSharpCode.TreeView;
@ -37,9 +28,11 @@ namespace ICSharpCode.ILSpy @@ -37,9 +28,11 @@ namespace ICSharpCode.ILSpy
public partial class AnalyzerTreeView : SharpTreeView, IPane
{
static AnalyzerTreeView instance;
public static AnalyzerTreeView Instance {
get {
public static AnalyzerTreeView Instance
{
get
{
if (instance == null) {
App.Current.VerifyAccess();
instance = new AnalyzerTreeView();
@ -47,42 +40,33 @@ namespace ICSharpCode.ILSpy @@ -47,42 +40,33 @@ namespace ICSharpCode.ILSpy
return instance;
}
}
private AnalyzerTreeView()
{
this.ShowRoot = false;
this.Root = new AnalyzerTreeNode { Language = MainWindow.Instance.CurrentLanguage };
ContextMenuProvider.Add(this);
}
public void Show()
{
if (!IsVisible)
MainWindow.Instance.ShowInBottomPane("Analyzer", this);
}
public void Show(AnalyzerTreeNode node)
{
Show();
node.IsExpanded = true;
this.Root.Children.Add(node);
this.SelectedItem = node;
this.FocusNode(node);
}
void IPane.Closed()
{
this.Root.Children.Clear();
}
}
[ExportMainMenuCommand(Menu = "_View", Header = "_Analyzer", MenuCategory = "ShowPane", MenuOrder = 100)]
sealed class ShowAnalyzerCommand : SimpleCommand
{
public override void Execute(object parameter)
{
AnalyzerTreeView.Instance.Show();
}
}
}

178
ILSpy/Commands.cs

@ -1,178 +0,0 @@ @@ -1,178 +0,0 @@
// 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.ComponentModel.Composition;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
namespace ICSharpCode.ILSpy
{
[ExportMainMenuCommand(Menu = "_File", Header = "E_xit", MenuOrder = 99999, MenuCategory = "Exit")]
sealed class ExitCommand : SimpleCommand
{
public override void Execute(object parameter)
{
MainWindow.Instance.Close();
}
}
[ExportToolbarCommand(ToolTip = "Back", ToolbarIcon = "Images/Back.png", ToolbarCategory = "Navigation", ToolbarOrder = 0)]
sealed class BrowseBackCommand : CommandWrapper {
public BrowseBackCommand() : base(NavigationCommands.BrowseBack) {}
}
[ExportToolbarCommand(ToolTip = "Forward", ToolbarIcon = "Images/Forward.png", ToolbarCategory = "Navigation", ToolbarOrder = 1)]
sealed class BrowseForwardCommand : CommandWrapper {
public BrowseForwardCommand() : base(NavigationCommands.BrowseForward) {}
}
[ExportToolbarCommand(ToolTip = "Open", ToolbarIcon = "Images/Open.png", ToolbarCategory = "Open", ToolbarOrder = 0)]
[ExportMainMenuCommand(Menu = "_File", MenuIcon = "Images/Open.png", MenuCategory = "Open", MenuOrder = 0)]
sealed class OpenCommand : CommandWrapper {
public OpenCommand() : base(ApplicationCommands.Open) {}
}
[ExportMainMenuCommand(Menu = "_File", Header = "Open from _GAC", MenuCategory = "Open", MenuOrder = 1)]
sealed class OpenFromGacCommand : SimpleCommand
{
public override void Execute(object parameter)
{
OpenFromGacDialog dlg = new OpenFromGacDialog();
dlg.Owner = MainWindow.Instance;
if (dlg.ShowDialog() == true) {
MainWindow.Instance.OpenFiles(dlg.SelectedFileNames);
}
}
}
[ExportToolbarCommand(ToolTip = "Reload all assemblies", ToolbarIcon = "Images/Refresh.png", ToolbarCategory = "Open", ToolbarOrder = 2)]
[ExportMainMenuCommand(Menu = "_File", Header = "Reload", MenuIcon = "Images/Refresh.png", MenuCategory = "Open", MenuOrder = 2)]
sealed class RefreshCommand : CommandWrapper {
public RefreshCommand() : base(NavigationCommands.Refresh) {}
}
[ExportMainMenuCommand(Menu = "_File", Header = "_Save Code...", MenuIcon = "Images/SaveFile.png", MenuCategory = "Save", MenuOrder = 0)]
sealed class SaveCommand : CommandWrapper
{
public SaveCommand() : base(ApplicationCommands.Save) {}
}
#if DEBUG
[ExportMainMenuCommand(Menu = "_File", Header = "DEBUG -- Decompile All", MenuCategory = "Open", MenuOrder = 2.5)]
sealed class DecompileAllCommand : SimpleCommand
{
public override bool CanExecute(object parameter)
{
return System.IO.Directory.Exists("c:\\temp\\decompiled");
}
public override void Execute(object parameter)
{
MainWindow.Instance.TextView.RunWithCancellation(
ct => Task<AvalonEditTextOutput>.Factory.StartNew(
() => {
AvalonEditTextOutput output = new AvalonEditTextOutput();
Parallel.ForEach(
MainWindow.Instance.CurrentAssemblyList.GetAssemblies(),
new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = ct },
delegate (LoadedAssembly asm) {
if (!asm.HasLoadError) {
Stopwatch w = Stopwatch.StartNew();
Exception exception = null;
using (var writer = new System.IO.StreamWriter("c:\\temp\\decompiled\\" + asm.ShortName + ".cs")) {
try {
new CSharpLanguage().DecompileAssembly(
asm, new Decompiler.PlainTextOutput(writer),
new DecompilationOptions { FullDecompilation = true, CancellationToken = ct });
} catch (Exception ex) {
writer.WriteLine(ex.ToString());
exception = ex;
}
}
lock (output) {
output.Write(asm.ShortName + " - " + w.Elapsed);
if (exception != null) {
output.Write(" - ");
output.Write(exception.GetType().Name);
}
output.WriteLine();
}
}
});
return output;
}
),
task => MainWindow.Instance.TextView.ShowText(task.Result));
}
}
#endif
class CommandWrapper : ICommand
{
ICommand wrappedCommand;
public CommandWrapper(ICommand wrappedCommand)
{
this.wrappedCommand = wrappedCommand;
}
public static ICommand Unwrap(ICommand command)
{
CommandWrapper w = command as CommandWrapper;
if (w != null)
return w.wrappedCommand;
else
return command;
}
public event EventHandler CanExecuteChanged {
add { wrappedCommand.CanExecuteChanged += value; }
remove { wrappedCommand.CanExecuteChanged -= value; }
}
public void Execute(object parameter)
{
wrappedCommand.Execute(parameter);
}
public bool CanExecute(object parameter)
{
return wrappedCommand.CanExecute(parameter);
}
}
public abstract class SimpleCommand : ICommand
{
public event EventHandler CanExecuteChanged {
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public abstract void Execute(object parameter);
public virtual bool CanExecute(object parameter)
{
return true;
}
}
}

32
ILSpy/Commands/BrowseBackCommand.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// 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.Windows.Input;
namespace ICSharpCode.ILSpy
{
[ExportToolbarCommand(ToolTip = "Back", ToolbarIcon = "Images/Back.png", ToolbarCategory = "Navigation", ToolbarOrder = 0)]
sealed class BrowseBackCommand : CommandWrapper
{
public BrowseBackCommand()
: base(NavigationCommands.BrowseBack)
{
}
}
}

32
ILSpy/Commands/BrowseForwardCommand.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// 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.Windows.Input;
namespace ICSharpCode.ILSpy
{
[ExportToolbarCommand(ToolTip = "Forward", ToolbarIcon = "Images/Forward.png", ToolbarCategory = "Navigation", ToolbarOrder = 1)]
sealed class BrowseForwardCommand : CommandWrapper
{
public BrowseForwardCommand()
: base(NavigationCommands.BrowseForward)
{
}
}
}

58
ILSpy/Commands/CommandWrapper.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// 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.Windows.Input;
namespace ICSharpCode.ILSpy
{
class CommandWrapper : ICommand
{
private ICommand wrappedCommand;
public CommandWrapper(ICommand wrappedCommand)
{
this.wrappedCommand = wrappedCommand;
}
public static ICommand Unwrap(ICommand command)
{
CommandWrapper w = command as CommandWrapper;
if (w != null)
return w.wrappedCommand;
else
return command;
}
public event EventHandler CanExecuteChanged
{
add { wrappedCommand.CanExecuteChanged += value; }
remove { wrappedCommand.CanExecuteChanged -= value; }
}
public void Execute(object parameter)
{
wrappedCommand.Execute(parameter);
}
public bool CanExecute(object parameter)
{
return wrappedCommand.CanExecute(parameter);
}
}
}

69
ILSpy/Commands/DecompileAllCommand.cs

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
// 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.
#if DEBUG
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using ICSharpCode.ILSpy.TextView;
namespace ICSharpCode.ILSpy
{
[ExportMainMenuCommand(Menu = "_File", Header = "DEBUG -- Decompile All", MenuCategory = "Open", MenuOrder = 2.5)]
sealed class DecompileAllCommand : SimpleCommand
{
public override bool CanExecute(object parameter)
{
return System.IO.Directory.Exists("c:\\temp\\decompiled");
}
public override void Execute(object parameter)
{
MainWindow.Instance.TextView.RunWithCancellation(ct => Task<AvalonEditTextOutput>.Factory.StartNew(() => {
AvalonEditTextOutput output = new AvalonEditTextOutput();
Parallel.ForEach(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = ct }, delegate(LoadedAssembly asm) {
if (!asm.HasLoadError) {
Stopwatch w = Stopwatch.StartNew();
Exception exception = null;
using (var writer = new System.IO.StreamWriter("c:\\temp\\decompiled\\" + asm.ShortName + ".cs")) {
try {
new CSharpLanguage().DecompileAssembly(asm, new Decompiler.PlainTextOutput(writer), new DecompilationOptions { FullDecompilation = true, CancellationToken = ct });
}
catch (Exception ex) {
writer.WriteLine(ex.ToString());
exception = ex;
}
}
lock (output) {
output.Write(asm.ShortName + " - " + w.Elapsed);
if (exception != null) {
output.Write(" - ");
output.Write(exception.GetType().Name);
}
output.WriteLine();
}
}
});
return output;
}), task => MainWindow.Instance.TextView.ShowText(task.Result));
}
}
}
#endif

31
ILSpy/Commands/ExitCommand.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
// 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
{
[ExportMainMenuCommand(Menu = "_File", Header = "E_xit", MenuOrder = 99999, MenuCategory = "Exit")]
sealed class ExitCommand : SimpleCommand
{
public override void Execute(object parameter)
{
MainWindow.Instance.Close();
}
}
}

0
ILSpy/ExportCommandAttribute.cs → ILSpy/Commands/ExportCommandAttribute.cs

33
ILSpy/Commands/OpenCommand.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
// 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.Windows.Input;
namespace ICSharpCode.ILSpy
{
[ExportToolbarCommand(ToolTip = "Open", ToolbarIcon = "Images/Open.png", ToolbarCategory = "Open", ToolbarOrder = 0)]
[ExportMainMenuCommand(Menu = "_File", MenuIcon = "Images/Open.png", MenuCategory = "Open", MenuOrder = 0)]
sealed class OpenCommand : CommandWrapper
{
public OpenCommand()
: base(ApplicationCommands.Open)
{
}
}
}

34
ILSpy/Commands/OpenFromGacCommand.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
// 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
{
[ExportMainMenuCommand(Menu = "_File", Header = "Open from _GAC", MenuCategory = "Open", MenuOrder = 1)]
sealed class OpenFromGacCommand : SimpleCommand
{
public override void Execute(object parameter)
{
OpenFromGacDialog dlg = new OpenFromGacDialog();
dlg.Owner = MainWindow.Instance;
if (dlg.ShowDialog() == true)
MainWindow.Instance.OpenFiles(dlg.SelectedFileNames);
}
}
}

33
ILSpy/Commands/RefreshCommand.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
// 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.Windows.Input;
namespace ICSharpCode.ILSpy
{
[ExportToolbarCommand(ToolTip = "Reload all assemblies", ToolbarIcon = "Images/Refresh.png", ToolbarCategory = "Open", ToolbarOrder = 2)]
[ExportMainMenuCommand(Menu = "_File", Header = "Reload", MenuIcon = "Images/Refresh.png", MenuCategory = "Open", MenuOrder = 2)]
sealed class RefreshCommand : CommandWrapper
{
public RefreshCommand()
: base(NavigationCommands.Refresh)
{
}
}
}

32
ILSpy/Commands/SaveCommand.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// 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.Windows.Input;
namespace ICSharpCode.ILSpy
{
[ExportMainMenuCommand(Menu = "_File", Header = "_Save Code...", MenuIcon = "Images/SaveFile.png", MenuCategory = "Save", MenuOrder = 0)]
sealed class SaveCommand : CommandWrapper
{
public SaveCommand()
: base(ApplicationCommands.Save)
{
}
}
}

31
ILSpy/Commands/ShowAnalyzerCommand.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
// 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
{
[ExportMainMenuCommand(Menu = "_View", Header = "_Analyzer", MenuCategory = "ShowPane", MenuOrder = 100)]
sealed class ShowAnalyzerCommand : SimpleCommand
{
public override void Execute(object parameter)
{
AnalyzerTreeView.Instance.Show();
}
}
}

39
ILSpy/Commands/SimpleCommand.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
// 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.Windows.Input;
namespace ICSharpCode.ILSpy
{
public abstract class SimpleCommand : ICommand
{
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public abstract void Execute(object parameter);
public virtual bool CanExecute(object parameter)
{
return true;
}
}
}

28
ILSpy/ILSpy.csproj

@ -93,6 +93,8 @@ @@ -93,6 +93,8 @@
</Compile>
<Compile Include="AssemblyList.cs" />
<Compile Include="AssemblyListManager.cs" />
<Compile Include="Commands\BrowseBackCommand.cs" />
<Compile Include="Commands\BrowseForwardCommand.cs" />
<Compile Include="AvalonEdit\IconBarManager.cs" />
<Compile Include="AvalonEdit\IconBarMargin.cs" />
<Compile Include="AvalonEdit\IconMarginActionsProvider.cs" />
@ -107,18 +109,20 @@ @@ -107,18 +109,20 @@
<Compile Include="Bookmarks\IBookmark.cs" />
<Compile Include="Bookmarks\MarkerBookmark.cs" />
<Compile Include="CommandLineArguments.cs" />
<Compile Include="Commands.cs" />
<Compile Include="Commands\ExitCommand.cs" />
<Compile Include="Commands\CommandWrapper.cs" />
<Compile Include="ConnectMethodDecompiler.cs" />
<Compile Include="Controls\DockedPane.cs" />
<Compile Include="Commands\DecompileAllCommand.cs" />
<Compile Include="DecompilerSettingsPanel.xaml.cs">
<DependentUpon>DecompilerSettingsPanel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="DisplaySettings.cs" />
<Compile Include="ExportCommandAttribute.cs" />
<Compile Include="Commands\ExportCommandAttribute.cs" />
<Compile Include="Controls\SearchBox.cs" />
<Compile Include="Controls\SortableGridViewColumn.cs" />
<Compile Include="CSharpLanguage.cs" />
<Compile Include="Languages\CSharpLanguage.cs" />
<Compile Include="DecompilationOptions.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="FilterSettings.cs" />
@ -126,19 +130,23 @@ @@ -126,19 +130,23 @@
<Compile Include="GacInterop.cs" />
<Compile Include="GuessFileType.cs" />
<Compile Include="ContextMenuEntry.cs" />
<Compile Include="ILAstLanguage.cs" />
<Compile Include="ILLanguage.cs" />
<Compile Include="Languages\ILAstLanguage.cs" />
<Compile Include="Languages\ILLanguage.cs" />
<Compile Include="ILSpySettings.cs" />
<Compile Include="Images\AccessOverlayIcon.cs" />
<Compile Include="Images\MemberIcon.cs" />
<Compile Include="Images\TypeIcon.cs" />
<Compile Include="IPane.cs" />
<Compile Include="ISmartTextOutput.cs" />
<Compile Include="Language.cs" />
<Compile Include="Languages\Language.cs" />
<Compile Include="Images\Images.cs" />
<Compile Include="Languages\Languages.cs" />
<Compile Include="LoadedAssembly.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="NavigationHistory.cs" />
<Compile Include="NavigationState.cs" />
<Compile Include="Commands\OpenCommand.cs" />
<Compile Include="Commands\OpenFromGacCommand.cs" />
<Compile Include="OpenFromGacDialog.xaml.cs">
<DependentUpon>OpenFromGacDialog.xaml</DependentUpon>
<SubType>Code</SubType>
@ -148,6 +156,8 @@ @@ -148,6 +156,8 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Commands\RefreshCommand.cs" />
<Compile Include="Commands\SaveCommand.cs" />
<Compile Include="SearchPane.cs">
<SubType>Code</SubType>
</Compile>
@ -155,6 +165,8 @@ @@ -155,6 +165,8 @@
<DependentUpon>DisplaySettingsPanel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Commands\SimpleCommand.cs" />
<Compile Include="Commands\ShowAnalyzerCommand.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzeContextMenuEntry.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedEventOverridesTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedEventTreeNode.cs" />
@ -171,6 +183,9 @@ @@ -171,6 +183,9 @@
<Compile Include="TreeNodes\Analyzer\AnalyzedVirtualMethodUsedByTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\Helpers.cs" />
<Compile Include="TreeNodes\Analyzer\ScopedWhereUsedAnalyzer.cs" />
<Compile Include="TreeNodes\BaseTypesEntryNode.cs" />
<Compile Include="TreeNodes\DerivedTypesEntryNode.cs" />
<Compile Include="TreeNodes\FilterResult.cs" />
<Compile Include="TreeNodes\IMemberTreeNode.cs" />
<Compile Include="TreeNodes\ResourceNodes\CursorResourceEntryNode.cs" />
<Compile Include="TreeNodes\ResourceNodes\ImageResourceEntryNode.cs" />
@ -335,6 +350,7 @@ @@ -335,6 +350,7 @@
<Resource Include="Images\ResourceXsd.png" />
<Resource Include="Images\ResourceXslt.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="AvalonEdit" />
<Folder Include="Bookmarks" />

27
ILSpy/IPane.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
// 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
{
public interface IPane
{
void Closed();
}
}

BIN
ILSpy/Images/Delete.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 575 B

After

Width:  |  Height:  |  Size: 584 B

BIN
ILSpy/Images/OverlayInternal.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
ILSpy/Images/OverlayProtected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 352 B

After

Width:  |  Height:  |  Size: 351 B

BIN
ILSpy/Images/OverlayProtectedInternal.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 440 B

After

Width:  |  Height:  |  Size: 440 B

0
ILSpy/CSharpLanguage.cs → ILSpy/Languages/CSharpLanguage.cs

0
ILSpy/ILAstLanguage.cs → ILSpy/Languages/ILAstLanguage.cs

0
ILSpy/ILLanguage.cs → ILSpy/Languages/ILLanguage.cs

40
ILSpy/Language.cs → ILSpy/Languages/Language.cs

@ -19,8 +19,6 @@ @@ -19,8 +19,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using ICSharpCode.Decompiler;
@ -229,42 +227,4 @@ namespace ICSharpCode.ILSpy @@ -229,42 +227,4 @@ namespace ICSharpCode.ILSpy
}
}
}
public static class Languages
{
static ReadOnlyCollection<Language> allLanguages;
/// <summary>
/// A list of all languages.
/// </summary>
public static ReadOnlyCollection<Language> AllLanguages
{
get
{
return allLanguages;
}
}
internal static void Initialize(CompositionContainer composition)
{
List<Language> languages = new List<Language>();
languages.AddRange(composition.GetExportedValues<Language>());
languages.Add(new ILLanguage(true));
#if DEBUG
languages.AddRange(ILAstLanguage.GetDebugLanguages());
languages.AddRange(CSharpLanguage.GetDebugLanguages());
#endif
allLanguages = languages.AsReadOnly();
}
/// <summary>
/// Gets a language using its name.
/// If the language is not found, C# is returned instead.
/// </summary>
public static Language GetLanguage(string name)
{
return AllLanguages.FirstOrDefault(l => l.Name == name) ?? AllLanguages.First();
}
}
}

60
ILSpy/Languages/Languages.cs

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
// 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;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
namespace ICSharpCode.ILSpy
{
public static class Languages
{
private static ReadOnlyCollection<Language> allLanguages;
/// <summary>
/// A list of all languages.
/// </summary>
public static ReadOnlyCollection<Language> AllLanguages
{
get { return allLanguages; }
}
internal static void Initialize(CompositionContainer composition)
{
List<Language> languages = new List<Language>();
languages.AddRange(composition.GetExportedValues<Language>());
languages.Add(new ILLanguage(true));
#if DEBUG
languages.AddRange(ILAstLanguage.GetDebugLanguages());
languages.AddRange(CSharpLanguage.GetDebugLanguages());
#endif
allLanguages = languages.AsReadOnly();
}
/// <summary>
/// Gets a language using its name.
/// If the language is not found, C# is returned instead.
/// </summary>
public static Language GetLanguage(string name)
{
return AllLanguages.FirstOrDefault(l => l.Name == name) ?? AllLanguages.First();
}
}
}

5
ILSpy/LoadedAssembly.cs

@ -171,6 +171,11 @@ namespace ICSharpCode.ILSpy @@ -171,6 +171,11 @@ namespace ICSharpCode.ILSpy
}
}
public IAssemblyResolver GetAssemblyResolver()
{
return new MyAssemblyResolver(this);
}
public LoadedAssembly LookupReferencedAssembly(string fullName)
{
foreach (LoadedAssembly asm in assemblyList.GetAssemblies()) {

8
ILSpy/SearchPane.cs

@ -35,14 +35,6 @@ using Mono.Cecil; @@ -35,14 +35,6 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Notifies panes when they are closed.
/// </summary>
public interface IPane
{
void Closed();
}
/// <summary>
/// Search pane
/// </summary>

6
ILSpy/TreeNodes/Analyzer/AnalyzedEventFiredByTreeNode.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -77,7 +77,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
foundMethods = new ConcurrentDictionary<MethodDefinition, int>();
foreach (var child in FindReferencesInType(analyzedEvent.DeclaringType)) {
foreach (var child in FindReferencesInType(analyzedEvent.DeclaringType).OrderBy(n => n.Text)) {
yield return child;
}
@ -117,7 +117,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -117,7 +117,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
if (found) {
MethodDefinition codeLocation = this.Language.GetOriginalCodeLocation(method) as MethodDefinition;
if (codeLocation != null && !HasAlreadyBeenFound(codeLocation)) {
yield return new AnalyzedMethodTreeNode(codeLocation);
var node = new AnalyzedMethodTreeNode(codeLocation);
node.Language = this.Language;
yield return node;
}
}
}

8
ILSpy/TreeNodes/Analyzer/AnalyzedEventOverridesTreeNode.cs

@ -71,7 +71,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -71,7 +71,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
ScopedWhereUsedAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedEvent, FindReferencesInType);
return analyzer.PerformAnalysis(ct);
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
}
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
@ -86,7 +88,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -86,7 +88,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
if (TypesHierarchyHelpers.IsBaseEvent(analyzedEvent, eventDef)) {
MethodDefinition anyAccessor = eventDef.AddMethod ?? eventDef.RemoveMethod;
bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot;
yield return new AnalyzedEventTreeNode(eventDef, hidesParent ? "(hides) " : "");
var node = new AnalyzedEventTreeNode(eventDef, hidesParent ? "(hides) " : "");
node.Language = this.Language;
yield return node;
}
}
}

11
ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessTreeNode.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using ICSharpCode.TreeView;
using Mono.Cecil;
@ -74,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -74,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foundMethods = new Lazy<Hashtable>(LazyThreadSafetyMode.ExecutionAndPublication);
var analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedField, FindReferencesInType);
foreach (var child in analyzer.PerformAnalysis(ct)) {
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
@ -93,8 +94,8 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -93,8 +94,8 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foreach (Instruction instr in method.Body.Instructions) {
if (CanBeReference(instr.OpCode.Code)) {
FieldReference fr = instr.Operand as FieldReference;
if (fr != null && fr.Name == name &&
Helpers.IsReferencedBy(analyzedField.DeclaringType, fr.DeclaringType) &&
if (fr != null && fr.Name == name &&
Helpers.IsReferencedBy(analyzedField.DeclaringType, fr.DeclaringType) &&
fr.Resolve() == analyzedField) {
found = true;
break;
@ -107,7 +108,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -107,7 +108,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
if (found) {
MethodDefinition codeLocation = this.Language.GetOriginalCodeLocation(method) as MethodDefinition;
if (codeLocation != null && !HasAlreadyBeenFound(codeLocation)) {
yield return new AnalyzedMethodTreeNode(codeLocation);
var node = new AnalyzedMethodTreeNode(codeLocation);
node.Language = this.Language;
yield return node;
}
}
}

15
ILSpy/TreeNodes/Analyzer/AnalyzedInterfaceEventImplementedByTreeNode.cs

@ -71,7 +71,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -71,7 +71,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
ScopedWhereUsedAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType);
return analyzer.PerformAnalysis(ct);
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
}
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
@ -84,15 +86,20 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -84,15 +86,20 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foreach (EventDefinition ev in type.Events.Where(e => e.Name == analyzedEvent.Name)) {
MethodDefinition accessor = ev.AddMethod ?? ev.RemoveMethod;
if (TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef))
yield return new AnalyzedEventTreeNode(ev);
if (TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) {
var node = new AnalyzedEventTreeNode(ev);
node.Language = this.Language;
yield return node;
}
yield break;
}
foreach (EventDefinition ev in type.Events.Where(e => e.Name.EndsWith(analyzedEvent.Name))) {
MethodDefinition accessor = ev.AddMethod ?? ev.RemoveMethod;
if (accessor.HasOverrides && accessor.Overrides.Any(m => m.Resolve() == analyzedMethod)) {
yield return new AnalyzedEventTreeNode(ev);
var node = new AnalyzedEventTreeNode(ev);
node.Language = this.Language;
yield return node;
}
}
}

15
ILSpy/TreeNodes/Analyzer/AnalyzedInterfaceMethodImplementedByTreeNode.cs

@ -69,7 +69,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -69,7 +69,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
ScopedWhereUsedAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType);
return analyzer.PerformAnalysis(ct);
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
}
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
@ -81,14 +83,19 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -81,14 +83,19 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
yield break;
foreach (MethodDefinition method in type.Methods.Where(m => m.Name == analyzedMethod.Name)) {
if (TypesHierarchyHelpers.MatchInterfaceMethod(method, analyzedMethod, implementedInterfaceRef))
yield return new AnalyzedMethodTreeNode(method);
if (TypesHierarchyHelpers.MatchInterfaceMethod(method, analyzedMethod, implementedInterfaceRef)) {
var node = new AnalyzedMethodTreeNode(method);
node.Language = this.Language;
yield return node;
}
yield break;
}
foreach (MethodDefinition method in type.Methods) {
if (method.HasOverrides && method.Overrides.Any(m => m.Resolve() == analyzedMethod)) {
yield return new AnalyzedMethodTreeNode(method);
var node = new AnalyzedMethodTreeNode(method);
node.Language = this.Language;
yield return node;
}
}
}

15
ILSpy/TreeNodes/Analyzer/AnalyzedInterfacePropertyImplementedByTreeNode.cs

@ -71,7 +71,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -71,7 +71,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
ScopedWhereUsedAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType);
return analyzer.PerformAnalysis(ct);
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
}
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
@ -84,15 +86,20 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -84,15 +86,20 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foreach (PropertyDefinition property in type.Properties.Where(e => e.Name == analyzedProperty.Name)) {
MethodDefinition accessor = property.GetMethod ?? property.SetMethod;
if (TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef))
yield return new AnalyzedPropertyTreeNode(property);
if (TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) {
var node = new AnalyzedPropertyTreeNode(property);
node.Language = this.Language;
yield return node;
}
yield break;
}
foreach (PropertyDefinition property in type.Properties.Where(e => e.Name.EndsWith(analyzedProperty.Name))) {
MethodDefinition accessor = property.GetMethod ?? property.SetMethod;
if (accessor.HasOverrides && accessor.Overrides.Any(m => m.Resolve() == analyzedMethod)) {
yield return new AnalyzedPropertyTreeNode(property);
var node = new AnalyzedPropertyTreeNode(property);
node.Language = this.Language;
yield return node;
}
}
}

10
ILSpy/TreeNodes/Analyzer/AnalyzedMethodOverridesTreeNode.cs

@ -76,12 +76,14 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -76,12 +76,14 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
ScopedWhereUsedAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType);
return analyzer.PerformAnalysis(ct);
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
}
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{
SharpTreeNode newNode = null;
AnalyzerTreeNode newNode = null;
try {
if (!TypesHierarchyHelpers.IsBaseType(analyzedMethod.DeclaringType, type, resolveTypeArguments: false))
yield break;
@ -97,8 +99,10 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -97,8 +99,10 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
// ignore this type definition. maybe add a notification about such cases.
}
if (newNode != null)
if (newNode != null) {
newNode.Language = this.Language;
yield return newNode;
}
}
public static bool CanShow(MethodDefinition method)

7
ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsedByTreeNode.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using ICSharpCode.TreeView;
using Mono.Cecil;
@ -71,7 +72,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -71,7 +72,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foundMethods = new ConcurrentDictionary<MethodDefinition, int>();
var analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType);
foreach (var child in analyzer.PerformAnalysis(ct)) {
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
@ -100,7 +101,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -100,7 +101,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
if (found) {
MethodDefinition codeLocation = this.Language.GetOriginalCodeLocation(method) as MethodDefinition;
if (codeLocation != null && !HasAlreadyBeenFound(codeLocation)) {
yield return new AnalyzedMethodTreeNode(codeLocation);
var node= new AnalyzedMethodTreeNode(codeLocation);
node.Language = this.Language;
yield return node;
}
}
}

17
ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsesTreeNode.cs

@ -51,14 +51,25 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -51,14 +51,25 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
}
protected override void LoadChildren()
{
analyzedMethod.Body = null;
foreach (var child in GetChildren().OrderBy(n => n.Text)) {
this.Children.Add(child);
}
}
private IEnumerable<AnalyzerTreeNode> GetChildren()
{
foreach (var f in GetUsedFields().Distinct()) {
this.Children.Add(new AnalyzedFieldTreeNode(f));
var node = new AnalyzedFieldTreeNode(f);
node.Language = this.Language;
yield return node;
}
foreach (var m in GetUsedMethods().Distinct()) {
this.Children.Add(new AnalyzedMethodTreeNode(m));
var node = new AnalyzedMethodTreeNode(m);
node.Language = this.Language;
yield return node;
}
analyzedMethod.Body = null;
}
private IEnumerable<MethodDefinition> GetUsedMethods()

8
ILSpy/TreeNodes/Analyzer/AnalyzedPropertyOverridesTreeNode.cs

@ -72,7 +72,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -72,7 +72,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
ScopedWhereUsedAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedProperty, FindReferencesInType);
return analyzer.PerformAnalysis(ct);
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
}
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
@ -88,7 +90,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -88,7 +90,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
if (TypesHierarchyHelpers.IsBaseProperty(analyzedProperty, property)) {
MethodDefinition anyAccessor = property.GetMethod ?? property.SetMethod;
bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot;
yield return new AnalyzedPropertyTreeNode(property, hidesParent ? "(hides) " : "");
var node = new AnalyzedPropertyTreeNode(property, hidesParent ? "(hides) " : "");
node.Language = this.Language;
yield return node;
}
}
}

33
ILSpy/TreeNodes/Analyzer/AnalyzedTypeExposedByTreeNode.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using ICSharpCode.TreeView;
using Mono.Cecil;
@ -68,7 +69,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -68,7 +69,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
ScopedWhereUsedAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedType, FindReferencesInType);
return analyzer.PerformAnalysis(ct);
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
}
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
@ -80,23 +83,35 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -80,23 +83,35 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
yield break;
foreach (FieldDefinition field in type.Fields) {
if (TypeIsExposedBy(field))
yield return new AnalyzedFieldTreeNode(field);
if (TypeIsExposedBy(field)) {
var node = new AnalyzedFieldTreeNode(field);
node.Language = this.Language;
yield return node;
}
}
foreach (PropertyDefinition property in type.Properties) {
if (TypeIsExposedBy(property))
yield return new AnalyzedPropertyTreeNode(property);
if (TypeIsExposedBy(property)) {
var node = new AnalyzedPropertyTreeNode(property);
node.Language = this.Language;
yield return node;
}
}
foreach (EventDefinition eventDef in type.Events) {
if (TypeIsExposedBy(eventDef))
yield return new AnalyzedEventTreeNode(eventDef);
if (TypeIsExposedBy(eventDef)) {
var node = new AnalyzedEventTreeNode(eventDef);
node.Language = this.Language;
yield return node;
}
}
foreach (MethodDefinition method in type.Methods) {
if (TypeIsExposedBy(method))
yield return new AnalyzedMethodTreeNode(method);
if (TypeIsExposedBy(method)) {
var node = new AnalyzedMethodTreeNode(method);
node.Language = this.Language;
yield return node;
}
}
}

8
ILSpy/TreeNodes/Analyzer/AnalyzedTypeExtensionMethodsTreeNode.cs

@ -69,7 +69,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -69,7 +69,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
ScopedWhereUsedAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedType, FindReferencesInType);
return analyzer.PerformAnalysis(ct);
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
}
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
@ -79,7 +81,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -79,7 +81,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foreach (MethodDefinition method in type.Methods) {
if (method.IsStatic && HasExtensionAttribute(method)) {
if (method.HasParameters && method.Parameters[0].ParameterType.Resolve() == analyzedType) {
yield return new AnalyzedMethodTreeNode(method);
var node = new AnalyzedMethodTreeNode(method);
node.Language = this.Language;
yield return node;
}
}
}

11
ILSpy/TreeNodes/Analyzer/AnalyzedTypeInstantiationsTreeNode.cs

@ -74,7 +74,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -74,7 +74,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
ScopedWhereUsedAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedType, FindReferencesInType);
return analyzer.PerformAnalysis(ct);
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
}
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
@ -102,8 +104,11 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -102,8 +104,11 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
method.Body = null;
if (found)
yield return new AnalyzedMethodTreeNode(method);
if (found) {
var node = new AnalyzedMethodTreeNode(method);
node.Language = this.Language;
yield return node;
}
}
}

13
ILSpy/TreeNodes/Analyzer/AnalyzedVirtualMethodUsedByTreeNode.cs

@ -75,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -75,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
InitializeAnalyzer();
var analyzer = new ScopedWhereUsedAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType);
foreach (var child in analyzer.PerformAnalysis(ct)) {
foreach (var child in analyzer.PerformAnalysis(ct).OrderBy(n => n.Text)) {
yield return child;
}
@ -95,8 +95,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -95,8 +95,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
possibleTypes = new List<TypeReference>();
TypeReference type = analyzedMethod.DeclaringType.BaseType;
while (type !=null)
{
while (type != null) {
possibleTypes.Add(type);
type = type.Resolve().BaseType;
}
@ -120,8 +119,8 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -120,8 +119,8 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
MethodReference mr = instr.Operand as MethodReference;
if (mr != null && mr.Name == name) {
// explicit call to the requested method
if (instr.OpCode.Code == Code.Call
&& Helpers.IsReferencedBy(analyzedMethod.DeclaringType, mr.DeclaringType)
if (instr.OpCode.Code == Code.Call
&& Helpers.IsReferencedBy(analyzedMethod.DeclaringType, mr.DeclaringType)
&& mr.Resolve() == analyzedMethod) {
found = true;
prefix = "(as base) ";
@ -147,7 +146,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -147,7 +146,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
if (found) {
MethodDefinition codeLocation = this.Language.GetOriginalCodeLocation(method) as MethodDefinition;
if (codeLocation != null && !HasAlreadyBeenFound(codeLocation)) {
yield return new AnalyzedMethodTreeNode(codeLocation, prefix);
var node = new AnalyzedMethodTreeNode(codeLocation);
node.Language = this.Language;
yield return node;
}
}
}

104
ILSpy/TreeNodes/BaseTypesEntryNode.cs

@ -0,0 +1,104 @@ @@ -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.Linq;
using ICSharpCode.Decompiler;
using ICSharpCode.TreeView;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
{
sealed class BaseTypesEntryNode : ILSpyTreeNode, IMemberTreeNode
{
private TypeReference tr;
private TypeDefinition def;
private bool isInterface;
public BaseTypesEntryNode(TypeReference tr, bool isInterface)
{
if (tr == null)
throw new ArgumentNullException("tr");
this.tr = tr;
this.def = tr.Resolve();
this.isInterface = isInterface;
this.LazyLoading = true;
}
public override bool ShowExpander
{
get { return def != null && (def.BaseType != null || def.HasInterfaces); }
}
public override object Text
{
get { return this.Language.TypeToString(tr, true); }
}
public override object Icon
{
get
{
if (def != null)
return TypeTreeNode.GetIcon(def);
else
return isInterface ? Images.Interface : Images.Class;
}
}
protected override void LoadChildren()
{
if (def != null)
BaseTypesTreeNode.AddBaseTypes(this.Children, def);
}
public override void ActivateItem(System.Windows.RoutedEventArgs e)
{
// on item activation, try to resolve once again (maybe the user loaded the assembly in the meantime)
if (def == null) {
def = tr.Resolve();
if (def != null)
this.LazyLoading = true;
// re-load children
}
e.Handled = ActivateItem(this, def);
}
internal static bool ActivateItem(SharpTreeNode node, TypeDefinition def)
{
if (def != null) {
var assemblyListNode = node.Ancestors().OfType<AssemblyListTreeNode>().FirstOrDefault();
if (assemblyListNode != null) {
assemblyListNode.Select(assemblyListNode.FindTypeNode(def));
return true;
}
}
return false;
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(tr, true));
}
MemberReference IMemberTreeNode.Member
{
get { return tr; }
}
}
}

96
ILSpy/TreeNodes/BaseTypesTreeNode.cs

@ -17,9 +17,7 @@ @@ -17,9 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using System.Windows.Threading;
using ICSharpCode.Decompiler;
using ICSharpCode.TreeView;
using Mono.Cecil;
@ -32,26 +30,28 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -32,26 +30,28 @@ namespace ICSharpCode.ILSpy.TreeNodes
sealed class BaseTypesTreeNode : ILSpyTreeNode
{
readonly TypeDefinition type;
public BaseTypesTreeNode(TypeDefinition type)
{
this.type = type;
this.LazyLoading = true;
}
public override object Text {
public override object Text
{
get { return "Base Types"; }
}
public override object Icon {
public override object Icon
{
get { return Images.SuperTypes; }
}
protected override void LoadChildren()
{
AddBaseTypes(this.Children, type);
}
internal static void AddBaseTypes(SharpTreeNodeCollection children, TypeDefinition type)
{
if (type.BaseType != null)
@ -60,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -60,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
children.Add(new BaseTypesEntryNode(i, true));
}
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(EnsureLazyChildren));
@ -69,78 +69,4 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -69,78 +69,4 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
}
}
sealed class BaseTypesEntryNode : ILSpyTreeNode, IMemberTreeNode
{
TypeReference tr;
TypeDefinition def;
bool isInterface;
public BaseTypesEntryNode(TypeReference tr, bool isInterface)
{
if (tr == null)
throw new ArgumentNullException("tr");
this.tr = tr;
this.def = tr.Resolve();
this.isInterface = isInterface;
this.LazyLoading = true;
}
public override bool ShowExpander {
get {
return def != null && (def.BaseType != null || def.HasInterfaces);
}
}
public override object Text {
get { return this.Language.TypeToString(tr, true); }
}
public override object Icon {
get {
if (def != null)
return TypeTreeNode.GetIcon(def);
else
return isInterface ? Images.Interface : Images.Class;
}
}
protected override void LoadChildren()
{
if (def != null)
BaseTypesTreeNode.AddBaseTypes(this.Children, def);
}
public override void ActivateItem(System.Windows.RoutedEventArgs e)
{
// on item activation, try to resolve once again (maybe the user loaded the assembly in the meantime)
if (def == null) {
def = tr.Resolve();
if (def != null)
this.LazyLoading = true; // re-load children
}
e.Handled = ActivateItem(this, def);
}
internal static bool ActivateItem(SharpTreeNode node, TypeDefinition def)
{
if (def != null) {
var assemblyListNode = node.Ancestors().OfType<AssemblyListTreeNode>().FirstOrDefault();
if (assemblyListNode != null) {
assemblyListNode.Select(assemblyListNode.FindTypeNode(def));
return true;
}
}
return false;
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(tr, true));
}
MemberReference IMemberTreeNode.Member {
get { return tr; }
}
}
}
}

111
ILSpy/TreeNodes/DerivedTypesEntryNode.cs

@ -0,0 +1,111 @@ @@ -0,0 +1,111 @@
// 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;
using System.Threading;
using ICSharpCode.Decompiler;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
{
class DerivedTypesEntryNode : ILSpyTreeNode, IMemberTreeNode
{
private TypeDefinition type;
private AssemblyDefinition[] assemblies;
private ThreadingSupport threading;
public DerivedTypesEntryNode(TypeDefinition type, AssemblyDefinition[] assemblies)
{
this.type = type;
this.assemblies = assemblies;
this.LazyLoading = true;
threading = new ThreadingSupport();
}
public override bool ShowExpander
{
get { return !type.IsSealed && base.ShowExpander; }
}
public override object Text
{
get { return this.Language.TypeToString(type, true); }
}
public override object Icon
{
get { return TypeTreeNode.GetIcon(type); }
}
public override FilterResult Filter(FilterSettings settings)
{
if (!settings.ShowInternalApi && !IsPublicAPI)
return FilterResult.Hidden;
if (settings.SearchTermMatches(type.Name)) {
if (type.IsNested && !settings.Language.ShowMember(type))
return FilterResult.Hidden;
else
return FilterResult.Match;
} else
return FilterResult.Recurse;
}
public bool IsPublicAPI
{
get
{
switch (type.Attributes & TypeAttributes.VisibilityMask) {
case TypeAttributes.Public:
case TypeAttributes.NestedPublic:
case TypeAttributes.NestedFamily:
case TypeAttributes.NestedFamORAssem:
return true;
default:
return false;
}
}
}
protected override void LoadChildren()
{
threading.LoadChildren(this, FetchChildren);
}
IEnumerable<ILSpyTreeNode> FetchChildren(CancellationToken ct)
{
// FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread
return DerivedTypesTreeNode.FindDerivedTypes(type, assemblies, ct);
}
public override void ActivateItem(System.Windows.RoutedEventArgs e)
{
e.Handled = BaseTypesEntryNode.ActivateItem(this, type);
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(type, true));
}
MemberReference IMemberTreeNode.Member
{
get { return type; }
}
}
}

81
ILSpy/TreeNodes/DerivedTypesTreeNode.cs

@ -20,7 +20,6 @@ using System; @@ -20,7 +20,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using ICSharpCode.Decompiler;
using ICSharpCode.NRefactory.Utils;
using Mono.Cecil;
@ -35,7 +34,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -35,7 +34,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
readonly AssemblyList list;
readonly TypeDefinition type;
ThreadingSupport threading;
public DerivedTypesTreeNode(AssemblyList list, TypeDefinition type)
{
this.list = list;
@ -43,27 +42,29 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -43,27 +42,29 @@ namespace ICSharpCode.ILSpy.TreeNodes
this.LazyLoading = true;
this.threading = new ThreadingSupport();
}
public override object Text {
public override object Text
{
get { return "Derived Types"; }
}
public override object Icon {
public override object Icon
{
get { return Images.SubTypes; }
}
protected override void LoadChildren()
{
threading.LoadChildren(this, FetchChildren);
}
IEnumerable<ILSpyTreeNode> FetchChildren(CancellationToken cancellationToken)
{
// FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread
var assemblies = list.GetAssemblies().Select(node => node.AssemblyDefinition).Where(asm => asm != null).ToArray();
return FindDerivedTypes(type, assemblies, cancellationToken);
}
internal static IEnumerable<DerivedTypesEntryNode> FindDerivedTypes(TypeDefinition type, AssemblyDefinition[] assemblies, CancellationToken cancellationToken)
{
foreach (AssemblyDefinition asm in assemblies) {
@ -80,7 +81,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -80,7 +81,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
}
}
static bool IsSameType(TypeReference typeRef, TypeDefinition type)
{
if (typeRef.FullName == type.FullName)
@ -96,66 +97,10 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -96,66 +97,10 @@ namespace ICSharpCode.ILSpy.TreeNodes
return false;
return true;
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
threading.Decompile(language, output, options, EnsureLazyChildren);
}
}
class DerivedTypesEntryNode : ILSpyTreeNode, IMemberTreeNode
{
TypeDefinition def;
AssemblyDefinition[] assemblies;
ThreadingSupport threading;
public DerivedTypesEntryNode(TypeDefinition def, AssemblyDefinition[] assemblies)
{
this.def = def;
this.assemblies = assemblies;
this.LazyLoading = true;
threading = new ThreadingSupport();
}
public override bool ShowExpander {
get {
return !def.IsSealed && base.ShowExpander;
}
}
public override object Text {
get { return this.Language.TypeToString(def, true); }
}
public override object Icon {
get {
return TypeTreeNode.GetIcon(def);
}
}
protected override void LoadChildren()
{
threading.LoadChildren(this, FetchChildren);
}
IEnumerable<ILSpyTreeNode> FetchChildren(CancellationToken ct)
{
// FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread
return DerivedTypesTreeNode.FindDerivedTypes(def, assemblies, ct);
}
public override void ActivateItem(System.Windows.RoutedEventArgs e)
{
e.Handled = BaseTypesEntryNode.ActivateItem(this, def);
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(def, true));
}
MemberReference IMemberTreeNode.Member {
get { return def; }
}
}
}
}

40
ILSpy/TreeNodes/FilterResult.cs

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
// 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.
namespace ICSharpCode.ILSpy.TreeNodes
{
public enum FilterResult
{
/// <summary>
/// Hides the node.
/// </summary>
Hidden,
/// <summary>
/// Shows the node (and resets the search term for child nodes).
/// </summary>
Match,
/// <summary>
/// Hides the node only if all children are hidden (and resets the search term for child nodes).
/// </summary>
MatchAndRecurse,
/// <summary>
/// Hides the node only if all children are hidden (doesn't reset the search term for child nodes).
/// </summary>
Recurse
}
}

58
ILSpy/TreeNodes/ILSpyTreeNode.cs

@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
@ -33,21 +32,24 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -33,21 +32,24 @@ namespace ICSharpCode.ILSpy.TreeNodes
{
FilterSettings filterSettings;
bool childrenNeedFiltering;
public FilterSettings FilterSettings {
public FilterSettings FilterSettings
{
get { return filterSettings; }
set {
set
{
if (filterSettings != value) {
filterSettings = value;
OnFilterSettingsChanged();
}
}
}
public Language Language {
public Language Language
{
get { return filterSettings != null ? filterSettings.Language : Languages.AllLanguages[0]; }
}
public virtual FilterResult Filter(FilterSettings settings)
{
if (string.IsNullOrEmpty(settings.SearchTerm))
@ -55,15 +57,15 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -55,15 +57,15 @@ namespace ICSharpCode.ILSpy.TreeNodes
else
return FilterResult.Hidden;
}
protected static object HighlightSearchMatch(string text, string suffix = null)
{
// TODO: implement highlighting the search match
return text + suffix;
}
public abstract void Decompile(Language language, ITextOutput output, DecompilationOptions options);
/// <summary>
/// Used to implement special view logic for some items.
/// This method is called on the main thread when only a single item is selected.
@ -73,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -73,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
{
return false;
}
/// <summary>
/// Used to implement special save logic for some items.
/// This method is called on the main thread when only a single item is selected.
@ -83,7 +85,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -83,7 +85,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
{
return false;
}
protected override void OnChildrenChanged(NotifyCollectionChangedEventArgs e)
{
if (e.NewItems != null) {
@ -96,7 +98,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -96,7 +98,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
base.OnChildrenChanged(e);
}
void ApplyFilterToChild(ILSpyTreeNode child)
{
FilterResult r;
@ -126,7 +128,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -126,7 +128,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
throw new InvalidEnumArgumentException();
}
}
FilterSettings StripSearchTerm(FilterSettings filterSettings)
{
if (filterSettings == null)
@ -137,7 +139,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -137,7 +139,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
return filterSettings;
}
protected virtual void OnFilterSettingsChanged()
{
RaisePropertyChanged("Text");
@ -148,13 +150,13 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -148,13 +150,13 @@ namespace ICSharpCode.ILSpy.TreeNodes
childrenNeedFiltering = true;
}
}
protected override void OnIsVisibleChanged()
{
base.OnIsVisibleChanged();
EnsureChildrenFiltered();
}
void EnsureChildrenFiltered()
{
EnsureLazyChildren();
@ -165,24 +167,4 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -165,24 +167,4 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
}
}
public enum FilterResult
{
/// <summary>
/// Hides the node.
/// </summary>
Hidden,
/// <summary>
/// Shows the node (and resets the search term for child nodes).
/// </summary>
Match,
/// <summary>
/// Hides the node only if all children are hidden (and resets the search term for child nodes).
/// </summary>
MatchAndRecurse,
/// <summary>
/// Hides the node only if all children are hidden (doesn't reset the search term for child nodes).
/// </summary>
Recurse
}
}
}

3
Mono.Cecil/symbols/pdb/Mono.Cecil.Pdb.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">net_4_0_Debug</Configuration>
@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\mono.snk</AssemblyOriginatorKeyFile>
<NoWarn>0649</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

Loading…
Cancel
Save