示例#1
0
        static void InsertXmlDocumentation(AstNode node, StringReader r)
        {
            // Find the first non-empty line:
            string firstLine;

            do
            {
                firstLine = r.ReadLine();
                if (firstLine == null)
                {
                    return;
                }
            } while (string.IsNullOrWhiteSpace(firstLine));
            string indentation            = firstLine.Substring(0, firstLine.Length - firstLine.TrimStart().Length);
            string line                   = firstLine;
            int    skippedWhitespaceLines = 0;

            // Copy all lines from input to output, except for empty lines at the end.
            while (line != null)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    skippedWhitespaceLines++;
                }
                else
                {
                    while (skippedWhitespaceLines > 0)
                    {
                        Comment emptyLine = new Comment(string.Empty, CommentType.Documentation);
                        emptyLine.AddAnnotation(node.GetResolveResult());
                        node.Parent.InsertChildBefore(node, emptyLine, Roles.Comment);
                        skippedWhitespaceLines--;
                    }
                    if (line.StartsWith(indentation, StringComparison.Ordinal))
                    {
                        line = line.Substring(indentation.Length);
                    }
                    Comment comment = new Comment(" " + line, CommentType.Documentation);
                    comment.AddAnnotation(node.GetResolveResult());
                    node.Parent.InsertChildBefore(node, comment, Roles.Comment);
                }
                line = r.ReadLine();
            }
        }