Namespace node. The loading of the type nodes is handled by the parent AssemblyTreeNode.
Наследование: ILSpyTreeNode
Пример #1
0
 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
 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);
         }
     }
 }
Пример #3
0
        internal void OnReadded(NamespaceTreeNode nsNode)
        {
            Debug.Assert(!namespaces.ContainsKey(nsNode.Name));
            namespaces.Add(nsNode.Name, nsNode);

            foreach (TypeTreeNode typeNode in nsNode.Children)
            {
                OnReadded(typeNode);
            }
        }
Пример #4
0
		public NamespaceTreeNodeCreator(string ns, AssemblyTreeNode asmNode) {
			Debug.Assert(asmNode.IsModule);
			if (!asmNode.IsModule)
				throw new InvalidOperationException();

			this.asmNode = asmNode;
			this.nsNode = asmNode.FindNamespaceNode(ns);
			if (this.nsNode == null) {
				this.nsNode = new NamespaceTreeNode(ns);
				this.nsNodeCreated = true;
			}
		}
Пример #5
0
        NamespaceTreeNode GetOrCreateNamespaceNode(string ns)
        {
            EnsureChildrenFiltered();
            NamespaceTreeNode nsNode;

            if (namespaces.TryGetValue(ns, out nsNode))
            {
                return(nsNode);
            }
            nsNode = new NamespaceTreeNode(ns);
            namespaces.Add(nsNode.Name, nsNode);
            AddToChildren(nsNode);
            return(nsNode);
        }
Пример #6
0
        internal void OnRemoved(NamespaceTreeNode nsNode)
        {
            bool b = namespaces.Remove(nsNode.Name);

            Debug.Assert(b);
            if (!b)
            {
                throw new InvalidOperationException();
            }

            foreach (TypeTreeNode typeNode in nsNode.Children)
            {
                OnRemoved(typeNode);
            }
        }
Пример #7
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);
                }
            }
        }
Пример #8
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);
                }
            }
        }
Пример #9
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);
                    }
                }
            }
        }
Пример #10
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);
                }
            }
        }
Пример #11
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);
                    }
                }
            }
        }
Пример #12
0
			public void Restore(NamespaceTreeNode[] nodes, ILSpyTreeNode[] parents) {
				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 info = infos[i];

					for (int j = info.Types.Length - 1; j >= 0; j--)
						info.Module.Types.Insert(info.Indexes[j], info.Types[j]);
				}

				infos = null;
			}
Пример #13
0
 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);
     }
 }
Пример #14
0
        internal void OnRemoved(NamespaceTreeNode nsNode)
        {
            bool b = namespaces.Remove(nsNode.Name);
            Debug.Assert(b);
            if (!b)
                throw new InvalidOperationException();

            foreach (TypeTreeNode typeNode in nsNode.Children)
                OnRemoved(typeNode);
        }
Пример #15
0
        internal void OnReadded(NamespaceTreeNode nsNode)
        {
            Debug.Assert(!namespaces.ContainsKey(nsNode.Name));
            namespaces.Add(nsNode.Name, nsNode);

            foreach (TypeTreeNode typeNode in nsNode.Children)
                OnReadded(typeNode);
        }
Пример #16
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);
				}
			}
		}
Пример #17
0
		NamespaceTreeNode GetOrCreateNamespaceNode(string ns) {
			EnsureChildrenFiltered();
			NamespaceTreeNode nsNode;
			if (namespaces.TryGetValue(ns, out nsNode))
				return nsNode;
			nsNode = new NamespaceTreeNode(ns);
			namespaces.Add(nsNode.Name, nsNode);
			AddToChildren(nsNode);
			return nsNode;
		}
