Beispiel #1
0
        /// <summary>
        /// Parses the inheritance chain into text.
        /// </summary>
        /// <param name="inheritance">The inheritance chain.</param>
        /// <returns>The parsed inheritance.</returns>
        public static string ParseInheritance(
            IList <TypeRef> inheritance)
        {
            var first = true;
            var sb    = new StringBuilder("Inheritance");

            foreach (TypeRef i in inheritance)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append("→");
                }

                if (i == inheritance[^ 1])
                {
                    sb.Append($" **{MarkdownWriter.Normalize(i.FriendlyName)}**");
                    continue;
                }

                sb.Append(Writer.WriteLink(i));
            }

            return(sb.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Parses a <see cref="DocExportedType"/> to a <see cref="DocFile"/>.
        /// </summary>
        /// <param name="t">The <see cref="DocExportedType"/> to parse.</param>
        /// <returns>The transformed <see cref="DocFile"/>.</returns>
        private DocFile ProcessType(DocExportedType t)
        {
            var result = new DocFile(t.FileName);

            var classification = t.IsInterface ? "Interface" : (t.IsEnum ? "Enum" : "Class");

            result.AddThenBlankLine(writer.WriteHeading1($"{MarkdownWriter.Normalize(t.TypeRef.FriendlyName)} {classification}"));

            result.AddThenBlankLine(ParserUtils.ProcessBreadcrumb(t));
            result.AddThenBlankLine(t.Description);
            ExtractCode(t.Code, result);

            ExtractTypeParameters(t.TypeParameters, result);

            if (t.Inheritance.Any())
            {
                result.AddThenBlankLine(ParserUtils.ParseInheritance(t.Inheritance));
            }

            if (t.ImplementedInterfaces.Any())
            {
                result.AddThenBlankLine(ParserUtils
                                        .ParseImplementedInterfaces(t.ImplementedInterfaces));
            }

            if (t.DerivedTypes.Any())
            {
                result.AddThenBlankLine(ParserUtils
                                        .ParseDerivedTypes(t.DerivedTypes));
            }

            ExtractExamples(t.Example, result);

            ExtractRemarks(t.Remarks, result);

            ExtractCtors(t.Constructor, result);

            ExtractProperties(t.Properties, result);

            ExtractMethods(t, result);

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Extracts the constructors into a table and files.
        /// </summary>
        /// <param name="constructor">The <see cref="DocConstructor"/>.</param>
        /// <param name="result">The <see cref="DocFile"/> to parse to.</param>
        private void ExtractCtors(DocConstructor constructor, DocFile result)
        {
            if (constructor == null || !constructor.Overloads.Any())
            {
                return;
            }

            var ctorFile = new DocFile(constructor.FileName);

            result.Files.Add(ctorFile);
            result.AddThenBlankLine(writer.WriteHeading2($"Constructors"));

            ctorFile.AddThenBlankLine(writer.WriteHeading1(
                                          $"{MarkdownWriter.Normalize(constructor.ConstructorType.TypeRef.FriendlyName.NameOnly())} Constructors"));
            ctorFile.AddThenBlankLine(ParserUtils.ProcessBreadcrumb(constructor));
            ctorFile.AddThenBlankLine(constructor.Overloads[0].Description);
            ctorFile.AddThenBlankLine(writer.WriteHeading2("Overloads"));

            var table     = new MarkdownTable("Ctor", "Description");
            var tableCtor = new MarkdownTable("Ctor", "Description");
Beispiel #4
0
        /// <summary>
        /// Parses the XML comments.
        /// </summary>
        /// <param name="doc">The <see cref="XmlDocument"/> for XML comments.</param>
        /// <param name="assembly">The <see cref="DocAssembly"/> to annotate.</param>
        private void ParseXml(XmlDocument doc, DocAssembly assembly)
        {
            var typeList = assembly.Namespaces.SelectMany(ns => ns.Types);

            foreach (var type in typeList)
            {
                var typeNode = doc.SelectSingleNode(type.XPath);
                if (typeNode == null)
                {
                    NotFound(type.XPath);
                }

                if (typeNode is XmlElement node)
                {
                    type.Description = GetTextBlock(node, ParserUtils.Summary);
                    type.Remarks     = GetTextBlock(node, ParserUtils.Remarks);
                    type.Example     = GetTextBlock(node, ParserUtils.Example);
                    ProcessTypeParamDescriptions(node, type.TypeParameters);
                }

                if (type.Constructor != null && type.Constructor.Overloads.Any())
                {
                    foreach (var overload in type.Constructor.Overloads)
                    {
                        var docNode = doc.SelectSingleNode(overload.XPath);

                        if (docNode == null)
                        {
                            NotFound(overload.XPath);
                        }

                        if (docNode is XmlElement ctorNode)
                        {
                            overload.Description = GetTextBlock(ctorNode, ParserUtils.Summary);
                            overload.Remarks     = GetTextBlock(ctorNode, ParserUtils.Remarks);
                            overload.Example     = GetTextBlock(ctorNode, ParserUtils.Example);
                            overload.Exceptions  = GetExceptions(ctorNode);
                            ProcessParameters(overload.Parameters, ctorNode);
                            ProcessTypeParamDescriptions(ctorNode, overload.TypeParameters);
                        }

                        if (string.IsNullOrWhiteSpace(overload.Description))
                        {
                            var ctorType = overload.Constructor.ConstructorType.Type;
                            overload.Description =
                                $"Initializes a new instance of the [{MarkdownWriter.Normalize(TypeCache.Cache[ctorType].FriendlyName)}]({TypeCache.Cache[ctorType].Link}) class.";
                        }
                    }
                }

                if (type.Methods.Any())
                {
                    foreach (var method in type.Methods)
                    {
                        foreach (var overload in method.MethodOverloads)
                        {
                            var oNode = doc.SelectSingleNode(overload.XPath);

                            if (oNode == null)
                            {
                                NotFound(overload.XPath);
                            }

                            if (oNode is XmlElement methodNode)
                            {
                                overload.Description = GetTextBlock(methodNode, ParserUtils.Summary);
                                overload.Remarks     = GetTextBlock(methodNode, ParserUtils.Remarks);
                                overload.Example     = GetTextBlock(methodNode, ParserUtils.Example);
                                overload.Exceptions  = GetExceptions(methodNode);
                                overload.Returns     = GetTextBlock(methodNode, ParserUtils.Returns);
                                ProcessParameters(overload.Parameters, methodNode);
                                ProcessTypeParamDescriptions(methodNode, overload.Method.MethodType.TypeParameters);
                            }
                        }
                    }
                }

                if (type.Properties.Any())
                {
                    ProcessProperties(doc, type.Properties, type.TypeParameters);
                }
            }
        }