Inheritance: ILSpyTreeNode, IMemberTreeNode
コード例 #1
0
ファイル: ModuleTreeNode.cs プロジェクト: 95ulisse/ILEdit
 protected override void LoadChildren()
 {
     this.Children.Add(new ReferenceFolderTreeNode(module, assemblyNode));
     if (module.HasResources)
         this.Children.Add(new ResourceListTreeNode(module));
     foreach (NamespaceTreeNode ns in namespaces.Values)
     {
         ns.Children.Clear();
     }
     foreach (TypeDefinition type in module.Types.OrderBy(t => t.FullName))
     {
         NamespaceTreeNode ns;
         if (!namespaces.TryGetValue(type.Namespace, out ns))
         {
             ns = new NamespaceTreeNode(type.Namespace);
             namespaces[type.Namespace] = ns;
         }
         TypeTreeNode node = new TypeTreeNode(type, assemblyNode);
         typeDict[type] = node;
         ns.Children.Add(node);
     }
     foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name))
     {
         if (ns.Children.Count > 0)
             this.Children.Add(ns);
     }
 }
コード例 #2
0
ファイル: NamespaceTreeNode.cs プロジェクト: arkanoid1/dnSpy
		internal void Append(TypeTreeNode typeNode) {
			bool b = name.Equals(typeNode.Namespace, StringComparison.Ordinal);
			Debug.Assert(b);
			if (!b)
				throw new InvalidOperationException();
			Children.Add(typeNode);
			((AssemblyTreeNode)Parent).OnReadded(typeNode);
		}
コード例 #3
0
ファイル: TypeDefCommands.cs プロジェクト: se7ensoft/dnSpy
        CreateNestedTypeDefCommand(TypeTreeNode ownerType, TypeDefOptions options)
        {
            this.ownerType = ownerType;

            var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerType);
            Debug.Assert(modNode != null);
            if (modNode == null)
                throw new InvalidOperationException();
            this.nestedType = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode);
        }
コード例 #4
0
ファイル: AssemblyListTreeNode.cs プロジェクト: zwkjgs/ILSpy
        /// <summary>
        /// Looks up the property node corresponding to the property definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public PropertyTreeNode FindPropertyNode(IProperty def)
        {
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringTypeDefinition);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureLazyChildren();
            return(typeNode.Children.OfType <PropertyTreeNode>().FirstOrDefault(m => m.PropertyDefinition.MetadataToken == def.MetadataToken && !m.IsHidden));
        }
コード例 #5
0
ファイル: AssemblyListTreeNode.cs プロジェクト: zwkjgs/ILSpy
        /// <summary>
        /// Looks up the event node corresponding to the event definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public EventTreeNode FindEventNode(IEvent def)
        {
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringTypeDefinition);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureLazyChildren();
            return(typeNode.Children.OfType <EventTreeNode>().FirstOrDefault(m => m.EventDefinition.MetadataToken == def.MetadataToken && !m.IsHidden));
        }
コード例 #6
0
        internal void Append(TypeTreeNode typeNode)
        {
            bool b = name.Equals(typeNode.Namespace, StringComparison.Ordinal);

            Debug.Assert(b);
            if (!b)
            {
                throw new InvalidOperationException();
            }
            Children.Add(typeNode);
            ((AssemblyTreeNode)Parent).OnReadded(typeNode);
        }
コード例 #7
0
        /// <summary>
        /// Looks up the method node corresponding to the method definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public ILSpyTreeNode FindMethodNode(IMethod def)
        {
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringTypeDefinition);

            if (typeNode == null)
            {
                return(null);
            }
            // method might be an accessor, must look for parent node
            ILSpyTreeNode  parentNode = typeNode;
            MethodTreeNode methodNode;

            parentNode.EnsureLazyChildren();
            switch (def.AccessorOwner)
            {
            case IProperty p:
                parentNode = parentNode.Children.OfType <PropertyTreeNode>().FirstOrDefault(m => m.PropertyDefinition.MetadataToken == p.MetadataToken && !m.IsHidden);
                if (parentNode == null)
                {
                    return(null);
                }
                parentNode.EnsureLazyChildren();
                methodNode = parentNode.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition.MetadataToken == def.MetadataToken && !m.IsHidden);
                if (methodNode == null || methodNode.IsHidden)
                {
                    return(parentNode);
                }
                return(methodNode);

            case IEvent e:
                parentNode = parentNode.Children.OfType <EventTreeNode>().FirstOrDefault(m => m.EventDefinition.MetadataToken == e.MetadataToken && !m.IsHidden);
                if (parentNode == null)
                {
                    return(null);
                }
                parentNode.EnsureLazyChildren();
                methodNode = parentNode.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition.MetadataToken == def.MetadataToken && !m.IsHidden);
                if (methodNode == null || methodNode.IsHidden)
                {
                    return(parentNode);
                }
                return(methodNode);

            default:
                methodNode = typeNode.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition.MetadataToken == def.MetadataToken && !m.IsHidden);
                if (methodNode != null)
                {
                    return(methodNode);
                }
                return(null);
            }
        }