Пример #18
0
		RenameNamespaceCommand(string newName, NamespaceTreeNode nsNode) {
			this.newName = newName;
			this.origName = nsNode.Name;
			this.nsNode = nsNode;
			this.existingNsNode = (NamespaceTreeNode)nsNode.Parent.Children.FirstOrDefault(a => a is NamespaceTreeNode && AssemblyTreeNode.NamespaceStringEqualsComparer.Equals(newName, ((NamespaceTreeNode)a).Name));

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

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

			// Make sure the exact same namespace names are restored if we undo. The names are UTF8
			// strings, but not necessarily canonicalized if it's an obfuscated assembly.
			nsNode.EnsureChildrenFiltered();
			this.origChildren = nsNode.Children.Cast<TypeTreeNode>().ToArray();
			this.typeNamespaces = new UTF8String[nsNode.Children.Count];
			for (int i = 0; i < this.typeNamespaces.Length; i++)
				this.typeNamespaces[i] = origChildren[i].TypeDefinition.Namespace;

			this.typeRefInfos = GetTypeRefInfos(module, new[] { nsNode });
		}
Пример #19
0
			public void Delete(NamespaceTreeNode[] nodes, ILSpyTreeNode[] parents) {
				Debug.Assert(parents != null && nodes.Length == parents.Length);
				Debug.Assert(infos == null);
				if (infos != null)
					throw new InvalidOperationException();

				infos = new ModuleInfo[nodes.Length];

				for (int i = 0; i < infos.Length; i++) {
					var node = nodes[i];
					var module = ILSpyTreeNode.GetModule(parents[i]);
					Debug.Assert(module != null);
					if (module == null)
						throw new InvalidOperationException();

					var info = new ModuleInfo(module, node.Children.Count);
					infos[i] = info;

					for (int j = 0; j < node.Children.Count; j++) {
						var typeNode = (TypeTreeNode)node.Children[j];
						int index = module.Types.IndexOf(typeNode.TypeDefinition);
						Debug.Assert(index >= 0);
						if (index < 0)
							throw new InvalidOperationException();
						module.Types.RemoveAt(index);
						info.Types[j] = typeNode.TypeDefinition;
						info.Indexes[j] = index;
					}
				}
			}
Пример #20
0
		DeleteNamespaceCommand(NamespaceTreeNode[] nodes) {
			this.parents = nodes.Select(a => (ILSpyTreeNode)a.Parent).ToArray();
			this.nodes = new DeletableNodes<NamespaceTreeNode>(nodes);
			this.modelNodes = new DeleteModelNodes();
		}
