示例#1
0
        private void WriteItems <T>(DocWriter writer, IReadOnlyList <T> items)
            where T : AItem
        {
            if (items?.Count > 0)
            {
                writer.WriteLine($"### {items[0].Header}");

                foreach (T item in items)
                {
                    writer.Break();
                    switch (item)
                    {
                    case ExceptionItem exception:
                        writer.WriteLine(
                            _items.TryGetValue(exception.Reference, out AMemberItem reference)
                                ? reference.AsLink()
                                : exception.Reference.Substring(2).AsDotNetApiLink());
                        break;

                    case ANamedItem namedItem:
                        writer.WriteLine(namedItem.AsLinkTarget());
                        writer.WriteLine($"`{namedItem.Name}`");
                        break;
                    }
                    writer.Break();
                    WriteText(writer, item);
                }
            }
        }
示例#2
0
        private void WriteLinkForType(DocWriter writer, TypeItem item)
        {
            writer.WriteLine($"- {item.AsLink()}");

            foreach (TypeItem nested in _items.Values.OfType <TypeItem>().Where(i => i.Parent == item).OrderBy(i => i.Name))
            {
                WriteLinkForType(writer, nested);
            }
        }
示例#3
0
 private void WriteItem <T>(DocWriter writer, T item)
     where T : AItem
 {
     if (item != null)
     {
         writer.WriteLine($"### {item.Header}");
         WriteText(writer, item);
     }
 }
示例#4
0
        private void WriteDocPages <T>()
            where T : AMemberItem
        {
            Items.Values.OfType <T>().AsParallel().ForAll(item =>
            {
                using DocWriter writer = new DocWriter(_outputPath, item);

                WriteDocFor(writer, item);
            });
        }
示例#5
0
        private void WriteTypePages()
        {
            Items.Values.OfType <TypeItem>().AsParallel().ForAll(item =>
            {
                using DocWriter writer = new DocWriter(_outputPath, item);

                WriteDocFor(writer, item);
                WriteLinkFor <ConstructorItem>(writer, item);
                WriteLinkFor <FieldItem>(writer, item);
                WriteLinkFor <PropertyItem>(writer, item);
                WriteLinkFor <MethodItem>(writer, item);
                WriteLinkFor <EventItem>(writer, item);
                WriteLinkFor <OperatorItem>(writer, item);
            });
        }
示例#6
0
        private void WriteLinkFor <T>(DocWriter writer, AMemberItem parent)
            where T : AMemberItem
        {
            bool hasHeader = false;

            foreach (T item in _items.Values.OfType <T>().Where(i => i.Parent == parent).OrderBy(i => i.Name))
            {
                if (!hasHeader)
                {
                    hasHeader = true;
                    writer.WriteLine($"### {item.Header}");
                }

                writer.WriteLine($"- {item.AsLink()}");
            }
        }
示例#7
0
        private void WriteDocFor <T>(DocWriter writer, T item)
            where T : AMemberItem
        {
            writer.WriteLine($"#### {MainName.AsLink()}");
            AMemberItem         parent  = item.Parent;
            Stack <AMemberItem> parents = new Stack <AMemberItem>();

            while (parent != null)
            {
                parents.Push(parent);
                parent = parent.Parent;
            }
            writer.WriteLine($"### {string.Join(".", parents.Select(i => i is NamespaceItem ? i.AsLinkWithTarget(MainName) : i.AsLink()))}");

            item.Write(this, writer);
        }
示例#8
0
        private void WriteHome()
        {
            using DocWriter writer = new DocWriter(_outputPath, MainName);

            writer.WriteLine($"### {MainName.AsLink()}");

            foreach (NamespaceItem item in Items.Values.OfType <NamespaceItem>().OrderBy(i => i.Name))
            {
                writer.WriteLine(item.AsLinkTarget());
                writer.WriteLine($"## {item.Name}");

                foreach (TypeItem type in Items.Values.OfType <TypeItem>().Where(i => i.Parent == item).OrderBy(i => i.Name))
                {
                    WriteLinkForType(writer, type);
                }
            }
        }
