public void Run(AstNode rootNode, TransformContext context) { if (!context.Settings.ShowXmlDocumentation || context.DecompileRun.DocumentationProvider == null) { return; } try { var provider = context.DecompileRun.DocumentationProvider; foreach (var entityDecl in rootNode.DescendantsAndSelf.OfType <EntityDeclaration>()) { if (!(entityDecl.GetSymbol() is IEntity entity)) { continue; } string doc = provider.GetDocumentation(entity); if (doc != null) { InsertXmlDocumentation(entityDecl, new StringReader(doc)); } } } catch (XmlException ex) { string[] msg = (" Exception while reading XmlDoc: " + ex).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); var insertionPoint = rootNode.FirstChild; for (int i = 0; i < msg.Length; i++) { rootNode.InsertChildBefore(insertionPoint, new Comment(msg[i], CommentType.Documentation), Roles.Comment); } } }
public void Run(AstNode rootNode, TransformContext context) { if (!context.Settings.ShowXmlDocumentation) { return; } try { var xmldoc = XmlDocLoader.LoadDocumentation(context.TypeSystem.ModuleDefinition); if (xmldoc == null) { return; } foreach (var entity in rootNode.DescendantsAndSelf.OfType <EntityDeclaration>()) { var symbol = entity.GetSymbol(); Mono.Cecil.MemberReference mr; switch (symbol) { case IMember member: mr = context.TypeSystem.GetCecil(member); break; case IType type: mr = context.TypeSystem.GetCecil(type.GetDefinition()); break; default: continue; } if (mr == null) { continue; } string doc = xmldoc.GetDocumentation(XmlDocKeyProvider.GetKey(mr)); if (doc != null) { InsertXmlDocumentation(entity, new StringReader(doc)); } } } catch (XmlException ex) { string[] msg = (" Exception while reading XmlDoc: " + ex).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); var insertionPoint = rootNode.FirstChild; for (int i = 0; i < msg.Length; i++) { rootNode.InsertChildBefore(insertionPoint, new Comment(msg[i], CommentType.Documentation), Roles.Comment); } } }
public static void InsertComment (AstNode node, MonoDevelop.CSharp.Ast.Comment comment) { if (node.EndLocation < comment.StartLocation) { node.AddChild (comment); return; } foreach (var child in node.Children) { if (child.StartLocation < comment.StartLocation && comment.StartLocation < child.EndLocation) { InsertComment (child, comment); return; } if (comment.StartLocation < child.StartLocation) { node.InsertChildBefore (child, comment, AstNode.Roles.Comment); return; } } node.AddChild (comment); }
public void Run (AstNode compilationUnit) { var c = new Comment ("/<reference path='mscorlib.ts'/>"); compilationUnit.InsertChildBefore (compilationUnit.FirstChild, c, Roles.Comment); }