Пример #21
0
        /// <summary>
        /// Fills the given node with the nodes necessary for the preview of the importing. This action requires a call to Scan()
        /// </summary>
        /// <param name="root"></param>
        public void BuildPreviewNodes(SharpTreeNode root)
        {
            //Checks that the root node isn't null
            if (root == null)
                throw new ArgumentNullException("root");

            //Checks if Scan() has already been called
            if (!Scanned)
                throw new InvalidOperationException("Cannot build preview nodes before a call to Scan()");

            //Gets the members needed by the import list and by this instance
            var members = GetMembersForPreview().ToArray();

            //Checks that there's at least one element
            if (members.Length == 0)
                return;

            //Builds up to the type nodes
            var typeNodes = BuildTypeNodes(members);

            //Lists of the assembly and module nodes (needed for preview of assembly references)
            var asmNodes = new List<ILEditTreeNode>();
            var moduleNodes = new List<ILEditTreeNode>();

            //Groups by assembly, module and then namespace
            var grouped =
                typeNodes.GroupBy(x => x.Member.Module)
                .OrderBy(x => x.Key.Name)
                .Select(x => x.OrderBy(y => y.Text.ToString()).GroupBy(y => ((TypeDefinition)y.Member).Namespace).OrderBy(y => y.Key).GroupBy(y => x.Key).ElementAt(0))
                .GroupBy(x => x.Key.Assembly)
                .OrderBy(x => x.Key.Name.Name)
                .Select(x =>
                {
                    //Assembly node
                    var asmNode = new ILEditTreeNode(x.Key, true) { IsExpanded = true, Foreground = GlobalContainer.NormalNodesBrush };
                    foreach (var m in x)
                    {
                        //Module node
                        var moduleNode = new ILEditTreeNode(m.Key, true) { IsExpanded = true, Foreground = GlobalContainer.NormalNodesBrush };
                        foreach (var n in m)
                        {
                            //Namespace node
                            var namespaceNode = new NamespaceTreeNode(n.Key) { IsExpanded = true, Foreground = GlobalContainer.NormalNodesBrush };
                            foreach (var t in n)
                                namespaceNode.Children.Add(t);
                            moduleNode.Children.Add(namespaceNode);
                        }
                        moduleNodes.Add(moduleNode);
                        asmNode.Children.Add(moduleNode);
                    }
                    asmNodes.Add(asmNode);
                    return asmNode;
                });

            //Clears the root
            root.Children.Clear();

            //Adds the nodes to the root
            foreach (var x in grouped)
                root.Children.Add(x);

            //Groups the references by module
            var references =
                members.OfType<Importers.AssemblyReferenceImporter>()
                .GroupBy(
                    x => (ModuleDefinition)x.Destination,
                    x => (AssemblyNameReference)x.Member
                );

            //Creates the references nodes
            foreach(var refs in references)
            {
                //Creates and populates the references node
                var refFolder = new ILEditTreeNode.ReferenceFolderNode();
                foreach (var r in refs)
                    refFolder.Children.Add(new ILEditTreeNode(r, true) { 
                        IsExpanded = true, 
                        Foreground = GlobalContainer.ModifiedNodesBrush 
                    });
                
                //Finds the module node to add to
                var moduleNode = moduleNodes.FirstOrDefault(x => (ModuleDefinition)x.TokenProvider == refs.Key);
                if (moduleNode != null)
                {
                    //Adds the references to the module node
                    moduleNode.Children.Insert(0, refFolder);
                }
                else
                {
                    //Finds or creates the assembly node
                    var asmNode = asmNodes.FirstOrDefault(x => (AssemblyDefinition)x.TokenProvider == refs.Key.Assembly);
                    if (asmNode != null)
                    {
                        //Adds a module node to the assembly
                        asmNode.Children.Add(new ILEditTreeNode(refs.Key, true) { 
                            IsExpanded = true, 
                            Foreground = GlobalContainer.NormalNodesBrush, 
                            Children = { refFolder } 
                        });
                    }
                    else
                    {
                        //Creates the nodes and adds it to the root
                        root.Children.Add(new ILEditTreeNode(refs.Key.Assembly, true) {
                            IsExpanded = true,
                            Foreground = GlobalContainer.NormalNodesBrush,
                            Children = {
                                new ILEditTreeNode(refs.Key, true) {
                                IsExpanded = true,
                                Foreground = GlobalContainer.NormalNodesBrush,
                                    Children = { refFolder }
                                }
                            }
                        });
                    }
                }
            }
        }
Пример #22
0
        /// <summary>
        /// Loads the children
        /// </summary>
        protected override void LoadChildren()
        {
            //Checks if the children must be filled manually
            if (ManuallyFilledChildren)
                return;

            //IEnumerable containing the childrenot the node
            IEnumerable<IMetadataTokenProvider> children = null;

            //Assembly
            if (_tokenProvider is AssemblyDefinition)
                children = ((AssemblyDefinition)_tokenProvider).Modules;
            //Module
            else if (_tokenProvider is ModuleDefinition)
            {
                //Types
                IEnumerable<TypeDefinition> types = ((ModuleDefinition)_tokenProvider).Types;
                if (this.ChildrenFilter != null)
                    types = types.Where(x => this.ChildrenFilter(x));

                //Groups the types by namespace and adds
                foreach (var node in types.GroupBy(x => x.Namespace)
                                     .OrderBy(x => x.Key)
                                     .Select(x =>
                                     {
                                         var n = new NamespaceTreeNode(x.Key);
                                         foreach (var t in x.OrderBy(y => y.Name))
                                             n.Children.Add(new ILEditTreeNode(t, false) { ChildrenFilter = this.ChildrenFilter, Foreground = this.Foreground });
                                         return n;
                                     })) 
                {
                    this.Children.Add(node);
                }

                //Returns
                return;
            }
            //Type
            else if (_tokenProvider is TypeDefinition)
            {
                var type = (TypeDefinition)_tokenProvider;
                children =
                    type.NestedTypes.Cast<IMetadataTokenProvider>()
                    .Concat(type.Fields)
                    .Concat(type.Methods.Where(x => !(x.IsGetter || x.IsSetter || x.IsAddOn || x.IsRemoveOn || x.IsFire)))
                    .Concat(type.Properties)
                    .Concat(type.Events);
            }
            //Property
            else if (_tokenProvider is PropertyDefinition)
            {
                var prop = (PropertyDefinition)_tokenProvider;
                children =
                    new IMetadataTokenProvider[] { prop.GetMethod, prop.SetMethod }
                    .Where(x => x != null)
                    .Concat(prop.HasOtherMethods ? prop.OtherMethods.Cast<IMetadataTokenProvider>() : new IMetadataTokenProvider[] { });
            }
            //Event
            else if (_tokenProvider is EventDefinition)
            {
                var evt = (EventDefinition)_tokenProvider;
                children =
                    new IMetadataTokenProvider[] { evt.AddMethod, evt.RemoveMethod, evt.InvokeMethod }
                    .Where(x => x != null)
                    .Concat(evt.HasOtherMethods ? evt.OtherMethods.Cast<IMetadataTokenProvider>() : new IMetadataTokenProvider[] { });
            }

            //If there are no children returns
            if (children == null)
                return;

            //Applies the filtering
            if (ChildrenFilter != null)
                children = children.Where(x => ChildrenFilter(x));

            //Adds the children
            foreach (var x in children)
                this.Children.Add(new ILEditTreeNode(x, false) { ChildrenFilter = this.ChildrenFilter, Foreground = this.Foreground });
        }