コード例 #8
0
        internal TypeTreeNode GetOrCreateNestedTypeTreeNode(TypeDef nestedType)
        {
            Debug.Assert(nestedType != null && nestedType.DeclaringType == type);
            EnsureChildrenFiltered();
            var typeNode = Children.OfType <TypeTreeNode>().FirstOrDefault(n => n.type == nestedType);

            if (typeNode != null)
            {
                return(typeNode);
            }
            typeNode = new TypeTreeNode(nestedType, parentAssemblyNode);
            AddToChildren(typeNode);
            return(typeNode);
        }
コード例 #9
0
        /// <summary>
        /// Looks up the method node corresponding to the method definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public ILSpyTreeNode FindMethodNode(MethodDefinition def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureLazyChildren();
            MethodTreeNode methodNode = typeNode.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def && !m.IsHidden);

            if (methodNode != null)
            {
                return(methodNode);
            }
            foreach (var p in typeNode.Children.OfType <ILSpyTreeNode>())
            {
                if (p.IsHidden)
                {
                    continue;
                }

                // method might be a child of a property or event
                if (p is PropertyTreeNode || p is EventTreeNode)
                {
                    p.EnsureLazyChildren();
                    methodNode = p.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def);
                    if (methodNode != null)
                    {
                        // If the requested method is a property or event accessor, and accessors are
                        // hidden in the UI, then return the owning property or event.
                        if (methodNode.IsHidden)
                        {
                            return(p);
                        }
                        else
                        {
                            return(methodNode);
                        }
                    }
                }
            }

            return(null);
        }
コード例 #10
0
        /// <summary>
        /// Looks up the event node corresponding to the event definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public EventTreeNode FindEventNode(EventDef def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureChildrenFiltered();
            return(typeNode.Children.OfType <EventTreeNode>().FirstOrDefault(m => m.EventDefinition == def));
        }
コード例 #11
0
        /// <summary>
        /// Looks up the property node corresponding to the property definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public PropertyTreeNode FindPropertyNode(PropertyDef def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureLazyChildren();
            return(typeNode.Children.OfType <PropertyTreeNode>().FirstOrDefault(m => m.PropertyDefinition == def && !m.IsHidden));
        }
コード例 #12
0
        /// <summary>
        /// Looks up the property node corresponding to the property definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public PropertyTreeNode FindPropertyNode(PropertyDef def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureChildrenFiltered();
            return(typeNode.Children.OfType <PropertyTreeNode>().FirstOrDefault(m => m.PropertyDef == def));
        }
コード例 #13
0
        /// <summary>
        /// Looks up the event node corresponding to the event definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public EventTreeNode FindEventNode(EventDefinition def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureLazyChildren();
            return(typeNode.Children.OfType <EventTreeNode>().FirstOrDefault(m => m.EventDefinition == def && !m.IsHidden));
        }
コード例 #14
0
        /// <summary>
        /// Looks up the field node corresponding to the field definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public FieldTreeNode FindFieldNode(FieldDef def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureChildrenFiltered();
            return(typeNode.Children.OfType <FieldTreeNode>().FirstOrDefault(m => m.FieldDef == def));
        }
コード例 #15
0
        protected override void LoadChildren()
        {
            var module = LoadedAssembly.GetPEFileOrNull();

            if (module == null)
            {
                // if we crashed on loading, then we don't have any children
                return;
            }
            typeSystem = LoadedAssembly.GetTypeSystemOrNull(DecompilerTypeSystem.GetOptions(new DecompilationOptions().DecompilerSettings));
            var assembly = (MetadataModule)typeSystem.MainModule;
            var metadata = module.Metadata;

            this.Children.Add(new Metadata.MetadataTreeNode(module, this));
            Decompiler.DebugInfo.IDebugInfoProvider debugInfo = LoadedAssembly.GetDebugInfoOrNull();
            if (debugInfo is Decompiler.PdbProvider.PortableDebugInfoProvider ppdb)
            {
                this.Children.Add(new Metadata.DebugMetadataTreeNode(module, ppdb.IsEmbedded, ppdb.Provider.GetMetadataReader(), this));
            }
            this.Children.Add(new ReferenceFolderTreeNode(module, this));
            if (module.Resources.Any())
            {
                this.Children.Add(new ResourceListTreeNode(module));
            }
            foreach (NamespaceTreeNode ns in namespaces.Values)
            {
                ns.Children.Clear();
            }
            foreach (var type in assembly.TopLevelTypeDefinitions.OrderBy(t => t.ReflectionName, NaturalStringComparer.Instance))
            {
                var escapedNamespace = Language.EscapeName(type.Namespace);
                if (!namespaces.TryGetValue(type.Namespace, out NamespaceTreeNode ns))
                {
                    ns = new NamespaceTreeNode(escapedNamespace);
                    namespaces.Add(type.Namespace, ns);
                }
                TypeTreeNode node = new TypeTreeNode(type, this);
                typeDict[(TypeDefinitionHandle)type.MetadataToken] = node;
                ns.Children.Add(node);
            }
            foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name, NaturalStringComparer.Instance))
            {
                if (ns.Children.Count > 0)
                {
                    this.Children.Add(ns);
                }
            }
        }
