Exemple #1
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);
        }
Exemple #2
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));
        }
Exemple #3
0
        protected override void LoadChildren()
        {
            ModuleDefinition moduleDefinition = assembly.GetModuleDefinitionOrNull();

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

            this.Children.Add(new ReferenceFolderTreeNode(moduleDefinition, this));
            if (moduleDefinition.HasResources)
            {
                this.Children.Add(new ResourceListTreeNode(moduleDefinition));
            }
            foreach (NamespaceTreeNode ns in namespaces.Values)
            {
                ns.Children.Clear();
            }
            foreach (TypeDefinition type in moduleDefinition.Types.OrderBy(t => t.FullName, NaturalStringComparer.Instance))
            {
                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, NaturalStringComparer.Instance))
            {
                if (ns.Children.Count > 0)
                {
                    this.Children.Add(ns);
                }
            }
        }