Browse Source

Add Event+Property nodes.

pull/1/head
Daniel Grunwald 14 years ago
parent
commit
93e6996810
  1. 49
      ILSpy/EventTreeNode.cs
  2. 16
      ILSpy/FieldTreeNode.cs
  3. 22
      ILSpy/ILSpy.csproj
  4. BIN
      ILSpy/Images/Event.png
  5. BIN
      ILSpy/Images/ExtensionMethod.png
  6. 11
      ILSpy/Images/Images.cs
  7. BIN
      ILSpy/Images/Indexer.png
  8. BIN
      ILSpy/Images/InternalField.png
  9. BIN
      ILSpy/Images/InternalMethod.png
  10. BIN
      ILSpy/Images/Operator.png
  11. BIN
      ILSpy/Images/PrivateField.png
  12. BIN
      ILSpy/Images/PrivateMethod.png
  13. BIN
      ILSpy/Images/Property.png
  14. BIN
      ILSpy/Images/ProtectedField.png
  15. BIN
      ILSpy/Images/ProtectedMethod.png
  16. BIN
      ILSpy/Images/Reference.png
  17. 55
      ILSpy/Images/TypeImages.cs
  18. 30
      ILSpy/Language.cs
  19. 33
      ILSpy/MethodTreeNode.cs
  20. 49
      ILSpy/PropertyTreeNode.cs
  21. 34
      ILSpy/TypeTreeNode.cs

49
ILSpy/EventTreeNode.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using ICSharpCode.TreeView;
using Mono.Cecil;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Represents an event in the TreeView.
/// </summary>
sealed class EventTreeNode : SharpTreeNode
{
readonly EventDefinition ev;
public EventTreeNode(EventDefinition ev)
{
if (ev == null)
throw new ArgumentNullException("ev");
this.ev = ev;
this.LazyLoading = true;
}
public override object Text {
get { return ev.Name + " : " + Language.Current.TypeToString(ev.EventType); }
}
public override object Icon {
get {
return Images.Event;
}
}
protected override void LoadChildren()
{
if (ev.AddMethod != null)
this.Children.Add(new MethodTreeNode(ev.AddMethod));
if (ev.RemoveMethod != null)
this.Children.Add(new MethodTreeNode(ev.RemoveMethod));
if (ev.InvokeMethod != null)
this.Children.Add(new MethodTreeNode(ev.InvokeMethod));
if (ev.HasOtherMethods) {
foreach (var m in ev.OtherMethods)
this.Children.Add(new MethodTreeNode(m));
}
}
}
}

16
ILSpy/FieldTreeNode.cs

@ -37,25 +37,15 @@ namespace ICSharpCode.ILSpy @@ -37,25 +37,15 @@ namespace ICSharpCode.ILSpy
}
public override object Text {
get { return field.Name; }
get { return field.Name + " : " + Language.Current.TypeToString(field.FieldType); }
}
public override object Icon {
get {
if (field.IsLiteral)
return Images.Literal;
switch (field.Attributes & FieldAttributes.FieldAccessMask) {
case FieldAttributes.Public:
return Images.Field;
case FieldAttributes.Assembly:
case FieldAttributes.FamANDAssem:
return Images.InternalField;
case FieldAttributes.Family:
case FieldAttributes.FamORAssem:
return Images.ProtectedField;
default:
return Images.PrivateField;
}
else
return Images.Field;
}
}
}

22
ILSpy/ILSpy.csproj

