/// <summary>
        /// Parse .Net XML documentation about this member.
        /// </summary>
        /// <remarks>Clears any existing comments before parsing the new ones.</remarks>
        /// <param name="parent">Expects the tag containing all documentation for this member.</param>
        public void ParseVisualStudioXmlDocumentation(XElement parent)
        {
            parent = parent.CleanWhitespaces();

            ClearComments();

            //todo: refactor: using DotNetComment.Tag, alot of this duplication can be removed

            bool previousCommentWasAParagraphTag = false;

            foreach (XNode node in parent.Nodes())
            {
                DotNetComment comment = null;
                switch (node.NodeType)
                {
                case XmlNodeType.Element:
                    XElement element = (node as XElement);
                    switch (element.Name.LocalName)
                    {
                    case "example":
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        ExampleComments.Add(comment);
                        previousCommentWasAParagraphTag = true;
                        break;

                    case "exception":
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        ExceptionComments.Add(comment as DotNetCommentQualifiedLinkedGroup);
                        previousCommentWasAParagraphTag = true;
                        break;

                    case "param":
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        ParameterComments.Add(comment as DotNetCommentParameter);
                        previousCommentWasAParagraphTag = true;
                        break;

                    case "permission":
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        PermissionComments.Add(comment as DotNetCommentQualifiedLinkedGroup);
                        previousCommentWasAParagraphTag = true;
                        break;

                    case "remarks":
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        RemarksComments.Add(comment);
                        previousCommentWasAParagraphTag = true;
                        break;

                    case "returns":
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        ReturnsComments.Add(comment);
                        previousCommentWasAParagraphTag = true;
                        break;

                    case "summary":
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        SummaryComments.Add(comment);
                        previousCommentWasAParagraphTag = true;
                        break;

                    case "typeparam":
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        TypeParameterComments.Add(comment as DotNetCommentParameter);
                        previousCommentWasAParagraphTag = true;
                        break;

                    case "value":
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        ValueComments.Add(comment);
                        previousCommentWasAParagraphTag = true;
                        break;

                    default:
                        comment = DotNetComment.FromVisualStudioXml(element);
                        if (comment == null)
                        {
                            break;
                        }
                        if (previousCommentWasAParagraphTag && comment.ToString() == "\n")
                        {
                            break;
                        }
                        FloatingComments.Add(comment);
                        previousCommentWasAParagraphTag = (comment.Tag == CommentTag.Para || comment.Tag == CommentTag.List || comment.Tag == CommentTag.Code);
                        break;
                    }
                    break;

                case XmlNodeType.Text:
                    comment = DotNetComment.FromVisualStudioXml(Utilities.XNodeToString(node));
                    if (comment == null)
                    {
                        break;
                    }
                    if (previousCommentWasAParagraphTag && comment.ToString() == "\n")
                    {
                        break;
                    }
                    FloatingComments.Add(comment);
                    previousCommentWasAParagraphTag = false;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        /// <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);
        }