Пример #23
0
        protected override IMetadataTokenProvider ImportCore(MemberImportingOptions options, SharpTreeNode node)
        {
            //Checks that the task hasn't been canceled
            options.CancellationToken.ThrowIfCancellationRequested();

            //Checks if the destination is a module or a type
            if (Destination is ModuleDefinition)
            {
                //Destination
                var dest = (ModuleDefinition)Destination;
                dest.Types.Add(typeClone);

                //Finds the correct namespace
                var ns = typeClone.Namespace;
                var moduleNode = Helpers.Tree.GetModuleNode((ModuleDefinition)Destination);
                var nsNode = moduleNode.Children.EnsureLazyChildren().OfType<NamespaceTreeNode>().FirstOrDefault(x => x.Name == ns);
                if (nsNode != null)
                    nsNode.AddChildAndColorAncestors(new ILEditTreeNode(typeClone, false));
                else
                {
                    nsNode = new NamespaceTreeNode(typeClone.Namespace) { Foreground = GlobalContainer.ModifiedNodesBrush };
                    nsNode.Children.Add(new ILEditTreeNode(typeClone, false));
                    moduleNode.AddChildAndColorAncestors(nsNode);
                }
            }
            else
            {
                //Destination
                var dest = (TypeDefinition)Destination;
                dest.NestedTypes.Add(typeClone);
                node.AddChildAndColorAncestors(new ILEditTreeNode(typeClone, false));
            }

            //Return
            return typeClone;
        }
Пример #24
0
 MoveNamespaceTypesToEmptypNamespaceCommand(ILSpyTreeNode[] nodes)
 {
     var nsNodes = nodes.Where(a => ((NamespaceTreeNode)a).Name != string.Empty).Select(a => (NamespaceTreeNode)a).ToArray();
     Debug.Assert(nsNodes.Length > 0);
     this.nodes = new DeletableNodes<NamespaceTreeNode>(nsNodes);
     this.nsTarget = GetTarget();
     this.typeRefInfos = RenameNamespaceCommand.GetTypeRefInfos(ILSpyTreeNode.GetModule(nodes[0]), nsNodes);
 }
Пример #25
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);
			}
		}
        string GetLinqPadClassName(NamespaceTreeNode namespaceTreeNode)
        {
            string linqpadGeneratedClassName = "UserQuery";

            var classNode =
                namespaceTreeNode.Children.FirstOrDefault(c => Equals(c.Text, linqpadGeneratedClassName));

            if (classNode == null)
            {
                string queryClassId = LinqPadUtil.GetQueryIdentifier(this.assemblyPath);

                var linqPadClass =
                    namespaceTreeNode.Children.FirstOrDefault(c => c.Text.ToString().Contains(queryClassId));

                if (linqPadClass != null)
                {
                    return linqPadClass.Text.ToString();
                }
            }
            else
            {
                return classNode.Text.ToString();
            }

            // If the LINQPad query class cannot be found, select something so it loads.
            return namespaceTreeNode.Children.First().Text.ToString();
        }