コード例 #16
0
        internal TypeTreeNode GetOrCreateNonNestedTypeTreeNode(TypeDef td)
        {
            Debug.Assert(td != null && td.DeclaringType == null);
            Debug.Assert(!LazyLoading);
            TypeTreeNode typeNode;

            if (typeDict.TryGetValue(td, out typeNode))
            {
                return(typeNode);
            }
            var nsNode = GetOrCreateNamespaceNode(td.Namespace);

            typeNode = new TypeTreeNode(td, this);
            typeDict.Add(td, typeNode);
            nsNode.AddToChildren(typeNode);
            return(typeNode);
        }
コード例 #17
0
 /// <summary>
 /// Looks up the type node corresponding to the type definition.
 /// Returns null if no matching node is found.
 /// </summary>
 public TypeTreeNode FindTypeNode(TypeDefinition def)
 {
     if (def == null)
     {
         return(null);
     }
     if (def.DeclaringType != null)
     {
         TypeTreeNode decl = FindTypeNode(def.DeclaringType);
         if (decl != null)
         {
             decl.EnsureLazyChildren();
             return(decl.Children.OfType <TypeTreeNode>().FirstOrDefault(t => t.TypeDefinition == def && !t.IsHidden));
         }
     }
     else
     {
         if (def.Module.Assembly == null) //def.Module.Assembly is null in secodary modules ...
         {
             foreach (AssemblyTreeNode node in this.Children)
             {
                 if (node.LoadedAssembly.IsLoaded)
                 {
                     var t = node.FindTypeNode(def);
                     if (t != null)
                     {
                         return(t);
                     }
                 }
             }
             return(null);
         }
         else
         {
             AssemblyTreeNode asm = FindAssemblyNode(def.Module.Assembly);
             if (asm != null)
             {
                 return(asm.FindTypeNode(def));
             }
         }
     }
     return(null);
 }
コード例 #18
0
        void LoadModuleChildren(IPEImage peImage, ModuleDef module)
        {
            var asmListTreeNode = this.Ancestors().OfType <DnSpyFileListTreeNode>().FirstOrDefault();

            Debug.Assert(asmListTreeNode != null);
            // Only show the PE node if it was loaded from a file. The hex document is always loaded
            // from a file, so if the PEImage wasn't loaded from the same file, conversion to/from
            // RVA/FileOffset won't work and the wrong data will be displayed, eg. in the .NET
            // storage stream nodes.
            if (DnSpyFile.LoadedFromFile && peImage != null)
            {
                this.Children.Add(new PETreeNode(peImage, module as ModuleDefMD));
            }
            if (module != null)
            {
                this.Children.Add(new ReferenceFolderTreeNode(module, this, asmListTreeNode));
                this.Children.Add(new ResourceListTreeNode(module));
                foreach (NamespaceTreeNode ns in namespaces.Values)
                {
                    ns.Children.Clear();
                }
                foreach (TypeDef type in module.Types.OrderBy(t => t.FullName, TypeStringComparer))
                {
                    NamespaceTreeNode ns;
                    if (!namespaces.TryGetValue(type.Namespace, out ns))
                    {
                        ns = new NamespaceTreeNode(type.Namespace);
                        namespaces[type.Namespace] = ns;
                    }
                    TypeTreeNode node = new TypeTreeNode(type, this);
                    typeDict[type] = node;
                    ns.Children.Add(node);
                }
                foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name))
                {
                    if (ns.Children.Count > 0)
                    {
                        this.Children.Add(ns);
                    }
                }
            }
        }