@ -72,10 +72,12 @@ @@ -72,10 +72,12 @@
<Compile Include="AssemblyReferenceTreeNode.cs" />
<Compile Include="AssemblyTreeNode.cs" />
<Compile Include="BaseTypesTreeNode.cs" />
<Compile Include="EventTreeNode.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="FieldTreeNode.cs" />
<Compile Include="Fusion.cs" />
<Compile Include="GacInterop.cs" />
<Compile Include="Language.cs" />
<Compile Include="Images\Images.cs" />
<Compile Include="MethodTreeNode.cs" />
<Compile Include="ModuleReferenceTreeNode.cs" />
@ -91,6 +93,7 @@ @@ -91,6 +93,7 @@
<SubType>Code</SubType>
<DependentUpon>MainWindow.xaml</DependentUpon>
</Compile>
<Compile Include="PropertyTreeNode.cs" />
<Compile Include="ReferenceFolderTreeNode.cs" />
<Compile Include="SortableGridViewColumn.cs" />
<Compile Include="TreeTraversal.cs" />
@ -111,9 +114,7 @@ @@ -111,9 +114,7 @@
<Resource Include="Images\InternalClass.png" />
<Resource Include="Images\InternalDelegate.png" />
<Resource Include="Images\InternalEnum.png" />
<Resource Include="Images\InternalField.png" />
<Resource Include="Images\InternalInterface.png" />
<Resource Include="Images\InternalMethod.png" />
<Resource Include="Images\InternalStruct.png" />
<Resource Include="Images\Literal.png" />
<Resource Include="Images\Method.png" />
@ -122,16 +123,12 @@ @@ -122,16 +123,12 @@
<Resource Include="Images\PrivateClass.png" />
<Resource Include="Images\PrivateDelegate.png" />
<Resource Include="Images\PrivateEnum.png" />
<Resource Include="Images\PrivateField.png" />
<Resource Include="Images\PrivateInterface.png" />
<Resource Include="Images\PrivateMethod.png" />
<Resource Include="Images\PrivateStruct.png" />
<Resource Include="Images\ProtectedClass.png" />
<Resource Include="Images\ProtectedDelegate.png" />
<Resource Include="Images\ProtectedEnum.png" />
<Resource Include="Images\ProtectedField.png" />
<Resource Include="Images\ProtectedInterface.png" />
<Resource Include="Images\ProtectedMethod.png" />
<Resource Include="Images\ProtectedStruct.png" />
<Resource Include="Images\Assembly.png" />
<Resource Include="Images\Struct.png" />
@ -163,5 +160,18 @@ @@ -163,5 +160,18 @@
<Resource Include="Images\Redo.png" />
<Resource Include="Images\Undo.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Event.png" />
<Resource Include="Images\ExtensionMethod.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Indexer.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Operator.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Property.png" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

BIN
ILSpy/Images/Event.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

BIN
ILSpy/Images/ExtensionMethod.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

11
ILSpy/Images/Images.cs

@ -32,30 +32,29 @@ namespace ICSharpCode.ILSpy @@ -32,30 +32,29 @@ namespace ICSharpCode.ILSpy
public static readonly BitmapImage Struct = LoadBitmap("Struct");
public static readonly BitmapImage Field = LoadBitmap("Field");
public static readonly BitmapImage Method = LoadBitmap("Method");
public static readonly BitmapImage ExtensionMethod = LoadBitmap("ExtensionMethod");
public static readonly BitmapImage Literal = LoadBitmap("Literal");
public static readonly BitmapImage Property = LoadBitmap("Property");
public static readonly BitmapImage Event = LoadBitmap("Event");
public static readonly BitmapImage Indexer = LoadBitmap("Indexer");
public static readonly BitmapImage Operator = LoadBitmap("Operator");
public static readonly BitmapImage InternalClass = LoadBitmap("InternalClass");
public static readonly BitmapImage InternalDelegate = LoadBitmap("InternalDelegate");
public static readonly BitmapImage InternalEnum = LoadBitmap("InternalEnum");
public static readonly BitmapImage InternalInterface = LoadBitmap("InternalInterface");
public static readonly BitmapImage InternalStruct = LoadBitmap("InternalStruct");
public static readonly BitmapImage InternalField = LoadBitmap("InternalField");
public static readonly BitmapImage InternalMethod = LoadBitmap("InternalMethod");
public static readonly BitmapImage PrivateClass = LoadBitmap("PrivateClass");
public static readonly BitmapImage PrivateDelegate = LoadBitmap("PrivateDelegate");
public static readonly BitmapImage PrivateEnum = LoadBitmap("PrivateEnum");
public static readonly BitmapImage PrivateInterface = LoadBitmap("PrivateInterface");
public static readonly BitmapImage PrivateStruct = LoadBitmap("PrivateStruct");
public static readonly BitmapImage PrivateField = LoadBitmap("PrivateField");
public static readonly BitmapImage PrivateMethod = LoadBitmap("PrivateMethod");
public static readonly BitmapImage ProtectedClass = LoadBitmap("ProtectedClass");
public static readonly BitmapImage ProtectedDelegate = LoadBitmap("ProtectedDelegate");
public static readonly BitmapImage ProtectedEnum = LoadBitmap("ProtectedEnum");
public static readonly BitmapImage ProtectedInterface = LoadBitmap("ProtectedInterface");
public static readonly BitmapImage ProtectedStruct = LoadBitmap("ProtectedStruct");
public static readonly BitmapImage ProtectedField = LoadBitmap("ProtectedField");
public static readonly BitmapImage ProtectedMethod = LoadBitmap("ProtectedMethod");
}
}

