Esempio n. 1
0
        private TocItemYaml FromHierarchyChange(IReadOnlyDictionary <string, HierarchyChange> changeDict, HierarchyChange change, BuildContext context)
        {
            var parentChange = change.Parent != null ? changeDict[change.Parent] : null;

            return(new TocItemYaml
            {
                Uid = change.Uid,
                Name = NameGenerator.GenerateTypeName(new NameGeneratorContext {
                    CurrentChange = change, ParentChange = parentChange
                }, null, true),
                Href = YamlUtility.ParseHrefFromChangeFile(change.File),
                Items = change.Children.Any() ? new TocYaml(
                    from child in change.Children
                    let toc = FromHierarchyChange(changeDict, changeDict[child], context)
                              orderby toc.Name.ToLower()
                              select toc) : null,
            });
        }
Esempio n. 2
0
        public Task <PageModel> GenerateArticleAsync(BuildContext context, XDocument document)
        {
            PageModel page = new PageModel()
            {
                Items = new List <ArticleItemYaml>()
            };
            ArticleItemYaml mainYaml = new ArticleItemYaml();

            page.Items.Add(mainYaml);

            var             articleContext = new ArticleContext(context);
            HierarchyChange curChange      = articleContext.CurrentChange;
            HierarchyChange parentChange   = articleContext.ParentChange;
            var             nameContext    = new NameGeneratorContext {
                CurrentChange = curChange, ParentChange = parentChange
            };
            var main = document.Root.NullableElement("compounddef");

            mainYaml.Uid = curChange.Uid;
            mainYaml.Id  = _nameGenerator.GenerateId(nameContext, main);
            mainYaml.SupportedLanguages = new string[] { Language };
            mainYaml.FullName           = _nameGenerator.GenerateTypeFullName(nameContext, main, true);
            mainYaml.Name         = _nameGenerator.GenerateTypeName(nameContext, main, true);
            mainYaml.NameWithType = mainYaml.Name;
            mainYaml.FullNameWithoutTypeParameter = _nameGenerator.GenerateTypeFullName(nameContext, main, false);
            mainYaml.NameWithoutTypeParameter     = _nameGenerator.GenerateTypeName(nameContext, main, false);
            mainYaml.Href     = YamlUtility.ParseHrefFromChangeFile(curChange.File);
            mainYaml.Type     = YamlUtility.ParseType(curChange.Type.ToString());
            mainYaml.Parent   = curChange.Parent;
            mainYaml.Children = curChange.Children != null ? new List <string>(curChange.Children.OrderBy(c => c)) : new List <string>();
            FillSummary(mainYaml, main);
            FillRemarks(mainYaml, main);
            FillSource(mainYaml, main);
            FillSees(mainYaml, main);
            FillException(mainYaml, main);
            FillInheritance(nameContext, mainYaml, main);
            FillSyntax(mainYaml, main, isMain: true);
            FillImplementsOrInherits(mainYaml, main);
            FillLanguageSpecificMetadata(mainYaml, articleContext, main);

            var members = new Dictionary <string, ArticleItemYaml>();

            foreach (var section in main.Elements("sectiondef"))
            {
                string kind  = section.NullableAttribute("kind").NullableValue();
                var    tuple = KindMapToType(kind);
                if (tuple.Item1.HasValue && ((tuple.Item2 & AccessLevel.NotAccessible) == AccessLevel.None))
                {
                    foreach (var member in section.Elements("memberdef"))
                    {
                        var memberYaml = new ArticleItemYaml();
                        memberYaml.Uid = member.NullableAttribute("id").NullableValue();
                        memberYaml.Id  = _nameGenerator.GenerateId(nameContext, member);
                        memberYaml.SupportedLanguages = new string[] { Language };
                        memberYaml.FullName           = _nameGenerator.GenerateMemberFullName(nameContext, member);
                        memberYaml.Name         = _nameGenerator.GenerateMemberName(nameContext, member);
                        memberYaml.NameWithType = _nameGenerator.GenerateMemberNameWithType(memberYaml.Name, mainYaml.Name);
                        memberYaml.Href         = mainYaml.Href;
                        memberYaml.Type         = string.IsNullOrEmpty(member.NullableElement("type").NullableValue()) && tuple.Item1.Value == MemberType.Method ? MemberType.Constructor : tuple.Item1.Value;
                        memberYaml.Parent       = mainYaml.Uid;
                        FillSummary(memberYaml, member);
                        FillRemarks(memberYaml, member);
                        FillSource(memberYaml, member);
                        FillSees(memberYaml, member);
                        FillException(memberYaml, member);
                        FillOverridden(memberYaml, member);
                        FillSyntax(memberYaml, member, isMain: false);
                        FillLanguageSpecificMetadata(memberYaml, articleContext, member);
                        FillOverload(memberYaml, member);

                        if (members.ContainsKey(memberYaml.Uid))
                        {
                            ConsoleLogger.WriteLine(
                                new LogEntry
                            {
                                Phase   = "GenerateArticles",
                                Level   = LogLevel.Warning,
                                Message = $"Duplicate items {memberYaml.Uid} found in {curChange.File}.",
                            });
                            continue;
                        }
                        members[memberYaml.Uid] = memberYaml;
                        EmptyToNull(memberYaml);
                    }
                }
            }

            mainYaml.Children.AddRange(from p in members
                                       orderby p.Value.Name.ToLower()
                                       select p.Key);
            page.Items.AddRange(from i in members.Values
                                orderby i.Name.ToLower()
                                select i);

            // after children are filled, fill inherited members
            FillInheritedMembers(mainYaml, main);
            FillReferences(page, document, articleContext);

            EmptyToNull(mainYaml);
            return(Task.FromResult(page));
        }