コード例 #19
0
        protected override void LoadChildren()
        {
            ModuleDef moduleDefinition = assembly.ModuleDefinition;

            if (moduleDefinition == null)
            {
                // if we crashed on loading, then we don't have any children
                return;
            }

            if (moduleDefinition is ModuleDefMD)
            {
                this.Children.Add(new ReferenceFolderTreeNode((ModuleDefMD)moduleDefinition, this));
            }
            if (moduleDefinition.HasResources)
            {
                this.Children.Add(new ResourceListTreeNode(moduleDefinition));
            }
            foreach (NamespaceTreeNode ns in namespaces.Values)
            {
                ns.Children.Clear();
            }
            foreach (TypeDef type in moduleDefinition.Types.OrderBy(t => t.FullName))
            {
                NamespaceTreeNode ns;
                if (!namespaces.TryGetValue(type.Namespace, out ns))
                {
                    ns = new NamespaceTreeNode(type.Namespace);
                    namespaces[type.Namespace] = ns;
                }
                TypeTreeNode node = new TypeTreeNode(type, this);
                typeDict[type] = node;
                ns.Children.Add(node);
            }
            foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name))
            {
                if (ns.Children.Count > 0)
                {
                    this.Children.Add(ns);
                }
            }
        }
コード例 #20
0
        protected override void LoadChildren()
        {
            var module = LoadedAssembly.GetPEFileOrNull();

            if (module == null)
            {
                // if we crashed on loading, then we don't have any children
                return;
            }
            typeSystem = LoadedAssembly.GetTypeSystemOrNull();
            var assembly = (MetadataModule)typeSystem.MainModule;
            var metadata = module.Metadata;

            this.Children.Add(new ReferenceFolderTreeNode(module, this));
            if (module.Resources.Any())
            {
                this.Children.Add(new ResourceListTreeNode(module));
            }
            foreach (NamespaceTreeNode ns in namespaces.Values)
            {
                ns.Children.Clear();
            }
            foreach (var type in assembly.TopLevelTypeDefinitions.OrderBy(t => t.ReflectionName, NaturalStringComparer.Instance))
            {
                if (!namespaces.TryGetValue(type.Namespace, out NamespaceTreeNode ns))
                {
                    ns = new NamespaceTreeNode(type.Namespace);
                    namespaces[type.Namespace] = ns;
                }
                TypeTreeNode node = new TypeTreeNode(type, this);
                typeDict[(TypeDefinitionHandle)type.MetadataToken] = node;
                ns.Children.Add(node);
            }
            foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name, NaturalStringComparer.Instance))
            {
                if (ns.Children.Count > 0)
                {
                    this.Children.Add(ns);
                }
            }
        }
コード例 #21
0
        void LoadModuleChildren(IPEImage peImage, ModuleDef module)
        {
            var asmListTreeNode = this.Ancestors().OfType <AssemblyListTreeNode>().FirstOrDefault();

            Debug.Assert(asmListTreeNode != null);
            if (peImage != null)
            {
                this.Children.Add(new PETreeNode(peImage, module as ModuleDefMD));
            }
            if (module != null)
            {
                if (module is ModuleDefMD)
                {
                    this.Children.Add(new ReferenceFolderTreeNode((ModuleDefMD)module, this, asmListTreeNode));
                }
                this.Children.Add(new ResourceListTreeNode(module));
                foreach (NamespaceTreeNode ns in namespaces.Values)
                {
                    ns.Children.Clear();
                }
                foreach (TypeDef type in module.Types.OrderBy(t => t.FullName, TypeStringComparer))
                {
                    NamespaceTreeNode ns;
                    if (!namespaces.TryGetValue(type.Namespace, out ns))
                    {
                        ns = new NamespaceTreeNode(type.Namespace);
                        namespaces[type.Namespace] = ns;
                    }
                    TypeTreeNode node = new TypeTreeNode(type, this);
                    typeDict[type] = node;
                    ns.Children.Add(node);
                }
                foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name))
                {
                    if (ns.Children.Count > 0)
                    {
                        this.Children.Add(ns);
                    }
                }
            }
        }
コード例 #22
0
        /// <summary>
        /// Looks up the method node corresponding to the method definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public MethodTreeNode FindMethodNode(MethodDefinition def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureLazyChildren();
            MethodTreeNode methodNode = typeNode.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def && !m.IsHidden);

            if (methodNode != null)
            {
                return(methodNode);
            }
            foreach (var p in typeNode.Children.OfType <ILSpyTreeNode>())
            {
                if (p.IsHidden)
                {
                    continue;
                }
                // method might be a child or a property or events
                p.EnsureLazyChildren();
                methodNode = p.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def && !m.IsHidden);
                if (methodNode != null)
                {
                    return(methodNode);
                }
            }

            return(null);
        }