BIN
ILSpy/Images/Indexer.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

BIN
ILSpy/Images/InternalField.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 789 B

BIN
ILSpy/Images/InternalMethod.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 776 B

BIN
ILSpy/Images/Operator.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

BIN
ILSpy/Images/PrivateField.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 831 B

BIN
ILSpy/Images/PrivateMethod.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 820 B

BIN
ILSpy/Images/Property.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

BIN
ILSpy/Images/ProtectedField.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 772 B

BIN
ILSpy/Images/ProtectedMethod.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 765 B

BIN
ILSpy/Images/Reference.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 466 B

55
ILSpy/Images/TypeImages.cs

@ -1,55 +0,0 @@ @@ -1,55 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Media.Imaging;
namespace ICSharpCode.ILSpy
{
static class TypeImages
{
static BitmapImage LoadBitmap(string name)
{
BitmapImage image = new BitmapImage(new Uri("pack://application:,,,/Images/" + name + ".png"));
image.Freeze();
return image;
}
public static readonly BitmapImage Class = LoadBitmap("Class");
public static readonly BitmapImage Delegate = LoadBitmap("Delegate");
public static readonly BitmapImage Enum = LoadBitmap("Enum");
public static readonly BitmapImage Interface = LoadBitmap("Interface");
public static readonly BitmapImage Struct = LoadBitmap("Struct");
public static readonly BitmapImage Field = LoadBitmap("Field");
public static readonly BitmapImage Method = LoadBitmap("Method");
public static readonly BitmapImage Literal = LoadBitmap("Literal");
public static readonly BitmapImage InternalClass = LoadBitmap("InternalClass");
public static readonly BitmapImage InternalDelegate = LoadBitmap("InternalDelegate");
public static readonly BitmapImage InternalEnum = LoadBitmap("InternalEnum");
public static readonly BitmapImage InternalInterface = LoadBitmap("InternalInterface");
public static readonly BitmapImage InternalStruct = LoadBitmap("InternalStruct");
public static readonly BitmapImage InternalField = LoadBitmap("InternalField");
public static readonly BitmapImage InternalMethod = LoadBitmap("InternalMethod");
public static readonly BitmapImage PrivateClass = LoadBitmap("PrivateClass");
public static readonly BitmapImage PrivateDelegate = LoadBitmap("PrivateDelegate");
public static readonly BitmapImage PrivateEnum = LoadBitmap("PrivateEnum");
public static readonly BitmapImage PrivateInterface = LoadBitmap("PrivateInterface");
public static readonly BitmapImage PrivateStruct = LoadBitmap("PrivateStruct");
public static readonly BitmapImage PrivateField = LoadBitmap("PrivateField");
public static readonly BitmapImage PrivateMethod = LoadBitmap("PrivateMethod");
public static readonly BitmapImage ProtectedClass = LoadBitmap("ProtectedClass");
public static readonly BitmapImage ProtectedDelegate = LoadBitmap("ProtectedDelegate");
public static readonly BitmapImage ProtectedEnum = LoadBitmap("ProtectedEnum");
public static readonly BitmapImage ProtectedInterface = LoadBitmap("ProtectedInterface");
public static readonly BitmapImage ProtectedStruct = LoadBitmap("ProtectedStruct");
public static readonly BitmapImage ProtectedField = LoadBitmap("ProtectedField");
public static readonly BitmapImage ProtectedMethod = LoadBitmap("ProtectedMethod");
}
}

30
ILSpy/Language.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using Mono.Cecil;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Description of ILanguage.
/// </summary>
public abstract class Language
{
public static readonly Language Current = Languages.IL;
public virtual string TypeToString(TypeReference t)
{
return t.Name;
}
}
public static class Languages
{
public static readonly Language IL = new ILLanguage();
class ILLanguage : Language
{
}
}
}

