Exemplo n.º 1
0
        public ArticleId(string articleIdOrSlugOrTitle)
        {
            if (articleIdOrSlugOrTitle == null)
            {
                throw new ArgumentNullException("articleIdOrSlugOrTitle");
            }

            this.hasValueLazy = new Lazy <bool>(() => (!string.IsNullOrWhiteSpace(articleIdOrSlugOrTitle)));

            string articleIdOrSlug = ArticleSlugUtility.Decode(articleIdOrSlugOrTitle);

            bool isId = GetIsId(articleIdOrSlug);

            if (isId)
            {
                this.originalSlugLazy = this.slugLazy;
                this.slugLazy         = new Lazy <string>(() => GetArticleSlug(articleIdOrSlug));
            }
            else
            {
                this.originalSlugLazy = new Lazy <string>(() => articleIdOrSlugOrTitle);
                this.slugLazy         = new Lazy <string>(() => ArticleSlugUtility.Encode(articleIdOrSlug));
            }

            this.idLazy = new Lazy <string>(() => IdUtility.CreateArticleId(this.slugLazy.Value));

            this.titleLazy = new Lazy <string>(() => ArticleSlugUtility.Decode(this.slugLazy.Value));
        }
Exemplo n.º 2
0
        private static string GetArticleSlug(string articleId)
        {
            if (articleId == null)
            {
                throw new ArgumentNullException("articleId");
            }

            int    slashIndex  = articleId.LastIndexOf('/');
            string articleSlug = (slashIndex >= 0) ? articleId.Substring(slashIndex + 1) : articleId;

            return(ArticleSlugUtility.Encode(articleSlug));
        }