static string DocCommentToJsDoc(DocumentationCommentTriviaSyntax doccomment, PropertyDeclarationSyntax propertyDecl) { StringBuilder js = new StringBuilder(); string comment = doccomment.ToString(); comment = comment.Replace("///", ""); var doc = new System.Xml.XmlDocument(); doc.LoadXml("<doc>" + comment + "</doc>"); var nodes = doc.FirstChild.ChildNodes; foreach (var node in nodes) { var element = node as System.Xml.XmlElement; string elementText = element.InnerText.Trim(); if (string.IsNullOrWhiteSpace(elementText)) { continue; } if (element.Name.Equals("summary", StringComparison.OrdinalIgnoreCase)) { js.AppendLine($" * @description {elementText}"); } else if (element.Name.Equals("returns", StringComparison.OrdinalIgnoreCase)) { var returnType = propertyDecl.Type; js.AppendLine($" * @returns {{{ToJavascriptType(returnType.ToString())}}} {elementText}"); } } return(js.ToString()); }
static string DocCommentToTypeScript(DocumentationCommentTriviaSyntax doccomment, MethodDeclarationSyntax methodDecl, ParameterListSyntax parameters, out List <string> paramNames, out List <string> paramTypes) { paramNames = new List <string>(); paramTypes = new List <string>(); StringBuilder js = new StringBuilder(); string comment = doccomment.ToString(); comment = comment.Replace("///", ""); var doc = new System.Xml.XmlDocument(); doc.LoadXml("<doc>" + comment + "</doc>"); var nodes = doc.FirstChild.ChildNodes; foreach (var node in nodes) { var element = node as System.Xml.XmlElement; string elementText = element.InnerText.Trim(); if (string.IsNullOrWhiteSpace(elementText)) { continue; } if (element.Name.Equals("summary", StringComparison.OrdinalIgnoreCase)) { js.AppendLine($" * @description {elementText}"); } else if (element.Name.Equals("returns", StringComparison.OrdinalIgnoreCase)) { var returnType = methodDecl.ReturnType; js.AppendLine($" * @returns {{{ToTypeScriptType(returnType.ToString())}}} {elementText}"); } else if (element.Name.Equals("param", StringComparison.OrdinalIgnoreCase)) { string paramType = ""; string paramName = element.Attributes["name"].Value; paramNames.Add(paramName); for (int j = 0; j < parameters.Parameters.Count; j++) { if (paramName.Equals(parameters.Parameters[j].Identifier.ToString())) { paramType = parameters.Parameters[j].Type.ToString(); break; } } paramTypes.Add(ToTypeScriptType(paramType)); js.AppendLine($" * @param {{{ToTypeScriptType(paramType)}}} {paramName} {elementText}"); } } return(js.ToString()); }
public void AddCommentNode(DocumentationCommentTriviaSyntax node, LocationStore commentLocationstore, ClassStore classStore, string fileName) { Comment comment = new DocComment(node.ToString(), node.GetLocation().GetLineSpan().StartLinePosition.Line + 1, node.GetLocation().GetLineSpan().EndLinePosition.Line) { FileName = fileName, }; comment.Initialize(commentLocationstore, classStore); Comments.Add(comment); }
static System.Xml.XmlDocument DocCommentToXml(DocumentationCommentTriviaSyntax doccomment) { string comment = doccomment.ToString(); comment = comment.Replace("///", ""); comment = comment.Replace("\t", " "); comment = comment.Replace("null ", "None "); comment = comment.Replace("true ", "True "); comment = comment.Replace("false ", "False "); var doc = new System.Xml.XmlDocument(); doc.LoadXml("<doc>" + comment + "</doc>"); return(doc); }
private static string GetSummary(CSharpSyntaxNode node) { DocumentationCommentTriviaSyntax xmlTrivia = node.GetLeadingTrivia() .Select(i => i.GetStructure()) .OfType <DocumentationCommentTriviaSyntax>() .FirstOrDefault(); //TODO: fix bool?isSummary = xmlTrivia?.ChildNodes() .OfType <XmlElementSyntax>() .Any(i => i.StartTag.Name.ToString().Equals("summary")); return(isSummary == true?xmlTrivia.ToString() : null); }
static string[] DocCommentToTypeScript(DocumentationCommentTriviaSyntax doccomment, PropertyDeclarationSyntax propertyDecl) { StringBuilder js = new StringBuilder(); string comment = doccomment.ToString(); comment = comment.Replace("///", ""); var doc = new System.Xml.XmlDocument(); doc.LoadXml("<doc>" + comment + "</doc>"); var nodes = doc.FirstChild.ChildNodes; foreach (var node in nodes) { var element = node as System.Xml.XmlElement; string elementText = element.InnerText.Trim(); if (string.IsNullOrWhiteSpace(elementText)) { continue; } if (element.Name.Equals("summary", StringComparison.OrdinalIgnoreCase)) { js.AppendLine($"{elementText}"); } //else if (element.Name.Equals("returns", StringComparison.OrdinalIgnoreCase)) //{ // var returnType = propertyDecl.Type; // js.AppendLine($" * @returns {{{ToJavascriptType(returnType.ToString())}}} {elementText}"); //} } string[] lines = js.ToString().Split(new char[] { '\n' }); for (int i = 0; i < lines.Length; i++) { lines[i] = lines[i].Trim(); } return(lines); }
static string DocCommentToPythonDoc(DocumentationCommentTriviaSyntax doccomment, int indentLevel) { StringBuilder summary = new StringBuilder(); StringBuilder args = new StringBuilder(); StringBuilder returns = new StringBuilder(); string comment = doccomment.ToString(); comment = comment.Replace("///", ""); comment = comment.Replace("\t", " "); var doc = new System.Xml.XmlDocument(); doc.LoadXml("<doc>" + comment + "</doc>"); var nodes = doc.FirstChild.ChildNodes; foreach (var node in nodes) { var element = node as System.Xml.XmlElement; string elementText = element.InnerText.Trim(); if (string.IsNullOrWhiteSpace(elementText)) { continue; } string[] lines = elementText.Split(new char[] { '\n' }); if (element.Name.Equals("summary", StringComparison.OrdinalIgnoreCase)) { foreach (var line in lines) { summary.AppendLine(_T(indentLevel) + line.Trim()); } } else if (element.Name.Equals("returns", StringComparison.OrdinalIgnoreCase)) { returns.AppendLine(); returns.AppendLine(_T(indentLevel) + "Returns:"); foreach (var line in lines) { returns.AppendLine(_T(indentLevel + 1) + line.Trim()); } } else if (element.Name.Equals("param", StringComparison.OrdinalIgnoreCase)) { if (args.Length == 0) { args.AppendLine(); args.AppendLine(_T(indentLevel) + "Args:"); } string parameterName = element.GetAttribute("name"); bool added = false; foreach (var line in lines) { if (!added) { args.AppendLine(_T(indentLevel + 1) + parameterName + " : " + line.Trim()); continue; } added = true; args.AppendLine(_T(indentLevel + 1) + line.Trim()); } } } StringBuilder rc = new StringBuilder(); rc.AppendLine(_T(indentLevel) + "\"\"\""); rc.Append(summary.ToString()); rc.Append(args.ToString()); rc.Append(returns.ToString()); rc.AppendLine(_T(indentLevel) + "\"\"\""); return(rc.ToString()); }
//public override void VisitDelegateDeclaration(DelegateDeclarationSyntax node) //{ // base.VisitDelegateDeclaration(node); //} //public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node) //{ // base.VisitDestructorDeclaration(node); //} //public override void VisitDiscardDesignation(DiscardDesignationSyntax node) //{ // base.VisitDiscardDesignation(node); //} public override void VisitDocumentationCommentTrivia(DocumentationCommentTriviaSyntax node) { Debug.Fail(node.ToString()); base.VisitDocumentationCommentTrivia(node); }