本文整理汇总了C#中IContent.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# IContent.Descendants方法的具体用法?C# IContent.Descendants怎么用?C# IContent.Descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContent
的用法示例。
在下文中一共展示了IContent.Descendants方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Export
/// <summary>
/// Exports an <see cref="IContent"/> item to xml as an <see cref="XElement"/>
/// </summary>
/// <param name="content">Content to export</param>
/// <param name="deep">Optional parameter indicating whether to include descendents</param>
/// <returns><see cref="XElement"/> containing the xml representation of the Content object</returns>
internal XElement Export(IContent content, bool deep = false)
{
//nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias);
var nodeName = UmbracoSettings.UseLegacyXmlSchema ? "node" : content.ContentType.Alias.ToSafeAliasWithForcingCheck();
var xml = Export(content, nodeName);
xml.Add(new XAttribute("nodeType", content.ContentType.Id));
xml.Add(new XAttribute("creatorName", content.GetCreatorProfile().Name));
xml.Add(new XAttribute("writerName", content.GetWriterProfile().Name));
xml.Add(new XAttribute("writerID", content.WriterId));
xml.Add(new XAttribute("template", content.Template == null ? "0" : content.Template.Id.ToString(CultureInfo.InvariantCulture)));
xml.Add(new XAttribute("nodeTypeAlias", content.ContentType.Alias));
if (deep)
{
var descendants = content.Descendants().ToArray();
var currentChildren = descendants.Where(x => x.ParentId == content.Id);
AddChildXml(descendants, currentChildren, xml);
}
return xml;
}
示例2: GetUrlsForNode
/// <summary>
/// We want to get the domains associated with the content node. This includes getting the allowed domains on the node as well as
/// searching up the tree to get the parents nodes since they are inherited.
/// </summary>
/// <param name="content"></param>
/// <param name="includeChildren"></param>
/// <returns></returns>
public List<string> GetUrlsForNode(IContent content, bool includeDescendants = false)
{
List<string> urls = new List<string>();
urls.Add(UmbracoContext.Current.RoutingContext.UrlProvider.GetUrl(content.Id, true));
urls.AddRange(UmbracoContext.Current.RoutingContext.UrlProvider.GetOtherUrls(content.Id));
if(includeDescendants)
{
foreach(IContent desc in content.Descendants())
{
urls.Add(UmbracoContext.Current.RoutingContext.UrlProvider.GetUrl(desc.Id, true));
urls.AddRange(UmbracoContext.Current.RoutingContext.UrlProvider.GetOtherUrls(desc.Id));
}
}
return urls;
}