コード例 #23
0
ファイル: EventDefCommands.cs プロジェクト: BahNahNah/dnSpy
 CreateEventDefCommand(TypeTreeNode ownerNode, EventDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.eventNode = new EventTreeNode(options.CreateEventDef(ownerNode.TypeDefinition.Module));
 }
コード例 #24
0
ファイル: EventDefCommands.cs プロジェクト: BahNahNah/dnSpy
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var ownerNode = nodes[0];
            if (!(ownerNode is TypeTreeNode))
                ownerNode = (ILSpyTreeNode)ownerNode.Parent;
            var typeNode = ownerNode as TypeTreeNode;
            Debug.Assert(typeNode != null);
            if (typeNode == null)
                throw new InvalidOperationException();

            var module = ILSpyTreeNode.GetModule(typeNode);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();
            var options = EventDefOptions.Create("MyEvent", module.CorLibTypes.GetTypeRef("System", "EventHandler"));

            var data = new EventOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, typeNode.TypeDefinition);
            var win = new EventOptionsDlg();
            win.Title = "Create Event";
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            UndoCommandManager.Instance.Add(new CreateEventDefCommand(typeNode, data.CreateEventDefOptions()));
        }
コード例 #25
0
ファイル: AssemblyTreeNode.cs プロジェクト: gsong2014/dnSpy
 void LoadModuleChildren(ModuleDef moduleDefinition)
 {
     var asmListTreeNode = this.Ancestors().OfType<AssemblyListTreeNode>().FirstOrDefault();
     Debug.Assert(asmListTreeNode != null);
     if (moduleDefinition is ModuleDefMD)
         this.Children.Add(new ReferenceFolderTreeNode((ModuleDefMD)moduleDefinition, this, asmListTreeNode));
     this.Children.Add(new ResourceListTreeNode(moduleDefinition));
     foreach (NamespaceTreeNode ns in namespaces.Values) {
         ns.Children.Clear();
     }
     foreach (TypeDef type in moduleDefinition.Types.OrderBy(t => t.FullName, TypeStringComparer)) {
         NamespaceTreeNode ns;
         if (!namespaces.TryGetValue(type.Namespace, out ns)) {
             ns = new NamespaceTreeNode(type.Namespace);
             namespaces[type.Namespace] = ns;
         }
         TypeTreeNode node = new TypeTreeNode(type, this);
         typeDict[type] = node;
         ns.Children.Add(node);
     }
     foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name)) {
         if (ns.Children.Count > 0)
             this.Children.Add(ns);
     }
 }
コード例 #26
0
ファイル: AssemblyTreeNode.cs プロジェクト: gsong2014/dnSpy
 internal void OnRemoved(TypeTreeNode typeNode)
 {
     bool b = typeDict.Remove(typeNode.TypeDefinition);
     Debug.Assert(b);
     if (!b)
         throw new InvalidOperationException();
 }
コード例 #27
0
ファイル: AssemblyTreeNode.cs プロジェクト: gsong2014/dnSpy
 internal void OnReadded(TypeTreeNode typeNode)
 {
     Debug.Assert(!typeDict.ContainsKey(typeNode.TypeDefinition));
     typeDict.Add(typeNode.TypeDefinition, typeNode);
 }
コード例 #28
0
 internal void OnReadded(TypeTreeNode typeNode)
 {
     Debug.Assert(!typeDict.ContainsKey(typeNode.TypeDefinition));
     typeDict.Add(typeNode.TypeDefinition, typeNode);
 }
コード例 #29
0
ファイル: TypeDefCommands.cs プロジェクト: nakijun/dnSpy
			public void Delete(TypeTreeNode[] nodes) {
				Debug.Assert(infos == null);
				if (infos != null)
					throw new InvalidOperationException();

				infos = new ModelInfo[nodes.Length];

				for (int i = 0; i < infos.Length; i++) {
					var node = nodes[i];

					var info = new ModelInfo(node.TypeDefinition);
					infos[i] = info;
					info.OwnerList.RemoveAt(info.Index);
				}
			}
コード例 #30
0
ファイル: MethodDefCommands.cs プロジェクト: arkanoid1/dnSpy
		CreateMethodDefCommand(TypeTreeNode ownerNode, MethodDefOptions options) {
			this.ownerNode = ownerNode;
			this.methodNode = new MethodTreeNode(options.CreateMethodDef(ownerNode.TypeDef.Module));
		}
コード例 #31
0
ファイル: FieldDefCommands.cs プロジェクト: damnya/dnSpy
 CreateFieldDefCommand(TypeTreeNode ownerNode, FieldDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.fieldNode = new FieldTreeNode(options.CreateFieldDef(ownerNode.TypeDefinition.Module));
 }
