本文整理汇总了C#中IPublishedContent.AncestorsOrSelf方法的典型用法代码示例。如果您正苦于以下问题:C# IPublishedContent.AncestorsOrSelf方法的具体用法?C# IPublishedContent.AncestorsOrSelf怎么用?C# IPublishedContent.AncestorsOrSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPublishedContent
的用法示例。
在下文中一共展示了IPublishedContent.AncestorsOrSelf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCSSClass
/// <summary>
/// Generates css class for current node from its doctype and name
/// </summary>
/// <param name="currentNode"></param>
/// <returns>
/// Doctypes: post, category, homepage, other-type
/// </returns>
public static String GenerateCSSClass(IPublishedContent currentNode)
{
//TODO: solve multilanguage issue (url names will differ for same pages)
String result = "other-type";
if (currentNode != null)
{
var typeService = ApplicationContext.Current.Services.ContentTypeService;
IContentType nodeType = typeService.GetContentType(currentNode.DocumentTypeAlias);
if (nodeType != null)
{
if (
nodeType.ContentTypeCompositionExists("Category") ||
currentNode.DocumentTypeAlias == "Category" ||
currentNode.DocumentTypeAlias == "SearchResults" ||
currentNode.DocumentTypeAlias == "List"
)
{
result = "category";
}
else if (
nodeType.ContentTypeCompositionExists("Homepage") ||
currentNode.DocumentTypeAlias == "Homepage"
)
{
result = "homepage";
}
else if (
nodeType.ContentTypeCompositionExists("SimplePage") ||
currentNode.DocumentTypeAlias == "Contact" ||
currentNode.DocumentTypeAlias == "ListElement" ||
currentNode.DocumentTypeAlias == "SimplePage" ||
currentNode.DocumentTypeAlias == "Site_Infographic"
)
{
result = "post";
}
}
IEnumerable<IPublishedContent> ancestors = currentNode.AncestorsOrSelf();
foreach (IPublishedContent ancestor in ancestors)
{
if (ancestor.Level > 0)
{
result += " con_" + ancestor.UrlName;
}
}
//add document type
var projectPrefixes = new string[] {"Site_", "Academy_", "Creative_" };
var doctypeName = currentNode.DocumentTypeAlias;
foreach (var prefix in projectPrefixes)
{
doctypeName = doctypeName.Replace(prefix, "");
}
doctypeName = Regex.Replace(doctypeName, "(\\B[A-Z])", "-$1");
doctypeName = doctypeName.ToCharArray()[0] == '-' ? doctypeName.Substring(1) : doctypeName ;
result += " doc_" + doctypeName.ToLower().Replace(" ", "-").Replace("_", "");
}
return result;
}
示例2: MapWebsite
public Website MapWebsite(IPublishedContent currentPage)
{
IPublishedContent websitePage = currentPage.AncestorsOrSelf("Website").FirstOrDefault();
if (websitePage == null)
{
throw new NullReferenceException("No ancestor or self Website document type found.");
}
var website = new Website();
_umbracoMapper.Map(websitePage, website);
return website;
}