Browse Source

Add "Base Types" node.

pull/1/head
Daniel Grunwald 14 years ago
parent
commit
0ea5e2fb8a
  1. 8
      ILSpy/AssemblyReferenceTreeNode.cs
  2. 89
      ILSpy/BaseTypesTreeNode.cs
  3. 5
      ILSpy/ILSpy.csproj
  4. 3
      ILSpy/Images/Images.cs
  5. BIN
      ILSpy/Images/Redo.png
  6. BIN
      ILSpy/Images/Undo.png
  7. 35
      ILSpy/OpenFromGacDialog.xaml.cs
  8. 96
      ILSpy/TypeTreeNode.cs

8
ILSpy/AssemblyReferenceTreeNode.cs

@ -35,6 +35,14 @@ namespace ICSharpCode.ILSpy @@ -35,6 +35,14 @@ namespace ICSharpCode.ILSpy
get { return Images.Assembly; }
}
public override bool ShowExpander {
get {
if (r.Name == "mscorlib")
EnsureLazyChildren(); // likely doesn't have any children
return base.ShowExpander;
}
}
public override void ActivateItem(System.Windows.RoutedEventArgs e)
{
var assemblyListNode = parentAssembly.Parent as AssemblyListTreeNode;

89
ILSpy/BaseTypesTreeNode.cs

@ -0,0 +1,89 @@ @@ -0,0 +1,89 @@
// 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>
/// Lists the base types of a class.
/// </summary>
sealed class BaseTypesTreeNode : SharpTreeNode
{
readonly TypeDefinition type;
public BaseTypesTreeNode(TypeDefinition type)
{
this.type = type;
this.LazyLoading = true;
}
public override object Text {
get { return "Base Types"; }
}
public override object Icon {
get { return Images.Undo; }
}
protected override void LoadChildren()
{
AddBaseTypes(this.Children, type);
}
static void AddBaseTypes(SharpTreeNodeCollection children, TypeDefinition type)
{
if (type.BaseType != null)
children.Add(new EntryNode(type.BaseType, false));
foreach (TypeReference i in type.Interfaces) {
children.Add(new EntryNode(i, true));
}
}
sealed class EntryNode : SharpTreeNode
{
TypeReference tr;
TypeDefinition def;
bool isInterface;
public EntryNode(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 {
if (isInterface || tr.FullName == "System.Object")
EnsureLazyChildren(); // need to create children to test whether we have any
return base.ShowExpander;
}
}
public override object Text {
get { return tr.FullName; }
}
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)
AddBaseTypes(this.Children, def);
}
}
}
}

5
ILSpy/ILSpy.csproj

@ -71,6 +71,7 @@ @@ -71,6 +71,7 @@
<Compile Include="AssemblyListTreeNode.cs" />
<Compile Include="AssemblyReferenceTreeNode.cs" />
<Compile Include="AssemblyTreeNode.cs" />
<Compile Include="BaseTypesTreeNode.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="FieldTreeNode.cs" />
<Compile Include="Fusion.cs" />
@ -158,5 +159,9 @@ @@ -158,5 +159,9 @@
<Resource Include="Images\ReferenceFolder.Closed.png" />
<Resource Include="Images\ReferenceFolder.Open.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Redo.png" />
<Resource Include="Images\Undo.png" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

3
ILSpy/Images/Images.cs

@ -21,6 +21,9 @@ namespace ICSharpCode.ILSpy @@ -21,6 +21,9 @@ namespace ICSharpCode.ILSpy
public static readonly BitmapImage ReferenceFolderOpen = LoadBitmap("ReferenceFolder.Open");
public static readonly BitmapImage ReferenceFolderClosed = LoadBitmap("ReferenceFolder.Closed");
public static readonly BitmapImage Redo = LoadBitmap("Redo");
public static readonly BitmapImage Undo = LoadBitmap("Undo");
public static readonly BitmapImage Class = LoadBitmap("Class");
public static readonly BitmapImage Delegate = LoadBitmap("Delegate");

BIN
ILSpy/Images/Redo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 B

BIN
ILSpy/Images/Undo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

35
ILSpy/OpenFromGacDialog.xaml.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.ILSpy @@ -45,7 +45,7 @@ namespace ICSharpCode.ILSpy
}
#region Fetch Gac Contents
sealed class GacEntry : IEquatable<GacEntry>
sealed class GacEntry
{
readonly AssemblyNameReference r;
readonly string fileName;
@ -89,32 +89,21 @@ namespace ICSharpCode.ILSpy @@ -89,32 +89,21 @@ namespace ICSharpCode.ILSpy
{
return r.FullName;
}
public override int GetHashCode()
{
return r.FullName.GetHashCode();
}
public override bool Equals(object obj)
{
return Equals(obj as GacEntry);
}
public bool Equals(GacEntry o)
{
return o != null && r.FullName == o.r.FullName;
}
}
void FetchGacContents()
{
var entries =
from r in GacInterop.GetGacAssemblyFullNames()
let file = GacInterop.FindAssemblyInNetGac(r)
where file != null
select new GacEntry(r, file);
foreach (var entry in entries.Distinct()) {
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<GacEntry>(AddNewEntry), entry);
HashSet<string> fullNames = new HashSet<string>();
foreach (var r in GacInterop.GetGacAssemblyFullNames()) {
if (cancelFetchThread)
return;
if (fullNames.Add(r.FullName)) { // filter duplicates
var file = GacInterop.FindAssemblyInNetGac(r);
if (file != null) {
var entry = new GacEntry(r, file);
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<GacEntry>(AddNewEntry), entry);
}
}
}
}