コード例 #32
0
ファイル: FieldDefCommands.cs プロジェクト: damnya/dnSpy
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var ownerNode = nodes[0];
            if (!(ownerNode is TypeTreeNode))
                ownerNode = (ILSpyTreeNode)ownerNode.Parent;
            var typeNode = ownerNode as TypeTreeNode;
            Debug.Assert(typeNode != null);
            if (typeNode == null)
                throw new InvalidOperationException();

            var module = ILSpyTreeNode.GetModule(typeNode);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            FieldDefOptions options;
            var type = typeNode.TypeDefinition;
            if (type.IsEnum) {
                var ts = type.GetEnumUnderlyingType();
                if (ts != null) {
                    options = FieldDefOptions.Create("MyField", new FieldSig(new ValueTypeSig(typeNode.TypeDefinition)));
                    options.Constant = module.UpdateRowId(new ConstantUser(ModelUtils.GetDefaultValue(ts), ts.RemovePinnedAndModifiers().GetElementType()));
                    options.Attributes |= FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.HasDefault;
                }
                else {
                    options = FieldDefOptions.Create("value__", new FieldSig(module.CorLibTypes.Int32));
                    options.Attributes |= FieldAttributes.SpecialName | FieldAttributes.RTSpecialName;
                }
            }
            else if (type.IsAbstract && type.IsSealed) {
                options = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));
                options.Attributes |= FieldAttributes.Static;
            }
            else
                options = FieldDefOptions.Create("MyField", new FieldSig(module.CorLibTypes.Int32));

            var data = new FieldOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, type);
            var win = new FieldOptionsDlg();
            win.Title = "Create Field";
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            UndoCommandManager.Instance.Add(new CreateFieldDefCommand(typeNode, data.CreateFieldDefOptions()));
        }
コード例 #33
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var ownerNode = nodes[0];
            if (!(ownerNode is TypeTreeNode))
                ownerNode = (ILSpyTreeNode)ownerNode.Parent;
            var typeNode = ownerNode as TypeTreeNode;
            Debug.Assert(typeNode != null);
            if (typeNode == null)
                throw new InvalidOperationException();

            var module = ILSpyTreeNode.GetModule(typeNode);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            bool isInstance = !(typeNode.TypeDefinition.IsAbstract && typeNode.TypeDefinition.IsSealed);
            var options = PropertyDefOptions.Create(module, "MyProperty", isInstance);

            var data = new PropertyOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, typeNode.TypeDefinition);
            var win = new PropertyOptionsDlg();
            win.Title = "Create Property";
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            UndoCommandManager.Instance.Add(new CreatePropertyDefCommand(typeNode, data.CreatePropertyDefOptions()));
        }
コード例 #34
0
ファイル: AssemblyTreeNode.cs プロジェクト: arkanoid1/dnSpy
		void LoadModuleChildren(IPEImage peImage, ModuleDef module) {
			var asmListTreeNode = this.Ancestors().OfType<DnSpyFileListTreeNode>().FirstOrDefault();
			Debug.Assert(asmListTreeNode != null);
			// Only show the PE node if it was loaded from a file. The hex document is always loaded
			// from a file, so if the PEImage wasn't loaded from the same file, conversion to/from
			// RVA/FileOffset won't work and the wrong data will be displayed, eg. in the .NET
			// storage stream nodes.
			if (DnSpyFile.LoadedFromFile && peImage != null)
				this.Children.Add(new PETreeNode(peImage, module as ModuleDefMD));
			if (module != null) {
				this.Children.Add(new ReferenceFolderTreeNode(module, this, asmListTreeNode));
				this.Children.Add(new ResourceListTreeNode(module));
				foreach (NamespaceTreeNode ns in namespaces.Values) {
					ns.Children.Clear();
				}
				foreach (TypeDef type in module.Types.OrderBy(t => t.FullName, TypeStringComparer)) {
					NamespaceTreeNode ns;
					if (!namespaces.TryGetValue(type.Namespace, out ns)) {
						ns = new NamespaceTreeNode(type.Namespace);
						namespaces[type.Namespace] = ns;
					}
					TypeTreeNode node = new TypeTreeNode(type, this);
					typeDict[type] = node;
					ns.Children.Add(node);
				}
				foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name)) {
					if (ns.Children.Count > 0)
						this.Children.Add(ns);
				}
			}
		}