示例#9
0
        private void WriteDocFor <T>(DocWriter writer, T item)
            where T : AMemberItem
        {
            writer.WriteLine($"#### {_mainName.AsLink()}");
            AMemberItem         parent  = item.Parent;
            Stack <AMemberItem> parents = new Stack <AMemberItem>();

            while (parent != null)
            {
                parents.Push(parent);
                parent = parent.Parent;
            }
            writer.WriteLine($"### {string.Join(".", parents.Select(i => i is NamespaceItem ? i.AsLinkWithTarget(_mainName) : i.AsLink()))}");
            writer.WriteLine($"## {item.Name} `{item.Title}`");

            WriteText(writer, item);
            WriteItem(writer, item.Remarks);
            WriteItem(writer, item.Example);
            WriteItems(writer, (item as AGenericDocItem)?.Generics);
            WriteItems(writer, (item as IParameterDocItem)?.Parameters);
            WriteItem(writer, (item as IReturnDocItem)?.Return);
            WriteItem(writer, (item as PropertyItem)?.Value);
            WriteItems(writer, item.Exceptions);
        }
示例#10
0
        private void WriteText(DocWriter writer, AItem item)
        {
            string summary = string.Empty;

            void WriteNodes(IEnumerable <XNode> nodes)
            {
                foreach (XNode node in nodes)
                {
                    switch (node)
                    {
                    case XText text:
                        summary += string.Join("  \n", text.Value.Split('\n'));
                        break;

                    case XElement element:
                        switch (element.Name.LocalName)
                        {
                        case "see":
                        case "seealso":
                            string referenceName = element.GetReferenceName();
                            summary +=
                                _items.TryGetValue(referenceName, out AMemberItem reference)
                                        ? (reference is NamespaceItem ? reference.AsLinkWithTarget(_mainName) : reference.AsLink())
                                        : referenceName.Substring(2).AsDotNetApiLink();
                            break;

                        case "typeparamref":
                            AMemberItem parent  = item as AMemberItem ?? item.Parent;
                            GenericItem generic = null;
                            while (parent != null && generic == null)
                            {
                                if (parent is AGenericDocItem genericItem)
                                {
                                    generic = Array.Find(genericItem.Generics, i => i.Name == element.GetName());
                                }

                                parent = parent.Parent;
                            }

                            if (generic == null)
                            {
                                summary += element.GetName();
                            }
                            else
                            {
                                summary +=
                                    writer.IsForThis(generic.Parent)
                                            ? generic.AsPageLink()
                                            : generic.AsLinkWithTarget();
                            }
                            break;

                        case "paramref":
                            IParameterDocItem parameterItem = (item as IParameterDocItem) ?? (item.Parent as IParameterDocItem);
                            ParameterItem     parameter     = parameterItem.Parameters.First(i => i.Name == element.GetName());

                            summary += parameter.AsPageLink();
                            break;

                        case "c":
                            summary += $"`{element.Value}`";
                            break;

                        case "code":
                            summary += $"```{element.Value}```\n";
                            break;

                        case "para":
                            summary += "\n\n";
                            WriteNodes(element.Nodes());
                            summary += "\n\n";
                            break;

                        default:
                            summary += element.ToString();
                            break;
                        }
                        break;

                    default:
                        throw new Exception($"unhandled node type in summary {node.NodeType}");
                    }
                }
            }

            WriteNodes(item.Summary.Nodes());

            string[] lines      = summary.Split('\n');
            int      startIndex = 0;
            int      firstLine  = 0;

            foreach (string line in lines)
            {
                if (!string.IsNullOrWhiteSpace(line))
                {
                    startIndex = line.Length - line.TrimStart().Length;
                    break;
                }

                ++firstLine;
            }

            summary = string.Join(Environment.NewLine, lines.Skip(firstLine).Select(l => l.StartsWith(" ") ? l.Substring(startIndex) : l));
            while (summary.EndsWith(Environment.NewLine))
            {
                summary = summary.Substring(0, summary.Length - Environment.NewLine.Length);
            }

            writer.WriteLine($"{summary.TrimEnd()}");
        }