Exemplo n.º 1
0
        ApiEntry CreateEntry(MemberInfo memberInfo)
        {
            var entry = ApiEntry.Create(this, _whitelist, memberInfo);

            if (entry == null)
            {
                return(null);
            }

            string docFileName = null;

            if (memberInfo is Type type)
            {
                docFileName = Path.ChangeExtension(new Uri(type.Assembly.CodeBase).LocalPath, "xml");
            }
            else
            {
                var codeBase = memberInfo.DeclaringType?.Assembly.CodeBase;
                if (codeBase != null)
                {
                    docFileName = Path.ChangeExtension(new Uri(codeBase).LocalPath, "xml");
                }
            }

            if (docFileName != null)
            {
                if (!_documentationCache.TryGetValue(docFileName, out var documentation))
                {
                    _documentationCache[docFileName] = documentation = File.Exists(docFileName) ? XDocument.Load(docFileName) : null;
                }
                var doc = documentation?.XPathSelectElement($"/doc/members/member[@name='{entry.XmlDocKey}']");
                entry.Documentation = XmlDoc.Generate(doc);
            }

            return(entry);
        }
Exemplo n.º 2
0
        public static XmlDoc Decode(XmlDoc root, XNode node)
        {
            if (node == null)
            {
                return(null);
            }
            switch (node)
            {
            case XElement element:
                switch (element.Name.LocalName)
                {
                case "member":
                    return(new MemberParagraph(element.Nodes().Select(n => Decode(root, n)).Where(n => n != null)));

                case "code":
                    return(new CodeParagraph(element.Value));

                case "c":
                    return(new CodeSpan(element.Value));

                case "example":
                    return(new Paragraph(ParagraphType.Example, element.Nodes().Select(n => Decode(root, n)).Where(n => n != null)));

                case "para":
                    return(new Paragraph(ParagraphType.Default, element.Nodes().Select(n => Decode(root, n)).Where(n => n != null)));

                case "param":
                    return(new ParamParagraph((string)element.Attribute("name"), element.Nodes().Select(n => Decode(root, n)).Where(n => n != null)));

                case "paramref":
                    return(new ParamRefSpan((string)element.Attribute("name")));

                case "remarks":
                    return(new Paragraph(ParagraphType.Remarks, element.Nodes().Select(n => Decode(root, n)).Where(n => n != null)));

                case "returns":
                    return(new Paragraph(ParagraphType.Remarks, element.Nodes().Select(n => Decode(root, n)).Where(n => n != null)));

                case "see":
                    return(new TypeRefSpan((string)element.Attribute("cref")));

                case "seealso":
                {
                    var link = new TypeRefSpan((string)element.Attribute("cref"));
                    root.SeeAlso.Add(link);
                    return(link);
                }

                case "summary":
                    return(new Paragraph(ParagraphType.Summary, element.Nodes().Select(n => Decode(root, n)).Where(n => n != null)));

                case "typeparam":
                    return(new TypeParamParagraph((string)element.Attribute("name"), element.Nodes().Select(n => Decode(root, n)).Where(n => n != null)));

                case "typeparamref":
                    return(new TypeParamRefSpan((string)element.Attribute("name")));

                case "value":
                    return(new Paragraph(ParagraphType.Value, element.Nodes().Select(n => Decode(root, n)).Where(n => n != null)));

                case "include":
                case "list":
                case "permissions":
                    throw new NotImplementedException($"{element.Name.LocalName} elements are not implemented");
                }

                break;

            case XText text:
                return(new Span(text.Value));
            }

            return(null);
        }