コード例 #35
0
ファイル: MethodDefCommands.cs プロジェクト: gsong2014/dnSpy
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var ownerNode = nodes[0];
            if (!(ownerNode is TypeTreeNode))
                ownerNode = (ILSpyTreeNode)ownerNode.Parent;
            var typeNode = ownerNode as TypeTreeNode;
            Debug.Assert(typeNode != null);
            if (typeNode == null)
                throw new InvalidOperationException();

            var module = ILSpyTreeNode.GetModule(typeNode);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            bool isInstance = !(typeNode.TypeDefinition.IsAbstract && typeNode.TypeDefinition.IsSealed);
            var sig = isInstance ? MethodSig.CreateInstance(module.CorLibTypes.Void) : MethodSig.CreateStatic(module.CorLibTypes.Void);
            var options = MethodDefOptions.Create("MyMethod", sig);
            if (typeNode.TypeDefinition.IsInterface)
                options.Attributes |= MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.NewSlot;

            var data = new MethodOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, typeNode.TypeDefinition, null);
            var win = new MethodOptionsDlg();
            win.Title = "Create Method";
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            UndoCommandManager.Instance.Add(new CreateMethodDefCommand(typeNode, data.CreateMethodDefOptions()));
        }
コード例 #36
0
ファイル: AssemblyTreeNode.cs プロジェクト: arkanoid1/dnSpy
		internal TypeTreeNode GetOrCreateNonNestedTypeTreeNode(TypeDef td) {
			Debug.Assert(td != null && td.DeclaringType == null);
			Debug.Assert(!LazyLoading);
			TypeTreeNode typeNode;
			if (typeDict.TryGetValue(td, out typeNode))
				return typeNode;
			var nsNode = GetOrCreateNamespaceNode(td.Namespace);
			typeNode = new TypeTreeNode(td, this);
			typeDict.Add(td, typeNode);
			nsNode.AddToChildren(typeNode);
			return typeNode;
		}
コード例 #37
0
		protected override void LoadChildren()
		{
			AssemblyDefinition assemblyDefinition = assembly.AssemblyDefinition;
			if (assemblyDefinition == null) {
				// if we crashed on loading, then we don't have any children
				return;
			}
			ModuleDefinition mainModule = assemblyDefinition.MainModule;

			this.Children.Add(new ReferenceFolderTreeNode(mainModule, this));
			if (mainModule.HasResources)
				this.Children.Add(new ResourceListTreeNode(mainModule));
			foreach (NamespaceTreeNode ns in namespaces.Values) {
				ns.Children.Clear();
			}
			foreach (TypeDefinition type in mainModule.Types.OrderBy(t => t.FullName)) {
				NamespaceTreeNode ns;
				if (!namespaces.TryGetValue(type.Namespace, out ns)) {
					ns = new NamespaceTreeNode(type.Namespace);
					namespaces[type.Namespace] = ns;
				}
				TypeTreeNode node = new TypeTreeNode(type, this);
				typeDict[type] = node;
				ns.Children.Add(node);
			}
			foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name)) {
				if (ns.Children.Count > 0)
					this.Children.Add(ns);
			}
		}
コード例 #38
0
ファイル: TreeViewUpdater.cs プロジェクト: arkanoid1/dnSpy
		void UpdateMemberNodes(TypeTreeNode typeNode) {
			// If it's not been loaded, we've got nothing to do
			if (typeNode.LazyLoading)
				return;

			var existing = new HashSet<object>();
			foreach (var child in typeNode.Children) {
				var memberNode = child as IMemberTreeNode;
				if (memberNode != null)
					existing.Add(memberNode.Member);
			}

			foreach (var fd in typeNode.TypeDef.Fields) {
				if (existing.Contains(fd))
					continue;
				typeNode.AddToChildren(new FieldTreeNode(fd));
			}

			foreach (var pd in typeNode.TypeDef.Properties) {
				if (existing.Contains(pd))
					continue;
				typeNode.AddToChildren(new PropertyTreeNode(pd, typeNode));
			}

			foreach (var ed in typeNode.TypeDef.Events) {
				if (existing.Contains(ed))
					continue;
				typeNode.AddToChildren(new EventTreeNode(ed));
			}

			var accessorMethods = typeNode.TypeDef.GetAccessorMethods();
			foreach (var md in typeNode.TypeDef.Methods) {
				if (existing.Contains(md))
					continue;
				if (!accessorMethods.Contains(md))
					typeNode.AddToChildren(new MethodTreeNode(md));
			}
		}
コード例 #39
0
ファイル: TypeDefCommands.cs プロジェクト: nakijun/dnSpy
		CreateTypeDefCommand(IList<TypeDef> ownerList, ILSpyTreeNode ownerNode, TypeDefOptions options) {
			this.ownerList = ownerList;
			var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerNode);
			Debug.Assert(modNode != null);
			if (modNode == null)
				throw new InvalidOperationException();
			this.nsNodeCreator = new NamespaceTreeNodeCreator(options.Namespace, modNode);
			this.typeNode = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode);
		}