33
ILSpy/MethodTreeNode.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Text;
using ICSharpCode.TreeView;
using Mono.Cecil;
@ -37,23 +38,31 @@ namespace ICSharpCode.ILSpy @@ -37,23 +38,31 @@ namespace ICSharpCode.ILSpy
}
public override object Text {
get { return method.Name; }
get {
StringBuilder b = new StringBuilder();
b.Append(method.Name);
b.Append('(');
for (int i = 0; i < method.Parameters.Count; i++) {
if (i > 0) b.Append(", ");
b.Append(Language.Current.TypeToString(method.Parameters[i].ParameterType));
}
b.Append(") : ");
b.Append(Language.Current.TypeToString(method.ReturnType));
return b.ToString();
}
}
public override object Icon {
get {
switch (method.Attributes & MethodAttributes.MemberAccessMask) {
case MethodAttributes.Public:
return Images.Method;
case MethodAttributes.Assembly:
case MethodAttributes.FamANDAssem:
return Images.InternalMethod;
case MethodAttributes.Family:
case MethodAttributes.FamORAssem:
return Images.ProtectedMethod;
default:
return Images.PrivateMethod;
if (method.IsSpecialName && method.Name.StartsWith("op_", StringComparison.Ordinal))
return Images.Operator;
if (method.IsStatic && method.HasParameters && method.Parameters[0].HasCustomAttributes) {
foreach (var ca in method.Parameters[0].CustomAttributes) {
if (ca.AttributeType.FullName == "System.Runtime.CompilerServices.ExtensionAttribute")
return Images.ExtensionMethod;
}
}
return Images.Method;
}
}
}

49
ILSpy/PropertyTreeNode.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using ICSharpCode.TreeView;
using Mono.Cecil;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Represents a property in the TreeView.
/// </summary>
sealed class PropertyTreeNode : SharpTreeNode
{
readonly PropertyDefinition property;
readonly bool isIndexer;
public PropertyTreeNode(PropertyDefinition property, bool isIndexer)
{
if (property == null)
throw new ArgumentNullException("property");
this.property = property;
this.isIndexer = isIndexer;
this.LazyLoading = true;
}
public override object Text {
get { return property.Name + " : " + Language.Current.TypeToString(property.PropertyType); }
}
public override object Icon {
get {
return isIndexer ? Images.Indexer : Images.Property;
}
}
protected override void LoadChildren()
{
if (property.GetMethod != null)
this.Children.Add(new MethodTreeNode(property.GetMethod));
if (property.SetMethod != null)
this.Children.Add(new MethodTreeNode(property.SetMethod));
if (property.HasOtherMethods) {
foreach (var m in property.OtherMethods)
this.Children.Add(new MethodTreeNode(m));
}
}
}
}

34
ILSpy/TypeTreeNode.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Media;
using ICSharpCode.TreeView;
@ -74,8 +75,39 @@ namespace ICSharpCode.ILSpy @@ -74,8 +75,39 @@ namespace ICSharpCode.ILSpy
foreach (FieldDefinition field in type.Fields) {
this.Children.Add(new FieldTreeNode(field));
}
HashSet<MethodDefinition> accessorMethods = new HashSet<MethodDefinition>();
// figure out the name of the indexer:
string defaultMemberName = null;
var defaultMemberAttribute = type.CustomAttributes.FirstOrDefault(
a => a.AttributeType.FullName == typeof(System.Reflection.DefaultMemberAttribute).FullName);
if (defaultMemberAttribute != null && defaultMemberAttribute.ConstructorArguments.Count == 1) {
defaultMemberName = defaultMemberAttribute.ConstructorArguments[0].Value as string;
}
foreach (PropertyDefinition property in type.Properties) {
this.Children.Add(new PropertyTreeNode(property, property.Name == defaultMemberName));
accessorMethods.Add(property.GetMethod);
accessorMethods.Add(property.SetMethod);
if (property.HasOtherMethods) {
foreach (var m in property.OtherMethods)
accessorMethods.Add(m);
}
}
foreach (EventDefinition ev in type.Events) {
this.Children.Add(new EventTreeNode(ev));
accessorMethods.Add(ev.AddMethod);
accessorMethods.Add(ev.RemoveMethod);
accessorMethods.Add(ev.InvokeMethod);
if (ev.HasOtherMethods) {
foreach (var m in ev.OtherMethods)
accessorMethods.Add(m);
}
}
foreach (MethodDefinition method in type.Methods) {
this.Children.Add(new MethodTreeNode(method));
if (!accessorMethods.Contains(method)) {
this.Children.Add(new MethodTreeNode(method));
}
}
}

Loading…
Cancel
Save