96
ILSpy/TypeTreeNode.cs

@ -36,15 +36,9 @@ namespace ICSharpCode.ILSpy @@ -36,15 +36,9 @@ namespace ICSharpCode.ILSpy
get { return type.Name; }
}
public TypeAttributes Visibility {
get {
return type.Attributes & TypeAttributes.VisibilityMask;
}
}
public bool IsPublicAPI {
get {
switch (this.Visibility) {
switch (type.Attributes & TypeAttributes.VisibilityMask) {
case TypeAttributes.Public:
case TypeAttributes.NestedPublic:
case TypeAttributes.NestedFamily:
@ -58,6 +52,7 @@ namespace ICSharpCode.ILSpy @@ -58,6 +52,7 @@ namespace ICSharpCode.ILSpy
protected override void LoadChildren()
{
this.Children.Add(new BaseTypesTreeNode(type));
foreach (TypeDefinition nestedType in type.NestedTypes) {
this.Children.Add(new TypeTreeNode(nestedType));
}
@ -79,7 +74,7 @@ namespace ICSharpCode.ILSpy @@ -79,7 +74,7 @@ namespace ICSharpCode.ILSpy
Delegate
}
ClassType GetClassType()
static ClassType GetClassType(TypeDefinition type)
{
if (type.IsValueType) {
if (type.IsEnum)
@ -98,46 +93,51 @@ namespace ICSharpCode.ILSpy @@ -98,46 +93,51 @@ namespace ICSharpCode.ILSpy
public override object Icon {
get {
switch (this.Visibility) {
case TypeAttributes.Public:
case TypeAttributes.NestedPublic:
switch (this.GetClassType()) {
case ClassType.Delegate: return Images.Delegate;
case ClassType.Enum: return Images.Enum;
case ClassType.Interface: return Images.Interface;
case ClassType.Struct: return Images.Struct;
default: return Images.Class;
}
case TypeAttributes.NotPublic:
case TypeAttributes.NestedAssembly:
case TypeAttributes.NestedFamANDAssem:
switch (this.GetClassType()) {
case ClassType.Delegate: return Images.InternalDelegate;
case ClassType.Enum: return Images.InternalEnum;
case ClassType.Interface: return Images.InternalInterface;
case ClassType.Struct: return Images.InternalStruct;
default: return Images.InternalClass;
}
case TypeAttributes.NestedFamily:
case TypeAttributes.NestedFamORAssem:
switch (this.GetClassType()) {
case ClassType.Delegate: return Images.ProtectedDelegate;
case ClassType.Enum: return Images.ProtectedEnum;
case ClassType.Interface: return Images.ProtectedInterface;
case ClassType.Struct: return Images.ProtectedStruct;
default: return Images.ProtectedClass;
}
case TypeAttributes.NestedPrivate:
switch (this.GetClassType()) {
case ClassType.Delegate: return Images.PrivateDelegate;
case ClassType.Enum: return Images.PrivateEnum;
case ClassType.Interface: return Images.PrivateInterface;
case ClassType.Struct: return Images.PrivateStruct;
default: return Images.PrivateClass;
}
default:
throw new NotSupportedException(this.Visibility.ToString());
}
return GetIcon(type);
}
}
public static ImageSource GetIcon(TypeDefinition type)
{
switch (type.Attributes & TypeAttributes.VisibilityMask) {
case TypeAttributes.Public:
case TypeAttributes.NestedPublic:
switch (GetClassType(type)) {
case ClassType.Delegate: return Images.Delegate;
case ClassType.Enum: return Images.Enum;
case ClassType.Interface: return Images.Interface;
case ClassType.Struct: return Images.Struct;
default: return Images.Class;
}
case TypeAttributes.NotPublic:
case TypeAttributes.NestedAssembly:
case TypeAttributes.NestedFamANDAssem:
switch (GetClassType(type)) {
case ClassType.Delegate: return Images.InternalDelegate;
case ClassType.Enum: return Images.InternalEnum;
case ClassType.Interface: return Images.InternalInterface;
case ClassType.Struct: return Images.InternalStruct;
default: return Images.InternalClass;
}
case TypeAttributes.NestedFamily:
case TypeAttributes.NestedFamORAssem:
switch (GetClassType(type)) {
case ClassType.Delegate: return Images.ProtectedDelegate;
case ClassType.Enum: return Images.ProtectedEnum;
case ClassType.Interface: return Images.ProtectedInterface;
case ClassType.Struct: return Images.ProtectedStruct;
default: return Images.ProtectedClass;
}
case TypeAttributes.NestedPrivate:
switch (GetClassType(type)) {
case ClassType.Delegate: return Images.PrivateDelegate;
case ClassType.Enum: return Images.PrivateEnum;
case ClassType.Interface: return Images.PrivateInterface;
case ClassType.Struct: return Images.PrivateStruct;
default: return Images.PrivateClass;
}
default:
throw new NotSupportedException();
}
}
#endregion

Loading…
Cancel
Save