コード例 #40
0
ファイル: TypeTreeNode.cs プロジェクト: arkanoid1/dnSpy
		internal TypeTreeNode GetOrCreateNestedTypeTreeNode(TypeDef nestedType) {
			Debug.Assert(nestedType != null && nestedType.DeclaringType == type);
			EnsureChildrenFiltered();
			var typeNode = Children.OfType<TypeTreeNode>().FirstOrDefault(n => n.type == nestedType);
			if (typeNode != null)
				return typeNode;
			typeNode = new TypeTreeNode(nestedType, parentAssemblyNode);
			AddToChildren(typeNode);
			return typeNode;
		}
コード例 #41
0
 CreatePropertyDefCommand(TypeTreeNode ownerNode, PropertyDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.propNode = new PropertyTreeNode(options.CreatePropertyDef(ownerNode.TypeDefinition.Module));
 }
コード例 #42
0
ファイル: TypeDefCommands.cs プロジェクト: nakijun/dnSpy
		TypeDefSettingsCommand(ModuleDef module, TypeTreeNode typeNode, TypeDefOptions options) {
			this.module = module;
			this.typeNode = typeNode;
			this.newOptions = options;
			this.origOptions = new TypeDefOptions(typeNode.TypeDefinition);

			this.origParentNode = (ILSpyTreeNode)typeNode.Parent;
			this.origParentChildIndex = this.origParentNode.Children.IndexOf(typeNode);
			Debug.Assert(this.origParentChildIndex >= 0);
			if (this.origParentChildIndex < 0)
				throw new InvalidOperationException();

			this.nameChanged = origOptions.Name != newOptions.Name;
			if (this.origParentNode is NamespaceTreeNode) {
				var asmNode = (AssemblyTreeNode)this.origParentNode.Parent;
				if (!AssemblyTreeNode.NamespaceStringEqualsComparer.Equals(newOptions.Namespace, origOptions.Namespace))
					this.nsNodeCreator = new NamespaceTreeNodeCreator(newOptions.Namespace, asmNode);
			}

			if (this.nameChanged || origOptions.Namespace != newOptions.Namespace)
				this.typeRefInfos = RefFinder.FindTypeRefsToThisModule(module).Where(a => RefFinder.TypeEqualityComparerInstance.Equals(a, typeNode.TypeDefinition)).Select(a => new TypeRefInfo(a)).ToArray();
		}
コード例 #43
0
ファイル: TypeDefCommands.cs プロジェクト: nakijun/dnSpy
			public void Restore(TypeTreeNode[] nodes) {
				Debug.Assert(infos != null);
				if (infos == null)
					throw new InvalidOperationException();
				Debug.Assert(infos.Length == nodes.Length);
				if (infos.Length != nodes.Length)
					throw new InvalidOperationException();

				for (int i = infos.Length - 1; i >= 0; i--) {
					var node = nodes[i];
					var info = infos[i];
					info.OwnerList.Insert(info.Index, node.TypeDefinition);
				}

				infos = null;
			}
コード例 #44
0
ファイル: TypeDefCommands.cs プロジェクト: BahNahNah/dnSpy
        TypeDefSettingsCommand(ModuleDef module, TypeTreeNode typeNode, TypeDefOptions options)
        {
            this.module = module;
            this.typeNode = typeNode;
            this.newOptions = options;
            this.origOptions = new TypeDefOptions(typeNode.TypeDefinition);

            this.origParentNode = (ILSpyTreeNode)typeNode.Parent;
            this.origParentChildIndex = this.origParentNode.Children.IndexOf(typeNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
                throw new InvalidOperationException();

            this.nameChanged = origOptions.Name != newOptions.Name;
            if (this.origParentNode is NamespaceTreeNode) {
                var asmNode = (AssemblyTreeNode)this.origParentNode.Parent;
                if (AssemblyTreeNode.NamespaceStringComparer.Compare(newOptions.Namespace, origOptions.Namespace) != 0)
                    this.nsNodeCreator = new NamespaceTreeNodeCreator(newOptions.Namespace, asmNode);
            }
        }
コード例 #45
0
ファイル: TypeDefCommands.cs プロジェクト: nakijun/dnSpy
		DeleteTypeDefCommand(TypeTreeNode[] asmNodes) {
			nodes = new DeletableNodes<TypeTreeNode>(asmNodes);
		}
コード例 #46
0
ファイル: AssemblyList.cs プロジェクト: almazik/ILSpy
 /// <summary>
 /// Registers a type node in the dictionary for quick type lookup.
 /// </summary>
 /// <remarks>This method is called by the assembly loading code (on a background thread)</remarks>
 public void RegisterTypeNode(TypeTreeNode node)
 {
     // called on background loading thread, so we need to use a ConcurrentDictionary
     typeDict[node.TypeDefinition] = node;
 }