/// <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 { AssemblyTreeNode asm = FindAssemblyNode(def.Module.Assembly); if (asm != null) { return(asm.FindTypeNode(def)); } } return(null); }
/// <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); }
/// <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)); }