1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
-
- using System;
- using System.IO;
- using ICSharpCode.NRefactory.CSharp;
- using Mono.Cecil;
- namespace ICSharpCode.ILSpy.XmlDoc
- {
-
-
-
- static class AddXmlDocTransform
- {
- public static void Run(AstNode node)
- {
- if (node is EntityDeclaration) {
- MemberReference mr = node.Annotation<MemberReference>();
- if (mr != null && mr.Module != null) {
- var xmldoc = XmlDocLoader.LoadDocumentation(mr.Module);
- if (xmldoc != null) {
- string doc = xmldoc.GetDocumentation(XmlDocKeyProvider.GetKey(mr));
- if (doc != null) {
- InsertXmlDocumentation(node, new StringReader(doc));
- }
- }
- }
- if (!(node is TypeDeclaration))
- return;
- }
- foreach (AstNode child in node.Children)
- Run(child);
- }
-
- static void InsertXmlDocumentation(AstNode node, StringReader r)
- {
-
- 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;
-
- while (line != null) {
- if (string.IsNullOrWhiteSpace(line)) {
- skippedWhitespaceLines++;
- } else {
- while (skippedWhitespaceLines > 0) {
- node.Parent.InsertChildBefore(node, new Comment(string.Empty, CommentType.Documentation), Roles.Comment);
- skippedWhitespaceLines--;
- }
- if (line.StartsWith(indentation, StringComparison.Ordinal))
- line = line.Substring(indentation.Length);
- node.Parent.InsertChildBefore(node, new Comment(" " + line, CommentType.Documentation), Roles.Comment);
- }
- line = r.ReadLine();
- }
- }
- }
- }
|