From 49d5791825bfb4293e9daafdb378cc463e49aa5f Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 28 Oct 2013 12:35:50 +1100 Subject: [PATCH] Adds DescendantsOrSelf extensions on ienumerable to published content extensions --- src/Umbraco.Web/PublishedContentExtensions.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 8de72a48bb..b4d07b8baa 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -1065,6 +1065,35 @@ namespace Umbraco.Web #region Axes: descendants, descendants-or-self + /// + /// Returns all DescendantsOrSelf of all content referenced + /// + /// + /// + /// + /// + /// This can be useful in order to return all nodes in an entire site by a type when combined with TypedContentAtRoot + /// + public static IEnumerable DescendantsOrSelf(this IEnumerable parentNodes, string docTypeAlias) + { + return parentNodes.SelectMany(x => x.DescendantsOrSelf(docTypeAlias)); + } + + /// + /// Returns all DescendantsOrSelf of all content referenced + /// + /// + /// + /// + /// This can be useful in order to return all nodes in an entire site by a type when combined with TypedContentAtRoot + /// + public static IEnumerable DescendantsOrSelf(this IEnumerable parentNodes) + where T : class, IPublishedContent + { + return parentNodes.SelectMany(x => x.DescendantsOrSelf()); + } + + // as per XPath 1.0 specs §2.2, // - the descendant axis contains the descendants of the context node; a descendant is a child or a child of a child and so on; thus // the descendant axis never contains attribute or namespace nodes.