/// <summary>Parses top-level .Net XML documentation comments. Returns null if no comments are found.</summary> /// <returns>Returns null if the element name is not recognized.</returns> public static DotNetComment FromVisualStudioXml(XElement element) { switch (element.Name.LocalName) { case "summary": case "remarks": case "example": case "para": //paragraph case "returns": case "value": DotNetCommentGroup group = DotNetCommentGroup.FromVisualStudioXml(element); if (group.IsEmpty) { return(null); } return(group); case "exception": case "permission": if (element.Attribute("cref") == null) { break; } if (String.IsNullOrEmpty(element.Attribute("cref").Value)) { break; } return(DotNetCommentQualifiedLinkedGroup.FromVisualStudioXml(element)); case "see": case "seealso": if (element.Attribute("cref") == null) { break; } if (String.IsNullOrEmpty(element.Attribute("cref").Value)) { break; } if (element.Nodes().Count() == 0) { return(DotNetCommentQualifiedLink.FromVisualStudioXml(element)); } else { return(DotNetCommentQualifiedLinkedGroup.FromVisualStudioXml(element)); } case "list": return(DotNetCommentList.FromVisualStudioXml(element)); case "param": return(DotNetCommentParameter.FromVisualStudioXml(element)); case "paramref": return(DotNetCommentParameterLink.FromVisualStudioXml(element)); case "typeparam": return(DotNetCommentTypeParameter.FromVisualStudioXml(element)); case "typeparamref": return(DotNetCommentTypeParameterLink.FromVisualStudioXml(element)); case "c": //inline code return(DotNetCommentCode.FromVisualStudioXml(element)); case "code": //code block return(DotNetCommentCodeBlock.FromVisualStudioXml(element)); case "inheritdoc": return(new DotNetCommentInherit()); case "duplicate": if (element.Attribute("cref") == null) { break; } string duplicateCref = element.Attribute("cref").Value; if (String.IsNullOrEmpty(duplicateCref)) { break; } return(new DotNetCommentDuplicate(DotNetCommentQualifiedLink.FromVisualStudioXml(duplicateCref))); } return(null); }
/// <summary>Parses inner .Net XML documentation comments.</summary> protected static List <DotNetComment> ParseSection(XElement element) { if (element == null) { return(new List <DotNetComment>()); } element = element.CleanWhitespaces(); List <DotNetComment> comments = new List <DotNetComment>(); List <CommentTag> nonParagraphTags = new List <CommentTag>() { CommentTag.Unknown, CommentTag.C, CommentTag.ParamRef, CommentTag.See, CommentTag.SeeAlso, CommentTag.TypeParamRef, }; bool previousCommentWasAParagraphTag = false; foreach (XNode node in element.Nodes()) { DotNetComment comment; switch (node.NodeType) { case XmlNodeType.CDATA: if (Utilities.XNodeToString(node).Contains("\n")) { comment = DotNetCommentCodeBlock.FromVisualStudioXml(node as XCData); comments.Add(comment); previousCommentWasAParagraphTag = true; } else { comment = DotNetCommentCode.FromVisualStudioXml(node as XCData); comments.Add(comment); previousCommentWasAParagraphTag = false; } break; case XmlNodeType.Element: comment = DotNetComment.FromVisualStudioXml(node as XElement); if (comment == null) { break; } comments.Add(comment); previousCommentWasAParagraphTag = !nonParagraphTags.Contains(comment.Tag); break; case XmlNodeType.Text: comment = DotNetComment.FromVisualStudioXml(Utilities.XNodeToString(node)); if (comment == null) { break; } if (previousCommentWasAParagraphTag && comment.ToString() == "\n") { break; } comments.Add(comment); previousCommentWasAParagraphTag = !nonParagraphTags.Contains(comment.Tag); break; } } return(comments); }