/// <summary>
 /// Looks up the type node corresponding to the type definition.
 /// Returns null if no matching node is found.
 /// </summary>
 public TypeTreeNode FindTypeNode(TypeDef 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
     {
         AssemblyTreeNode asm = FindAssemblyNode(def.Module.Assembly);
         if (asm != null)
         {
             return(asm.FindTypeNode(def));
         }
     }
     return(null);
 }
Пример #2
0
        /// <summary>
        /// Looks up the type node corresponding to the type definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public TypeTreeNode FindTypeNode(ITypeDefinition def)
        {
            if (def == null)
            {
                return(null);
            }
            var declaringType = def.DeclaringTypeDefinition;

            if (declaringType != null)
            {
                TypeTreeNode decl = FindTypeNode(declaringType);
                if (decl != null)
                {
                    decl.EnsureLazyChildren();
                    return(decl.Children.OfType <TypeTreeNode>().FirstOrDefault(t => t.TypeDefinition.MetadataToken == def.MetadataToken && !t.IsHidden));
                }
            }
            else
            {
                AssemblyTreeNode asm = FindAssemblyNode(def.ParentModule);
                if (asm != null)
                {
                    return(asm.FindTypeNode(def));
                }
            }
            return(null);
        }
Пример #3
0
        /// <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));
        }
Пример #4
0
        /// <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
        /// <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);
        }
Пример #6
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));
        }
        /// <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));
        }
 /// <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);
 }
Пример #9
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);
        }