11 changed files with 4 additions and 1018 deletions
@ -1,15 +0,0 @@ |
|||||||
<gui:OptionPanel x:Class="ICSharpCode.SharpDevelop.Gui.OptionPanels.SharpDevelopUIOptions" |
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|
||||||
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui" |
|
||||||
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" |
|
||||||
xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Gui.OptionPanels" |
|
||||||
xmlns:core="http://icsharpcode.net/sharpdevelop/core"> |
|
||||||
<GroupBox Header="{core:Localize Dialog.Options.IDEOptions.SharpDevelop.GeneralUI.GroupBoxHeader}"> |
|
||||||
<widgets:StackPanelWithSpacing SpaceBetweenItems="5"> |
|
||||||
<CheckBox x:Name="ExpandReferencesCheckBox" |
|
||||||
Content="{core:Localize Dialog.Options.IDEOptions.SharpDevelop.GeneralUI.ExpandReferences}" |
|
||||||
IsChecked="{core:OptionBinding local:SharpDevelopUIOptions.ExpandReferences}"/> |
|
||||||
</widgets:StackPanelWithSpacing> |
|
||||||
</GroupBox> |
|
||||||
</gui:OptionPanel> |
|
@ -1,21 +0,0 @@ |
|||||||
// 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.Windows.Controls; |
|
||||||
using ICSharpCode.Core; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels |
|
||||||
{ |
|
||||||
public partial class SharpDevelopUIOptions : OptionPanel |
|
||||||
{ |
|
||||||
public SharpDevelopUIOptions() |
|
||||||
{ |
|
||||||
InitializeComponent(); |
|
||||||
} |
|
||||||
|
|
||||||
public static bool ExpandReferences { |
|
||||||
get { return PropertyService.Get("ExpandReferences", false); } |
|
||||||
set { PropertyService.Set("ExpandReferences", value); } |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,163 +0,0 @@ |
|||||||
// 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 Mono.Cecil; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.Project.InnerExpand |
|
||||||
{ |
|
||||||
public abstract class MemberNode : AbstractProjectBrowserTreeNode |
|
||||||
{ |
|
||||||
protected readonly MemberReference member; |
|
||||||
protected readonly TypeDefinition type; |
|
||||||
|
|
||||||
public MemberNode(string name, MemberReference member, TypeDefinition type) |
|
||||||
{ |
|
||||||
this.member = member; |
|
||||||
this.type = type; |
|
||||||
Text = name; |
|
||||||
} |
|
||||||
|
|
||||||
public override object AcceptVisitor(ProjectBrowserTreeNodeVisitor visitor, object data) |
|
||||||
{ |
|
||||||
return visitor.Visit(this, data); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#region Field nodes
|
|
||||||
public class PublicFieldNode : MemberNode |
|
||||||
{ |
|
||||||
public PublicFieldNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.Field"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class InternalFieldNode : MemberNode |
|
||||||
{ |
|
||||||
public InternalFieldNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.InteralField"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class ProtectedFieldNode : MemberNode |
|
||||||
{ |
|
||||||
public ProtectedFieldNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.ProtectedField"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PrivateFieldNode : MemberNode |
|
||||||
{ |
|
||||||
public PrivateFieldNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.PrivateField"); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Properties nodes
|
|
||||||
public class PublicPropertyNode : MemberNode |
|
||||||
{ |
|
||||||
public PublicPropertyNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.Property"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class InternalPropertyNode : MemberNode |
|
||||||
{ |
|
||||||
public InternalPropertyNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.InteralProperty"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class ProtectedPropertyNode : MemberNode |
|
||||||
{ |
|
||||||
public ProtectedPropertyNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.ProtectedProperty"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PrivatePropertyNode : MemberNode |
|
||||||
{ |
|
||||||
public PrivatePropertyNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.PrivateProperty"); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Method nodes
|
|
||||||
|
|
||||||
public class PublicMethodNode : MemberNode |
|
||||||
{ |
|
||||||
public PublicMethodNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.Method"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class InternalMethodNode : MemberNode |
|
||||||
{ |
|
||||||
public InternalMethodNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.InternalMethod"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class ProtectedMethodNode : MemberNode |
|
||||||
{ |
|
||||||
public ProtectedMethodNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.ProtectedMethod"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PrivateMethodNode : MemberNode |
|
||||||
{ |
|
||||||
public PrivateMethodNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.PrivateMethod"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Event node
|
|
||||||
public class PublicEventNode : MemberNode |
|
||||||
{ |
|
||||||
public PublicEventNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.Event"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class InternalEventNode : MemberNode |
|
||||||
{ |
|
||||||
public InternalEventNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.InternalEvent"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class ProtectedEventNode : MemberNode |
|
||||||
{ |
|
||||||
public ProtectedEventNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.ProtectedEvent"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PrivateEventNode : MemberNode |
|
||||||
{ |
|
||||||
public PrivateEventNode(string name, MemberReference member, TypeDefinition type) : base(name, member, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.PrivateEvent"); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
} |
|
@ -1,101 +0,0 @@ |
|||||||
// 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.Windows; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using ICSharpCode.Core; |
|
||||||
using Mono.Cecil; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.Project.InnerExpand |
|
||||||
{ |
|
||||||
public class NamespaceNode : CustomFolderNode |
|
||||||
{ |
|
||||||
readonly List<TypeDefinition> types; |
|
||||||
|
|
||||||
public NamespaceNode(string name, List<TypeDefinition> types) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.NameSpace"); |
|
||||||
Text = name; |
|
||||||
this.types = types; |
|
||||||
|
|
||||||
this.PerformInitialization(); |
|
||||||
} |
|
||||||
|
|
||||||
public void RefreshNodes(bool forceRefresh = false) |
|
||||||
{ |
|
||||||
if (Nodes.Count > 0 && !forceRefresh) |
|
||||||
return; |
|
||||||
|
|
||||||
Nodes.Clear(); |
|
||||||
|
|
||||||
foreach (var type in types) { |
|
||||||
TypeNode node = null; |
|
||||||
string name = type.Name; |
|
||||||
|
|
||||||
if (type.IsValueType) { |
|
||||||
if (type.IsPublic) { |
|
||||||
node = new PublicStructNode(name, type); |
|
||||||
} else { |
|
||||||
node = new PrivateStructNode(name, type); |
|
||||||
} |
|
||||||
} else { |
|
||||||
if (type.IsEnum) { |
|
||||||
if (type.IsPublic) { |
|
||||||
node = new PublicEnumNode(name, type); |
|
||||||
} else { |
|
||||||
node = new PrivateEnumNode(name, type); |
|
||||||
} |
|
||||||
} else { |
|
||||||
|
|
||||||
if (type.BaseType != null && type.BaseType.FullName == "System.MulticastDelegate"){ |
|
||||||
if (type.IsPublic) { |
|
||||||
node = new PublicDelegateNode(name, type); |
|
||||||
} else { |
|
||||||
node = new PrivateDelegateNode(name, type); |
|
||||||
} |
|
||||||
} else { |
|
||||||
if (type.IsClass) { |
|
||||||
if (type.IsPublic) { |
|
||||||
node = new PublicClassNode(name, type); |
|
||||||
} else { |
|
||||||
node = new PrivateClassNode(name, type); |
|
||||||
} |
|
||||||
} |
|
||||||
else { |
|
||||||
if (type.IsInterface) { |
|
||||||
if (type.IsPublic) { |
|
||||||
node = new PublicInterfaceNode(name, type); |
|
||||||
} else { |
|
||||||
node = new PrivateInterfaceNode(name, type); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (node != null) |
|
||||||
node.InsertSorted(this); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override void Expanding() |
|
||||||
{ |
|
||||||
foreach (var node in Nodes) { |
|
||||||
if (!(node is TypeNode)) continue; |
|
||||||
|
|
||||||
var n = (TypeNode)node; |
|
||||||
n.ShowMembers(); |
|
||||||
} |
|
||||||
|
|
||||||
base.Expanding(); |
|
||||||
} |
|
||||||
|
|
||||||
public override object AcceptVisitor(ProjectBrowserTreeNodeVisitor visitor, object data) |
|
||||||
{ |
|
||||||
return visitor.Visit(this, data); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,279 +0,0 @@ |
|||||||
// 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.Text; |
|
||||||
using Mono.Cecil; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.Project.InnerExpand |
|
||||||
{ |
|
||||||
public abstract class TypeNode : AbstractProjectBrowserTreeNode |
|
||||||
{ |
|
||||||
protected readonly TypeDefinition type; |
|
||||||
|
|
||||||
public TypeNode(string name, TypeDefinition type) |
|
||||||
{ |
|
||||||
Text = name; |
|
||||||
this.type = type; |
|
||||||
|
|
||||||
this.PerformInitialization(); |
|
||||||
} |
|
||||||
|
|
||||||
public virtual void ShowMembers(bool forceRefresh = false) |
|
||||||
{ |
|
||||||
if (Nodes.Count > 0 && !forceRefresh) |
|
||||||
return; |
|
||||||
|
|
||||||
Nodes.Clear(); |
|
||||||
|
|
||||||
foreach (var ev in type.Events) { |
|
||||||
if (ev.AddMethod == null && ev.RemoveMethod == null ) continue; |
|
||||||
|
|
||||||
if (ev.AddMethod != null && !ev.AddMethod.IsPublic && |
|
||||||
ev.RemoveMethod != null && !ev.RemoveMethod.IsPublic) continue; |
|
||||||
|
|
||||||
new PublicEventNode(ev.Name, ev, type).InsertSorted(this); |
|
||||||
} |
|
||||||
|
|
||||||
foreach (var property in type.Properties) { |
|
||||||
if (property.GetMethod == null && property.SetMethod == null ) continue; |
|
||||||
|
|
||||||
if (property.GetMethod != null && !property.GetMethod.IsPublic && |
|
||||||
property.SetMethod != null && !property.SetMethod.IsPublic) continue; |
|
||||||
new PublicPropertyNode(property.Name, property, type).InsertSorted(this); |
|
||||||
} |
|
||||||
|
|
||||||
foreach (var method in type.Methods) { |
|
||||||
if (!method.IsPublic) continue; |
|
||||||
if (method.Name.StartsWith("get_") || method.Name.StartsWith("set_")) continue; |
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(); |
|
||||||
|
|
||||||
if (!method.IsConstructor) { |
|
||||||
sb.Append(method.Name); |
|
||||||
} else { |
|
||||||
sb.Append(method.DeclaringType.Name); |
|
||||||
} |
|
||||||
|
|
||||||
sb.Append(DecompilerService.GetParameters(method)); |
|
||||||
|
|
||||||
new PublicMethodNode(sb.ToString(), method, type).InsertSorted(this); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public override object AcceptVisitor(ProjectBrowserTreeNodeVisitor visitor, object data) |
|
||||||
{ |
|
||||||
return visitor.Visit(this, data); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#region Classes
|
|
||||||
|
|
||||||
public abstract class ClassNode : TypeNode |
|
||||||
{ |
|
||||||
public ClassNode(string name, TypeDefinition type) : base(name, type) { } |
|
||||||
} |
|
||||||
|
|
||||||
public class PublicClassNode : ClassNode |
|
||||||
{ |
|
||||||
public PublicClassNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.Class"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class InternalClassNode : ClassNode |
|
||||||
{ |
|
||||||
public InternalClassNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.InternalClass"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class ProtectedClassNode : ClassNode |
|
||||||
{ |
|
||||||
public ProtectedClassNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.ProtectedClass"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PrivateClassNode : ClassNode |
|
||||||
{ |
|
||||||
public PrivateClassNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.PrivateClass"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Interfaces
|
|
||||||
public abstract class InterfaceNode : TypeNode |
|
||||||
{ |
|
||||||
public InterfaceNode(string name, TypeDefinition type) : base(name, type) { } |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public class PublicInterfaceNode : InterfaceNode |
|
||||||
{ |
|
||||||
public PublicInterfaceNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.Interface"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class InternalInterfaceNode : InterfaceNode |
|
||||||
{ |
|
||||||
public InternalInterfaceNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.InternalInterface"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class ProtectedInterfaceNode : InterfaceNode |
|
||||||
{ |
|
||||||
public ProtectedInterfaceNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.ProtectedInterface"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PrivateInterfaceNode : InterfaceNode |
|
||||||
{ |
|
||||||
public PrivateInterfaceNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.PrivateInterface"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Structs
|
|
||||||
|
|
||||||
public abstract class StructNode : TypeNode |
|
||||||
{ |
|
||||||
public StructNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PublicStructNode : StructNode |
|
||||||
{ |
|
||||||
public PublicStructNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.Struct"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class InternalStructNode : StructNode |
|
||||||
{ |
|
||||||
public InternalStructNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.InternalStruct"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class ProtectedStructNode : StructNode |
|
||||||
{ |
|
||||||
public ProtectedStructNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.ProtectedStruct"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PrivateStructNode : StructNode |
|
||||||
{ |
|
||||||
public PrivateStructNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.PrivateStruct"); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Enums
|
|
||||||
public abstract class EnumNode : TypeNode |
|
||||||
{ |
|
||||||
public EnumNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PublicEnumNode : EnumNode |
|
||||||
{ |
|
||||||
public PublicEnumNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.Enum"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class IntenalEnumNode : EnumNode |
|
||||||
{ |
|
||||||
public IntenalEnumNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.InternalEnum"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class ProtectedEnumNode : EnumNode |
|
||||||
{ |
|
||||||
public ProtectedEnumNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.ProtectedEnum"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PrivateEnumNode : EnumNode |
|
||||||
{ |
|
||||||
public PrivateEnumNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.PrivateEnum"); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Delegates
|
|
||||||
public abstract class DelegateNode : TypeNode |
|
||||||
{ |
|
||||||
public DelegateNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public override void ShowMembers(bool forceRefresh) |
|
||||||
{ |
|
||||||
// do nothing
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PublicDelegateNode : DelegateNode |
|
||||||
{ |
|
||||||
public PublicDelegateNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.Delegate"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class InternalDelegateNode : DelegateNode |
|
||||||
{ |
|
||||||
public InternalDelegateNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.InternalDelegate"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class ProtectedDelegateNode : DelegateNode |
|
||||||
{ |
|
||||||
public ProtectedDelegateNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.ProtectedDelegate"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public class PrivateDelegateNode : DelegateNode |
|
||||||
{ |
|
||||||
public PrivateDelegateNode(string name, TypeDefinition type) : base(name, type) |
|
||||||
{ |
|
||||||
SetIcon("Icons.16x16.PrivateDelegate"); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
} |
|
@ -1,338 +0,0 @@ |
|||||||
// 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.CodeDom; |
|
||||||
using System.CodeDom.Compiler; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.IO; |
|
||||||
using System.Linq; |
|
||||||
using System.Text; |
|
||||||
using System.Windows.Navigation; |
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
|
||||||
using ICSharpCode.SharpDevelop.Gui; |
|
||||||
using ICSharpCode.SharpDevelop.Project; |
|
||||||
using Mono.Cecil; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop |
|
||||||
{ |
|
||||||
public static class DecompilerService |
|
||||||
{ |
|
||||||
public static string GetParameters(MethodDefinition method) |
|
||||||
{ |
|
||||||
StringBuilder sb = new StringBuilder(); |
|
||||||
|
|
||||||
if (!method.HasParameters) |
|
||||||
sb.Append("()"); |
|
||||||
else { |
|
||||||
sb.Append("("); |
|
||||||
for (int i = 0 ; i < method.Parameters.Count; ++i) { |
|
||||||
var p = method.Parameters[i]; |
|
||||||
|
|
||||||
if (p.IsOut) |
|
||||||
sb.Append("out "); |
|
||||||
else |
|
||||||
if (p.ParameterType.IsByReference) |
|
||||||
sb.Append("ref "); |
|
||||||
|
|
||||||
sb.Append(p.ParameterType.Name.Replace("&", string.Empty)); |
|
||||||
sb.Append(" "); |
|
||||||
|
|
||||||
sb.Append(p.Name); |
|
||||||
|
|
||||||
if (i < method.Parameters.Count - 1) |
|
||||||
sb.Append(", "); |
|
||||||
} |
|
||||||
sb.Append(")"); |
|
||||||
} |
|
||||||
|
|
||||||
return sb.ToString(); |
|
||||||
} |
|
||||||
|
|
||||||
public static void ReadMetadata(IClass c, out string filePath) |
|
||||||
{ |
|
||||||
if (c == null) { |
|
||||||
filePath = null; |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
CodeCompileUnit compileUnit = new CodeCompileUnit(); |
|
||||||
|
|
||||||
// add namespace
|
|
||||||
CodeNamespace generatedNamespace = new CodeNamespace(c.Namespace); |
|
||||||
generatedNamespace.Imports.Add(new CodeNamespaceImport("System")); |
|
||||||
compileUnit.Namespaces.Add(generatedNamespace); |
|
||||||
|
|
||||||
// add type
|
|
||||||
var targetClass = new CodeTypeDeclaration(c.Name); |
|
||||||
|
|
||||||
// write attributes
|
|
||||||
AddAttributes(c, targetClass); |
|
||||||
|
|
||||||
// write class definition
|
|
||||||
if (c.IsPublic) targetClass.TypeAttributes |= System.Reflection.TypeAttributes.Public; |
|
||||||
if (c.IsSealed) targetClass.TypeAttributes |= System.Reflection.TypeAttributes.Sealed; |
|
||||||
// static class limitation - c.IsStatic: https://connect.microsoft.com/VisualStudio/feedback/details/93653/codedom-unable-to-generate-static-events-and-classes
|
|
||||||
targetClass.IsPartial = c.IsPartial; |
|
||||||
|
|
||||||
switch (c.ClassType) { |
|
||||||
case ClassType.Class: |
|
||||||
targetClass.IsClass = true; |
|
||||||
break; |
|
||||||
case ClassType.Enum: |
|
||||||
targetClass.IsEnum = true; |
|
||||||
break; |
|
||||||
case ClassType.Interface: |
|
||||||
targetClass.IsInterface = true; |
|
||||||
break; |
|
||||||
case ClassType.Struct: |
|
||||||
targetClass.IsStruct = true; |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
// generics
|
|
||||||
foreach (var typeParameter in c.TypeParameters) { |
|
||||||
var tp = new CodeTypeParameter(typeParameter.Name); |
|
||||||
foreach (var con in typeParameter.Constraints) { |
|
||||||
tp.Constraints.Add(con.Name); |
|
||||||
} |
|
||||||
targetClass.TypeParameters.Add(tp); |
|
||||||
} |
|
||||||
|
|
||||||
// base types
|
|
||||||
foreach (var basetype in c.BaseTypes) { |
|
||||||
if (basetype.FullyQualifiedName.Equals("System.Object", StringComparison.OrdinalIgnoreCase)) |
|
||||||
continue; |
|
||||||
var baseType = AddGenericBaseTypes(basetype); |
|
||||||
targetClass.BaseTypes.Add(baseType); |
|
||||||
} |
|
||||||
|
|
||||||
// field members
|
|
||||||
foreach (var f in c.Fields) { |
|
||||||
if (!f.IsPublic && !f.IsProtected) continue; |
|
||||||
|
|
||||||
CodeMemberField field = new CodeMemberField() { Name = f.Name, |
|
||||||
Attributes = MemberAttributes.Public }; |
|
||||||
AddDefinition(f, field); |
|
||||||
AddAttributes(f, field); |
|
||||||
AddDocumentation(f, field); |
|
||||||
|
|
||||||
field.Type = new CodeTypeReference(f.ReturnType.FullyQualifiedName); |
|
||||||
targetClass.Members.Add(field); |
|
||||||
} |
|
||||||
|
|
||||||
// event members
|
|
||||||
foreach (var e in c.Events) { |
|
||||||
if (!e.IsPublic && !e.IsProtected) continue; |
|
||||||
CodeMemberEvent ev = new CodeMemberEvent() { Name = e.Name, |
|
||||||
Attributes = MemberAttributes.Public, |
|
||||||
Type = new CodeTypeReference(e.ReturnType.FullyQualifiedName) }; |
|
||||||
AddDefinition(e, ev); |
|
||||||
AddDocumentation(e, ev); |
|
||||||
|
|
||||||
targetClass.Members.Add(ev); |
|
||||||
} |
|
||||||
|
|
||||||
// properties
|
|
||||||
foreach (var property in c.Properties) { |
|
||||||
if (!property.IsPublic && !property.IsProtected) continue; |
|
||||||
CodeMemberProperty p = new CodeMemberProperty() { |
|
||||||
Name = property.Name, |
|
||||||
Attributes = MemberAttributes.Public, |
|
||||||
Type = new CodeTypeReference(property.ReturnType.FullyQualifiedName), |
|
||||||
HasGet = property.CanGet, |
|
||||||
HasSet = property.CanSet |
|
||||||
}; |
|
||||||
|
|
||||||
AddAttributes(property, p); |
|
||||||
AddDefinition(property, p); |
|
||||||
AddDocumentation(property, p); |
|
||||||
|
|
||||||
if (property.IsIndexer) { |
|
||||||
p.Parameters.Add(new CodeParameterDeclarationExpression("System.Int32", "index")); |
|
||||||
} |
|
||||||
targetClass.Members.Add(p); |
|
||||||
} |
|
||||||
|
|
||||||
// methods and constructors
|
|
||||||
foreach (var method in c.Methods) { |
|
||||||
if (!method.IsPublic && !method.IsProtected) continue; |
|
||||||
|
|
||||||
if (method.IsConstructor) { |
|
||||||
CodeConstructor constructor = new CodeConstructor() { Name = c.Name, |
|
||||||
Attributes = MemberAttributes.Public }; |
|
||||||
AddAttributes(method, constructor); |
|
||||||
AddDefinition(method, constructor); |
|
||||||
AddParameters(method, constructor); |
|
||||||
AddDocumentation(method, constructor); |
|
||||||
|
|
||||||
targetClass.Members.Add(constructor); |
|
||||||
} else { |
|
||||||
CodeMemberMethod m = new CodeMemberMethod() { |
|
||||||
Name = method.Name, |
|
||||||
Attributes = MemberAttributes.Public, |
|
||||||
ReturnType = new CodeTypeReference(method.ReturnType.FullyQualifiedName), |
|
||||||
}; |
|
||||||
|
|
||||||
AddAttributes(method, m); |
|
||||||
AddDefinition(method, m); |
|
||||||
AddParameters(method, m); |
|
||||||
AddDocumentation(method, m); |
|
||||||
|
|
||||||
targetClass.Members.Add(m); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// delegates
|
|
||||||
foreach (var inner in c.InnerClasses) { |
|
||||||
if (inner.ClassType == ClassType.Delegate) { |
|
||||||
IMethod invoker = inner.Methods.Where(method => method.Name == "Invoke").FirstOrDefault(); |
|
||||||
CodeTypeDelegate del = new CodeTypeDelegate(inner.Name) { |
|
||||||
Attributes = MemberAttributes.Public, |
|
||||||
ReturnType = new CodeTypeReference(invoker.ReturnType.FullyQualifiedName) |
|
||||||
}; |
|
||||||
|
|
||||||
AddDocumentation(invoker, del); |
|
||||||
|
|
||||||
foreach (var p in invoker.Parameters) |
|
||||||
del.Parameters.Add(new CodeParameterDeclarationExpression(p.ReturnType.FullyQualifiedName, p.Name)); |
|
||||||
|
|
||||||
targetClass.Members.Add(del); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// add class
|
|
||||||
generatedNamespace.Types.Add(targetClass); |
|
||||||
filePath = WriteTempFile(c.Name, compileUnit); |
|
||||||
} |
|
||||||
|
|
||||||
static CodeTypeReference AddGenericBaseTypes(IReturnType basetype) |
|
||||||
{ |
|
||||||
string type = basetype.FullyQualifiedName; |
|
||||||
CodeTypeReference baseType = new CodeTypeReference(type); |
|
||||||
if (basetype.IsConstructedReturnType) |
|
||||||
{ |
|
||||||
var constructed = basetype as ConstructedReturnType; |
|
||||||
int i = 0; |
|
||||||
foreach (var typearg in constructed.TypeArguments) { |
|
||||||
baseType.TypeArguments.Add(new CodeTypeReference(typearg.Name, CodeTypeReferenceOptions.GenericTypeParameter)); |
|
||||||
|
|
||||||
if (typearg is ConstructedReturnType) { |
|
||||||
CodeTypeReference baseType1 = new CodeTypeReference(typearg.FullyQualifiedName); |
|
||||||
baseType1.TypeArguments.Add(AddGenericBaseTypes(typearg)); |
|
||||||
baseType.TypeArguments[i].TypeArguments.Add(baseType1); |
|
||||||
} |
|
||||||
++i; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return baseType; |
|
||||||
} |
|
||||||
|
|
||||||
static void AddParameters(IMethod method, CodeMemberMethod m) |
|
||||||
{ |
|
||||||
foreach (var p in method.Parameters) { |
|
||||||
string returnType = p.ReturnType.FullyQualifiedName; |
|
||||||
|
|
||||||
var par = new CodeParameterDeclarationExpression(returnType, p.Name); |
|
||||||
|
|
||||||
if (p.ReturnType.IsConstructedReturnType) |
|
||||||
{ |
|
||||||
CodeTypeReference baseType = new CodeTypeReference(returnType); |
|
||||||
var c = p.ReturnType as ConstructedReturnType; |
|
||||||
foreach (var typearg in c.TypeArguments) { |
|
||||||
baseType.TypeArguments.Add(new CodeTypeReference(typearg.Name, CodeTypeReferenceOptions.GenericTypeParameter)); |
|
||||||
} |
|
||||||
|
|
||||||
par.Type = baseType; |
|
||||||
} |
|
||||||
|
|
||||||
if (p.IsRef) |
|
||||||
par.Direction = FieldDirection.Ref; |
|
||||||
if (p.IsOut) |
|
||||||
par.Direction = FieldDirection.Out; |
|
||||||
if (p.IsParams) |
|
||||||
par.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.ParamArrayAttribute)))); |
|
||||||
// TODO: if (p.IsOptional)
|
|
||||||
|
|
||||||
m.Parameters.Add(par); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
static void AddDocumentation(IEntity entity, CodeTypeMember member) |
|
||||||
{ |
|
||||||
if (string.IsNullOrEmpty(entity.Documentation) || string.IsNullOrEmpty(entity.Documentation.Trim())) |
|
||||||
return; |
|
||||||
|
|
||||||
member.Comments.Add(new CodeCommentStatement(entity.Documentation.Replace(" ", string.Empty), true)); |
|
||||||
} |
|
||||||
|
|
||||||
static void AddDefinition(IEntity entity, CodeTypeMember member) |
|
||||||
{ |
|
||||||
if (entity.IsProtected) |
|
||||||
member.Attributes = MemberAttributes.Family; |
|
||||||
|
|
||||||
if (entity.IsStatic) |
|
||||||
member.Attributes |= MemberAttributes.Static; |
|
||||||
if (entity.IsNew) |
|
||||||
member.Attributes |= MemberAttributes.New; |
|
||||||
if (entity.IsOverride) |
|
||||||
member.Attributes |= MemberAttributes.Override; |
|
||||||
if (entity.IsAbstract) |
|
||||||
member.Attributes |= MemberAttributes.Abstract; |
|
||||||
if (entity.IsVirtual) |
|
||||||
member.Attributes |= MemberAttributes.Final; |
|
||||||
if (entity.IsConst) |
|
||||||
member.Attributes |= MemberAttributes.Const; |
|
||||||
} |
|
||||||
|
|
||||||
static void AddAttributes(IEntity entity, CodeTypeMember member) |
|
||||||
{ |
|
||||||
// write attributes
|
|
||||||
foreach (var attr in entity.Attributes) { |
|
||||||
|
|
||||||
List<CodeAttributeArgument> list = new List<CodeAttributeArgument>(); |
|
||||||
for (int i = 0; i < attr.PositionalArguments.Count; i++) { |
|
||||||
if (!(attr.PositionalArguments[i] is IReturnType)) |
|
||||||
list.Add(new CodeAttributeArgument(new CodePrimitiveExpression(attr.PositionalArguments[i]))); |
|
||||||
} |
|
||||||
|
|
||||||
if (list.Count == 0) { |
|
||||||
member.CustomAttributes.Add( |
|
||||||
new CodeAttributeDeclaration(attr.AttributeType.FullyQualifiedName)); |
|
||||||
} else { |
|
||||||
member.CustomAttributes.Add( |
|
||||||
new CodeAttributeDeclaration(attr.AttributeType.FullyQualifiedName, list.ToArray())); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
static string WriteTempFile(string fileName, CodeCompileUnit compileUnit) |
|
||||||
{ |
|
||||||
// temp file
|
|
||||||
string tempFolder = Path.GetTempPath(); |
|
||||||
string file = fileName + ".temp." + |
|
||||||
ProjectService.CurrentProject.LanguageProperties.CodeDomProvider.FileExtension; |
|
||||||
|
|
||||||
string filePath = Path.Combine(tempFolder, file); |
|
||||||
|
|
||||||
if (File.Exists(filePath)) |
|
||||||
File.SetAttributes(filePath, FileAttributes.Temporary); |
|
||||||
|
|
||||||
// write file
|
|
||||||
using (var sw = new StreamWriter(filePath, false)) |
|
||||||
{ |
|
||||||
ProjectService |
|
||||||
.CurrentProject |
|
||||||
.LanguageProperties |
|
||||||
.CodeDomProvider.GenerateCodeFromCompileUnit( |
|
||||||
compileUnit, |
|
||||||
sw, |
|
||||||
new CodeGeneratorOptions()); |
|
||||||
} |
|
||||||
|
|
||||||
File.SetAttributes(filePath, FileAttributes.ReadOnly); |
|
||||||
return filePath; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue