Cake.Web.Core.Content.Blog.BlogIndex.BlogIndex C# (CSharp) Метод

BlogIndex() публичный Метод

public BlogIndex ( IEnumerable posts ) : System
posts IEnumerable
Результат System
        public BlogIndex(IEnumerable<BlogPost> posts)
        {
            _posts = new List<BlogPost>(posts);
            _categoryToPostsLookup = new Dictionary<string, List<BlogPost>>(StringComparer.OrdinalIgnoreCase);
            _yearMonthToPostsLookup = new Dictionary<int, Dictionary<int, List<BlogPost>>>();
            _authorToPostsLookup = new Dictionary<string, List<BlogPost>>(StringComparer.OrdinalIgnoreCase);
            _idToPostLookup = new Dictionary<string, BlogPost>(StringComparer.OrdinalIgnoreCase);
            _archive = new List<DateTime>();

            var categories = new HashSet<BlogCategory>(new BlogCategoryComparer());
            var authors = new HashSet<string>();

            foreach (var post in _posts)
            {
                // Create lookup by category.
                foreach (var category in post.Categories)
                {
                    var categorySlug = category.Slug;
                    if (!_categoryToPostsLookup.ContainsKey(categorySlug))
                    {
                        _categoryToPostsLookup.Add(categorySlug, new List<BlogPost>());
                    }

                    _categoryToPostsLookup[categorySlug].Add(post);

                    categories.Add(category);
                }

                // Create lookup by year and month.
                AddToArchive(post);

                if (!_authorToPostsLookup.ContainsKey(post.Author))
                {
                    _authorToPostsLookup.Add(post.Author, new List<BlogPost>());
                }

                _authorToPostsLookup[post.Author].Add(post);

                authors.Add(post.Author);

                // Create lookup by ID.
                AddToLookup(post);
            }

            _categories = new List<BlogCategory>(categories);
            _authors = new List<string>(authors);
        }