Browse Source

Add "Base Types" node.

pull/1/head
Daniel Grunwald 16 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
get { return Images.Assembly; } 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) public override void ActivateItem(System.Windows.RoutedEventArgs e)
{ {
var assemblyListNode = parentAssembly.Parent as AssemblyListTreeNode; var assemblyListNode = parentAssembly.Parent as AssemblyListTreeNode;

89
ILSpy/BaseTypesTreeNode.cs

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

3
ILSpy/Images/Images.cs

@ -21,6 +21,9 @@ namespace ICSharpCode.ILSpy
public static readonly BitmapImage ReferenceFolderOpen = LoadBitmap("ReferenceFolder.Open"); public static readonly BitmapImage ReferenceFolderOpen = LoadBitmap("ReferenceFolder.Open");
public static readonly BitmapImage ReferenceFolderClosed = LoadBitmap("ReferenceFolder.Closed"); 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 Class = LoadBitmap("Class");
public static readonly BitmapImage Delegate = LoadBitmap("Delegate"); 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
} }
#region Fetch Gac Contents #region Fetch Gac Contents
sealed class GacEntry : IEquatable<GacEntry> sealed class GacEntry
{ {
readonly AssemblyNameReference r; readonly AssemblyNameReference r;
readonly string fileName; readonly string fileName;
@ -89,32 +89,21 @@ namespace ICSharpCode.ILSpy
{ {
return r.FullName; 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() void FetchGacContents()
{ {
var entries = HashSet<string> fullNames = new HashSet<string>();
from r in GacInterop.GetGacAssemblyFullNames() foreach (var r in GacInterop.GetGacAssemblyFullNames()) {
let file = GacInterop.FindAssemblyInNetGac(r) if (cancelFetchThread)
where file != null return;
select new GacEntry(r, file); if (fullNames.Add(r.FullName)) { // filter duplicates
foreach (var entry in entries.Distinct()) { var file = GacInterop.FindAssemblyInNetGac(r);
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<GacEntry>(AddNewEntry), entry); 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
get { return type.Name; } get { return type.Name; }
} }
public TypeAttributes Visibility {
get {
return type.Attributes & TypeAttributes.VisibilityMask;
}
}
public bool IsPublicAPI { public bool IsPublicAPI {
get { get {
switch (this.Visibility) { switch (type.Attributes & TypeAttributes.VisibilityMask) {
case TypeAttributes.Public: case TypeAttributes.Public:
case TypeAttributes.NestedPublic: case TypeAttributes.NestedPublic:
case TypeAttributes.NestedFamily: case TypeAttributes.NestedFamily:
@ -58,6 +52,7 @@ namespace ICSharpCode.ILSpy
protected override void LoadChildren() protected override void LoadChildren()
{ {
this.Children.Add(new BaseTypesTreeNode(type));
foreach (TypeDefinition nestedType in type.NestedTypes) { foreach (TypeDefinition nestedType in type.NestedTypes) {
this.Children.Add(new TypeTreeNode(nestedType)); this.Children.Add(new TypeTreeNode(nestedType));
} }
@ -79,7 +74,7 @@ namespace ICSharpCode.ILSpy
Delegate Delegate
} }
ClassType GetClassType() static ClassType GetClassType(TypeDefinition type)
{ {
if (type.IsValueType) { if (type.IsValueType) {
if (type.IsEnum) if (type.IsEnum)
@ -98,46 +93,51 @@ namespace ICSharpCode.ILSpy
public override object Icon { public override object Icon {
get { get {
switch (this.Visibility) { return GetIcon(type);
case TypeAttributes.Public: }
case TypeAttributes.NestedPublic: }
switch (this.GetClassType()) {
case ClassType.Delegate: return Images.Delegate; public static ImageSource GetIcon(TypeDefinition type)
case ClassType.Enum: return Images.Enum; {
case ClassType.Interface: return Images.Interface; switch (type.Attributes & TypeAttributes.VisibilityMask) {
case ClassType.Struct: return Images.Struct; case TypeAttributes.Public:
default: return Images.Class; case TypeAttributes.NestedPublic:
} switch (GetClassType(type)) {
case TypeAttributes.NotPublic: case ClassType.Delegate: return Images.Delegate;
case TypeAttributes.NestedAssembly: case ClassType.Enum: return Images.Enum;
case TypeAttributes.NestedFamANDAssem: case ClassType.Interface: return Images.Interface;
switch (this.GetClassType()) { case ClassType.Struct: return Images.Struct;
case ClassType.Delegate: return Images.InternalDelegate; default: return Images.Class;
case ClassType.Enum: return Images.InternalEnum; }
case ClassType.Interface: return Images.InternalInterface; case TypeAttributes.NotPublic:
case ClassType.Struct: return Images.InternalStruct; case TypeAttributes.NestedAssembly:
default: return Images.InternalClass; case TypeAttributes.NestedFamANDAssem:
} switch (GetClassType(type)) {
case TypeAttributes.NestedFamily: case ClassType.Delegate: return Images.InternalDelegate;
case TypeAttributes.NestedFamORAssem: case ClassType.Enum: return Images.InternalEnum;
switch (this.GetClassType()) { case ClassType.Interface: return Images.InternalInterface;
case ClassType.Delegate: return Images.ProtectedDelegate; case ClassType.Struct: return Images.InternalStruct;
case ClassType.Enum: return Images.ProtectedEnum; default: return Images.InternalClass;
case ClassType.Interface: return Images.ProtectedInterface; }
case ClassType.Struct: return Images.ProtectedStruct; case TypeAttributes.NestedFamily:
default: return Images.ProtectedClass; case TypeAttributes.NestedFamORAssem:
} switch (GetClassType(type)) {
case TypeAttributes.NestedPrivate: case ClassType.Delegate: return Images.ProtectedDelegate;
switch (this.GetClassType()) { case ClassType.Enum: return Images.ProtectedEnum;
case ClassType.Delegate: return Images.PrivateDelegate; case ClassType.Interface: return Images.ProtectedInterface;
case ClassType.Enum: return Images.PrivateEnum; case ClassType.Struct: return Images.ProtectedStruct;
case ClassType.Interface: return Images.PrivateInterface; default: return Images.ProtectedClass;
case ClassType.Struct: return Images.PrivateStruct; }
default: return Images.PrivateClass; case TypeAttributes.NestedPrivate:
} switch (GetClassType(type)) {
default: case ClassType.Delegate: return Images.PrivateDelegate;
throw new NotSupportedException(this.Visibility.ToString()); 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 #endregion

Loading…
Cancel
Save