当前位置: 首页>>代码示例>>C#>>正文


C# IPublishedContent.AncestorsOrSelf方法代码示例

本文整理汇总了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;
        }
开发者ID:pawelgur,项目名称:UmbracoExtensions,代码行数:67,代码来源:UmbracoNodeHelpers.cs

示例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;
        }
开发者ID:mccallsolutions,项目名称:UmbracoGo,代码行数:14,代码来源:CurrentPageMapperFactory.cs


注:本文中的IPublishedContent.AncestorsOrSelf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。