public static bool HasParentsOfType(this DynamicNode node, string documentType, out DynamicNodeList parents) { var nodes = node.Ancestors(documentType); parents = new DynamicNodeList(); if (nodes == null) { return(false); } else if (nodes.Count() == 0) { return(false); } else { parents = nodes; return(true); } }