public void MultipleTypeParamsWithSameName()
        {
            var comment = DocumentationComment.FromXmlFragment(
                @"<typeparam name=""a"">This comment should be retained.</typeparam>
<typeparam name=""a"">This comment should not be retained.</typeparam>");

            Assert.Equal(1, comment.TypeParameterNames.Length);
            Assert.Equal("a", comment.TypeParameterNames[0]);
            Assert.Equal("This comment should be retained.", comment.GetTypeParameterText("a"));
        }
Beispiel #2
0
        private void TestFormat(string docCommentXmlFragment, string expectedCSharp, string expectedVB)
        {
            var docComment = DocumentationComment.FromXmlFragment(docCommentXmlFragment);

            var csharpFormattedComment = string.Join("\r\n", AbstractMetadataAsSourceService.DocCommentFormatter.Format(_csharpService, docComment));
            var vbFormattedComment     = string.Join("\r\n", AbstractMetadataAsSourceService.DocCommentFormatter.Format(_vbService, docComment));

            Assert.Equal(expectedCSharp, csharpFormattedComment);
            Assert.Equal(expectedVB, vbFormattedComment);
        }
Beispiel #3
0
        public void PreserveExceptionTypeOrdering()
        {
            var comment = DocumentationComment.FromXmlFragment(
                @"<exception cref=""z"">Z</exception>
<exception cref=""a"">A</exception>
<exception cref=""b"">B</exception>");

            Assert.Equal("z", comment.ExceptionTypes[0]);
            Assert.Equal("a", comment.ExceptionTypes[1]);
            Assert.Equal("b", comment.ExceptionTypes[2]);
        }
        public void ParseTagWithMultiLineComments()
        {
            var comment = DocumentationComment.FromXmlFragment(
                @"<summary>
Summary 1
Summary 2
</summary>"
                );

            Assert.Equal("Summary 1 Summary 2", comment.SummaryText);
        }
Beispiel #5
0
        public void UnknownTag()
        {
            var comment = DocumentationComment.FromXmlFragment(
                @"<summary>This is a summary.</summary>
<RandomTag>This is another summary.</RandomTag>
<param name=""a"">The param named 'a'</param>");

            Assert.Equal("This is a summary.", comment.SummaryText);
            Assert.Equal("a", comment.ParameterNames[0]);
            Assert.Equal("The param named 'a'", comment.GetParameterText("a"));
        }
Beispiel #6
0
        public void TextOutsideTag()
        {
            var comment = DocumentationComment.FromXmlFragment(
                @"<summary>This is a summary.</summary>
This is random top-level text.
<param name=""a"">The param named 'a'</param>");

            Assert.Equal("This is a summary.", comment.SummaryText);
            Assert.Equal("a", comment.ParameterNames[0]);
            Assert.Equal("The param named 'a'", comment.GetParameterText("a"));
        }
Beispiel #7
0
        public void PreserveTypeParameterNameOrdering()
        {
            var comment = DocumentationComment.FromXmlFragment(
                @"<typeparam name=""z"">Z</typeparam>
<typeparam name=""a"">A</typeparam>
<typeparam name=""b"">B</typeparam>");

            Assert.Equal("z", comment.TypeParameterNames[0]);
            Assert.Equal("a", comment.TypeParameterNames[1]);
            Assert.Equal("b", comment.TypeParameterNames[2]);
        }
Beispiel #8
0
        public void GetSymbolXmlDocComments()
        {
            TestCode testCode = new TestCode(@"
/// <summary>
/// This is a test class!
/// </summary>
class C$lass1 { }");
            Symbol   symbol   = testCode.SemanticModel.GetDeclaredSymbol((TypeDeclarationSyntax)testCode.SyntaxNode);

            DocumentationComment docComment = symbol.GetDocumentationComment();

            Assert.AreEqual("This is a test class!", docComment.SummaryTextOpt);
        }
        private ICompletionData CompletionData(IEntity entity)
        {
            ICompletionData completionData = null;

            if (entity.Documentation != null)
            {
                completionData = new CompletionData(_signature, _completionText,
                                                    _signature + Environment.NewLine +
                                                    DocumentationConverter.ConvertDocumentation(entity.Documentation));
            }
            else
            {
                IDocumentationProvider docProvider = null;
                if (entity.ParentAssembly.AssemblyName != null)
                {
                    docProvider =
                        XmlDocumentationProviderFactory.Get(entity.ParentAssembly.AssemblyName);
                }
                var ambience = new CSharpAmbience
                {
                    ConversionFlags = ConversionFlags.ShowParameterList |
                                      ConversionFlags.ShowParameterNames |
                                      ConversionFlags.ShowReturnType |
                                      ConversionFlags.ShowBody |
                                      ConversionFlags.ShowTypeParameterList
                };

                var documentationSignature = ambience.ConvertEntity(entity);
                if (docProvider != null)
                {
                    DocumentationComment documentationComment = docProvider.GetDocumentation(entity);
                    if (documentationComment != null)
                    {
                        var documentation = documentationSignature + Environment.NewLine +
                                            DocumentationConverter.ConvertDocumentation(
                            documentationComment.Xml.Text);
                        completionData = new CompletionData(_signature, _completionText, documentation);
                    }
                    else
                    {
                        completionData = new CompletionData(_signature, _completionText, documentationSignature);
                    }
                }
                else
                {
                    completionData = new CompletionData(_signature, _completionText, documentationSignature);
                }
            }
            return(completionData);
        }
Beispiel #10
0
        private Dictionary <string, DocumentationComment> GetMembers()
        {
            if (_xmlFilePathToMembersToDocumentationComments.ContainsKey(_xmlFilePath))
            {
                return(_xmlFilePathToMembersToDocumentationComments[_xmlFilePath]);
            }

            var membersToDocumentationComments = new Dictionary <string, DocumentationComment>();

            //Allow loading just one file at a time
            lock (lockObj)
            {
                //Check again
                if (_xmlFilePathToMembersToDocumentationComments.ContainsKey(_xmlFilePath))
                {
                    return(_xmlFilePathToMembersToDocumentationComments[_xmlFilePath]);
                }

                var xmlDocument = new XmlDocument();
                xmlDocument.Load(_xmlFilePath);

                XmlNode node = xmlDocument.SelectSingleNode("//members");

                if (node != null && node.HasChildNodes)
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        if (childNode.Name != "member")
                        {
                            continue;
                        }

                        var attribute = childNode.Attributes["name"];
                        if (attribute == null)
                        {
                            continue;
                        }

                        string memberId = attribute.Value;
                        DocumentationComment docComment = DocumentationComment.FromXmlFragment(childNode.InnerXml);

                        membersToDocumentationComments[memberId] = docComment;
                    }
                }

                _xmlFilePathToMembersToDocumentationComments[_xmlFilePath] = membersToDocumentationComments;
            }

            return(membersToDocumentationComments);
        }
Beispiel #11
0
        private static AutoCompleteItemParameter[] GetSymbolParameters(ReadOnlyArray <IParameterSymbol> paramsArray,
                                                                       DocumentationComment docComment,
                                                                       bool includeThis = false)
        {
            var result = paramsArray.Where(p => !includeThis || !p.IsThis)
                         .Select(p => new AutoCompleteItemParameter()
            {
                Name        = p.Name,
                Type        = GetparameterTypeName(p.Type),
                Description = docComment != null ? docComment.GetParameterText(p.Name) : null
            })
                         .ToArray();

            return(result.Length == 0 ? null : result);
        }
Beispiel #12
0
 static string generate(DocumentationComment dc)
 {
     try
     {
         XmlDocument d = new XmlDocument();
         d.LoadXml("<doc>" + dc.Text + "</doc>");
         StringBuilder sb = new StringBuilder();
         if (d.SelectNodes("/doc/param").Count > 0)
         {
             sb.Append(dc.Ident + "(");
             //foreach (XmlNode n in d.SelectNodes("/doc/param"))
             for (int i = 0; i < d.SelectNodes("/doc/param").Count; i++)
             {
                 sb.Append(d.SelectNodes("/doc/param")[i].Attributes["name"].InnerText.Trim());
                 if (i != d.SelectNodes("/doc/param").Count - 1)
                 {
                     sb.Append(", ");
                 }
             }
             sb.Append(")");
             sb.AppendLine();
             sb.AppendLine();
         }
         sb.AppendLine(d.SelectSingleNode("/doc/summary").InnerText.Trim().Replace("<br />", "\r\n").Replace("<br>", "\r\n").Replace("<br/>", "\r\n"));
         foreach (XmlNode n in d.SelectNodes("/doc/param"))
         {
             sb.Append(n.Attributes["name"].InnerText.Trim());
             sb.Append(": ");
             sb.AppendLine(n.InnerText.Trim());
         }
         foreach (XmlNode n in d.SelectNodes("/doc/returns"))
         {
             sb.AppendLine("Returns: " + n.InnerText.Trim());
         }
         if (sb.Length >= 2)
         {
             sb.Remove(sb.Length - 2, 2); // remove last \n
         }
         return(sb.ToString());
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.ToString());
         LoggingService.Error(dc.Text, ex);
     }
     return(dc.Text);
 }
        public void TrimEachLine()
        {
            var multiLineText =
                @"



Hello
     World     .        
+
.......




123

                                           1";

            var fullXml =
                $@"<summary>{multiLineText}</summary>
                  <returns>{multiLineText}</returns>
                  <value>{multiLineText}</value>
                  <example>{multiLineText}</example>
                  <param name=""goo"">{multiLineText}</param>
                  <typeparam name=""T"">{multiLineText}</typeparam>
                  <remarks>{multiLineText}</remarks>";

            var expected =
                @"Hello
World     .
+
.......
123
1";

            var comment = DocumentationComment.FromXmlFragment(fullXml);

            Assert.Equal(expected, comment.SummaryText);
            Assert.Equal(expected, comment.ReturnsText);
            Assert.Equal(expected, comment.ValueText);
            Assert.Equal(expected, comment.ExampleText);
            Assert.Equal(expected, comment.GetParameterText("goo"));
            Assert.Equal(expected, comment.GetTypeParameterText("T"));
            Assert.Equal(expected, comment.RemarksText);
        }
Beispiel #14
0
        public void MultipleExceptionsWithSameName()
        {
            var comment = DocumentationComment.FromXmlFragment(
                @"<exception cref=""A"">First A description</exception>
<exception cref=""B"">First B description</exception>
<exception cref=""A"">Second A description</exception>
<exception cref=""B"">Second B description</exception>");

            Assert.Equal(2, comment.ExceptionTypes.Length);
            Assert.Equal("A", comment.ExceptionTypes[0]);
            Assert.Equal("B", comment.ExceptionTypes[1]);
            Assert.Equal(2, comment.GetExceptionTexts("A").Length);
            Assert.Equal("First A description", comment.GetExceptionTexts("A")[0]);
            Assert.Equal("Second A description", comment.GetExceptionTexts("A")[1]);
            Assert.Equal(2, comment.GetExceptionTexts("B").Length);
            Assert.Equal("First B description", comment.GetExceptionTexts("B")[0]);
            Assert.Equal("Second B description", comment.GetExceptionTexts("B")[1]);
        }
Beispiel #15
0
        private static T CreateDocumentData <T>(ISymbol symbol, string rootName, string id) where T : DocumentDataObject, new()
        {
            var data = new T();

            data.Name        = symbol.Name;
            data.DisplayName = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);

            if (!string.IsNullOrEmpty(id))
            {
                data.SupportedProjects.Add(id);
            }

            if (rootName != null)
            {
                data.DisplayName = data.DisplayName.Replace(rootName, string.Empty).Substring(1);
            }

            data.AccessModifier = Helper.RetrieveAccessModifier(symbol.DeclaredAccessibility);
            data.FullName       = GetFullName(symbol, rootName);

            DocumentationComment comment = null;

            try
            {
                var commentXml = symbol.GetDocumentationCommentXml();
                comment = DocumentationComment.FromXmlFragment(commentXml);
            }
            catch
            {
            }

            if (comment != null)
            {
                // TODO: Parse XML
                data.Summary           = comment.SummaryText;
                data.ReturnDescription = comment.ReturnsText;
            }

            return(data);
        }
        private static DocumentedType CoallateTypeWithDocumentation(INamedTypeSymbol type)
        {
            var fields     = ImmutableArray.CreateBuilder <DocumentedSymbol <IFieldSymbol> >();
            var methods    = ImmutableArray.CreateBuilder <DocumentedSymbol <IMethodSymbol> >();
            var properties = ImmutableArray.CreateBuilder <DocumentedSymbol <IPropertySymbol> >();
            var events     = ImmutableArray.CreateBuilder <DocumentedSymbol <IEventSymbol> >();

            foreach (var member in type.GetMembers())
            {
                var xml = DocumentationComment.Parse(member.GetDocumentationCommentXml());

                switch (member)
                {
                case IFieldSymbol field:
                    fields.Add(new DocumentedSymbol <IFieldSymbol>(field, xml));
                    break;

                case IMethodSymbol method:
                    methods.Add(new DocumentedSymbol <IMethodSymbol>(method, xml));
                    break;

                case IPropertySymbol prop:
                    properties.Add(new DocumentedSymbol <IPropertySymbol>(prop, xml));
                    break;

                case IEventSymbol @event:
                    events.Add(new DocumentedSymbol <IEventSymbol>(@event, xml));
                    break;
                }
            }

            return(new DocumentedType(type, DocumentationComment.Parse(type.GetDocumentationCommentXml()))
            {
                Fields = fields.ToImmutable(),
                Methods = methods.ToImmutable(),
                Properties = properties.ToImmutable(),
                Events = events.ToImmutable()
            });
        }
Beispiel #17
0
        public void ParseFullTag()
        {
            var comment = DocumentationComment.FromXmlFragment(
                @"<summary>Hello, world!</summary>
                  <returns>42.</returns>
                  <example>goo.Bar();</example>
                  <param name=""goo"">A goo.</param>
                  <typeparam name=""T"">A type.</typeparam>
                  <exception cref=""System.Exception"">An exception</exception>
                  <remarks>A remark</remarks>");

            Assert.Equal("Hello, world!", comment.SummaryText);
            Assert.Equal("42.", comment.ReturnsText);
            Assert.Equal("goo.Bar();", comment.ExampleText);
            Assert.Equal("goo", comment.ParameterNames[0]);
            Assert.Equal("A goo.", comment.GetParameterText("goo"));
            Assert.Equal("T", comment.TypeParameterNames[0]);
            Assert.Equal("A type.", comment.GetTypeParameterText("T"));
            Assert.Equal("System.Exception", comment.ExceptionTypes[0]);
            Assert.Equal("An exception", comment.GetExceptionTexts("System.Exception")[0]);
            Assert.Equal("A remark", comment.RemarksText);
        }
Beispiel #18
0
            private IEnumerable <SyntaxTrivia> ConvertDocCommentToRegularComment(DocumentationCommentTriviaSyntax structuredTrivia)
            {
                var xmlFragment = DocumentationCommentUtilities.ExtractXMLFragment(structuredTrivia.ToFullString());

                var docComment = DocumentationComment.FromXmlFragment(xmlFragment);

                var commentLines = AbstractMetadataAsSourceService.DocCommentFormatter.Format(_formattingService, docComment);

                foreach (var line in commentLines)
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        yield return(SyntaxFactory.Comment("// " + line));
                    }
                    else
                    {
                        yield return(SyntaxFactory.Comment("//"));
                    }

                    yield return(SyntaxFactory.ElasticCarriageReturnLineFeed);
                }
            }
        public string GetDocumentation(IProject project, IEntity entity)
        {
            string idString = entity.GetIdString();
            string result;

            if (_documentationCache.TryGetValue(idString, out result))
            {
                return(result);
            }

            DocumentationComment documentationComment = null;

            if (entity.Documentation != null)
            {
                // Documentation from source code
                documentationComment = entity.Documentation;
            }
            else
            {
                if (entity.ParentAssembly.AssemblyName != null)
                {
                    IDocumentationProvider docProvider =
                        XmlDocumentationProviderFactory.Get(project, entity.ParentAssembly.AssemblyName);

                    if (docProvider != null)
                    {
                        documentationComment = docProvider.GetDocumentation(entity);
                    }
                }
            }

            result = documentationComment != null
                ? DocumentationConverter.ConvertDocumentation(documentationComment.Xml.Text)
                : null;

            _documentationCache.TryAdd(idString, result);
            return(result);
        }
Beispiel #20
0
        public void ParseFullTagEmptyValues()
        {
            var comment = DocumentationComment.FromXmlFragment(
                @"<summary></summary>
                  <returns></returns>
                  <value></value>
                  <example></example>
                  <param name=""goo""></param>
                  <typeparam name=""T""></typeparam>
                  <exception cref=""System.Exception""></exception>
                  <remarks></remarks>");

            Assert.Equal(string.Empty, comment.SummaryText);
            Assert.Equal(string.Empty, comment.ReturnsText);
            Assert.Equal(string.Empty, comment.ValueText);
            Assert.Equal(string.Empty, comment.ExampleText);
            Assert.Equal("goo", comment.ParameterNames[0]);
            Assert.Equal(string.Empty, comment.GetParameterText("goo"));
            Assert.Equal("T", comment.TypeParameterNames[0]);
            Assert.Equal(string.Empty, comment.GetTypeParameterText("T"));
            Assert.Equal("System.Exception", comment.ExceptionTypes[0]);
            Assert.Equal(string.Empty, comment.GetExceptionTexts("System.Exception")[0]);
            Assert.Equal(string.Empty, comment.RemarksText);
        }
Beispiel #21
0
        public void NoExceptionWithGivenName()
        {
            var comment = DocumentationComment.FromXmlFragment(@"<summary>This is a summary</summary>");

            Assert.Equal(0, comment.GetExceptionTexts("A").Length);
        }
Beispiel #22
0
 public static DocumentationComment GetStructuredDocumentation(string xmlDocumentation, string lineEnding)
 {
     return(DocumentationComment.From(xmlDocumentation, lineEnding));
 }
Beispiel #23
0
        public DocumentationComment GetDocumentation(IEntity entity)
        {
            if (entity == null)
            {
                throw new System.ArgumentNullException("entity");
            }

            // If we had an exception while getting the help xml the monodoc help provider
            // shouldn't try it again. A corrupt .zip file could cause long tooltip delays otherwise.
            if (hadError)
            {
                return(null);
            }
            var idString = entity.GetIdString();
            DocumentationComment result;

            if (commentCache.TryGetValue(idString, out result))
            {
                return(result);
            }
            XmlDocument doc = null;

            try
            {
                var helpTree = MonoDevelop.Projects.HelpService.HelpTree;
                if (helpTree == null)
                {
                    return(null);
                }
                if (entity.EntityType == EntityType.TypeDefinition)
                {
#pragma warning disable 612,618
                    doc = helpTree.GetHelpXml(idString);
#pragma warning restore 612,618
                }
                else
                {
                    var parentId = entity.DeclaringTypeDefinition.GetIdString();

#pragma warning disable 612,618
                    doc = helpTree.GetHelpXml(parentId);
#pragma warning restore 612,618
                    if (doc == null)
                    {
                        return(null);
                    }
                    XmlNode node = SelectNode(doc, entity);

                    if (node != null)
                    {
                        return(commentCache[idString] = new DocumentationComment(node.OuterXml, new SimpleTypeResolveContext(entity)));
                    }
                    return(null);
                    //					var node = doc.SelectSingleNode ("/Type/Members/Member")
                    //					return new DocumentationComment (doc.OuterXml, new SimpleTypeResolveContext (entity));
                }
            }
            catch (Exception e)
            {
                hadError = true;
                //LoggingService.LogError("Error while reading monodoc file.", e);
                Console.WriteLine("Error while reading monodoc file." + e);
            }
            if (doc == null)
            {
                commentCache[idString] = null;
                return(null);
            }
            return(commentCache[idString] = new DocumentationComment(doc.OuterXml, new SimpleTypeResolveContext(entity)));
        }
 public VSTypeScriptDocumentationCommentWrapper(DocumentationComment underlyingObject)
 => _underlyingObject = underlyingObject;
 public static VSTypeScriptDocumentationCommentWrapper FromXmlFragment(string xml)
 => new VSTypeScriptDocumentationCommentWrapper(DocumentationComment.FromXmlFragment(xml));
Beispiel #26
0
        public DocumentationComment GetDocumentation(IEntity entity)
        {
            if (entity == null)
            {
                throw new System.ArgumentNullException("entity");
            }

            var idString = entity.GetIdString();
            DocumentationComment result;

            if (commentCache.TryGetValue(idString, out result))
            {
                return(result);
            }
            XmlDocument doc = null;

            try
            {
                var helpTree = MonoDevelop.Projects.HelpService.HelpTree;
                if (helpTree == null)
                {
                    return(null);
                }
                if (entity.EntityType == EntityType.TypeDefinition)
                {
#pragma warning disable 612,618
                    doc = helpTree.GetHelpXml(idString);
#pragma warning restore 612,618
                }
                else
                {
                    var parentId = entity.DeclaringTypeDefinition.GetIdString();

#pragma warning disable 612,618
                    doc = helpTree.GetHelpXml(parentId);
#pragma warning restore 612,618
                    if (doc == null)
                    {
                        commentCache[idString] = null;
                        return(null);
                    }
                    XmlNode node = SelectNode(doc, entity);

                    if (node != null)
                    {
                        return(commentCache[idString] = new DocumentationComment(node.OuterXml, new SimpleTypeResolveContext(entity)));
                    }
                    commentCache[idString] = null;
                    return(null);
                    //					var node = doc.SelectSingleNode ("/Type/Members/Member")
                    //					return new DocumentationComment (doc.OuterXml, new SimpleTypeResolveContext (entity));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while reading monodoc file." + e);
            }
            if (doc == null)
            {
                commentCache[idString] = null;
                return(null);
            }
            return(commentCache[idString] = new DocumentationComment(doc.OuterXml, new SimpleTypeResolveContext(entity)));
        }
		private static AutoCompleteItemParameter[] GetSymbolParameters(ReadOnlyArray<IParameterSymbol> paramsArray,
		                                                               DocumentationComment docComment,
		                                                               bool includeThis = false)
		{
			var result = paramsArray.Where(p => !includeThis || !p.IsThis)
			                        .Select(p => new AutoCompleteItemParameter()
				                        {
					                        Name = p.Name,
					                        Type = GetparameterTypeName(p.Type),
					                        Description = docComment != null ? docComment.GetParameterText(p.Name) : null
				                        })
			                        .ToArray();
			return result.Length == 0 ? null : result;
		}
Beispiel #28
0
        public void ParseTagWithMultipleSummaries()
        {
            var comment = DocumentationComment.FromXmlFragment("<summary>Summary 1</summary><summary>Summary 2</summary>");

            Assert.Equal("Summary 1", comment.SummaryText);
        }
Beispiel #29
0
            internal static ImmutableArray <string> Format(IDocumentationCommentFormattingService docCommentFormattingService, DocumentationComment docComment)
            {
                var formattedCommentLinesBuilder = ArrayBuilder <string> .GetInstance();

                var lineBuilder = new StringBuilder();

                var formattedSummaryText = docCommentFormattingService.Format(docComment.SummaryText);

                if (!string.IsNullOrWhiteSpace(formattedSummaryText))
                {
                    formattedCommentLinesBuilder.Add(s_summaryHeader);
                    formattedCommentLinesBuilder.AddRange(CreateWrappedTextFromRawText(formattedSummaryText));
                }

                var parameterNames = docComment.ParameterNames;

                if (parameterNames.Length > 0)
                {
                    formattedCommentLinesBuilder.Add(string.Empty);
                    formattedCommentLinesBuilder.Add(s_paramHeader);

                    for (var i = 0; i < parameterNames.Length; i++)
                    {
                        if (i != 0)
                        {
                            formattedCommentLinesBuilder.Add(string.Empty);
                        }

                        lineBuilder.Clear();
                        lineBuilder.Append(' ', s_indentSize);
                        lineBuilder.Append(string.Format(s_labelFormat, parameterNames[i]));
                        formattedCommentLinesBuilder.Add(lineBuilder.ToString());

                        var rawParameterText       = docComment.GetParameterText(parameterNames[i]);
                        var formattedParameterText = docCommentFormattingService.Format(rawParameterText);
                        if (!string.IsNullOrWhiteSpace(formattedParameterText))
                        {
                            formattedCommentLinesBuilder.AddRange(CreateWrappedTextFromRawText(formattedParameterText));
                        }
                    }
                }

                var typeParameterNames = docComment.TypeParameterNames;

                if (typeParameterNames.Length > 0)
                {
                    formattedCommentLinesBuilder.Add(string.Empty);
                    formattedCommentLinesBuilder.Add(s_typeParameterHeader);

                    for (var i = 0; i < typeParameterNames.Length; i++)
                    {
                        if (i != 0)
                        {
                            formattedCommentLinesBuilder.Add(string.Empty);
                        }

                        lineBuilder.Clear();
                        lineBuilder.Append(' ', s_indentSize);
                        lineBuilder.Append(string.Format(s_labelFormat, typeParameterNames[i]));
                        formattedCommentLinesBuilder.Add(lineBuilder.ToString());

                        var rawTypeParameterText       = docComment.GetTypeParameterText(typeParameterNames[i]);
                        var formattedTypeParameterText = docCommentFormattingService.Format(rawTypeParameterText);
                        if (!string.IsNullOrWhiteSpace(formattedTypeParameterText))
                        {
                            formattedCommentLinesBuilder.AddRange(CreateWrappedTextFromRawText(formattedTypeParameterText));
                        }
                    }
                }

                var formattedReturnsText = docCommentFormattingService.Format(docComment.ReturnsText);

                if (!string.IsNullOrWhiteSpace(formattedReturnsText))
                {
                    formattedCommentLinesBuilder.Add(string.Empty);
                    formattedCommentLinesBuilder.Add(s_returnsHeader);
                    formattedCommentLinesBuilder.AddRange(CreateWrappedTextFromRawText(formattedReturnsText));
                }

                var formattedValueText = docCommentFormattingService.Format(docComment.ValueText);

                if (!string.IsNullOrWhiteSpace(formattedValueText))
                {
                    formattedCommentLinesBuilder.Add(string.Empty);
                    formattedCommentLinesBuilder.Add(s_valueHeader);
                    formattedCommentLinesBuilder.AddRange(CreateWrappedTextFromRawText(formattedValueText));
                }

                var exceptionTypes = docComment.ExceptionTypes;

                if (exceptionTypes.Length > 0)
                {
                    formattedCommentLinesBuilder.Add(string.Empty);
                    formattedCommentLinesBuilder.Add(s_exceptionsHeader);

                    for (var i = 0; i < exceptionTypes.Length; i++)
                    {
                        var rawExceptionTexts = docComment.GetExceptionTexts(exceptionTypes[i]);

                        for (var j = 0; j < rawExceptionTexts.Length; j++)
                        {
                            if (i != 0 || j != 0)
                            {
                                formattedCommentLinesBuilder.Add(string.Empty);
                            }

                            lineBuilder.Clear();
                            lineBuilder.Append(' ', s_indentSize);
                            lineBuilder.Append(string.Format(s_labelFormat, exceptionTypes[i]));
                            formattedCommentLinesBuilder.Add(lineBuilder.ToString());

                            var formattedExceptionText = docCommentFormattingService.Format(rawExceptionTexts[j]);
                            if (!string.IsNullOrWhiteSpace(formattedExceptionText))
                            {
                                formattedCommentLinesBuilder.AddRange(CreateWrappedTextFromRawText(formattedExceptionText));
                            }
                        }
                    }
                }

                var formattedRemarksText = docCommentFormattingService.Format(docComment.RemarksText);

                if (!string.IsNullOrWhiteSpace(formattedRemarksText))
                {
                    formattedCommentLinesBuilder.Add(string.Empty);
                    formattedCommentLinesBuilder.Add(s_remarksHeader);
                    formattedCommentLinesBuilder.AddRange(CreateWrappedTextFromRawText(formattedRemarksText));
                }

                // Eliminate any blank lines at the beginning.
                while (formattedCommentLinesBuilder.Count > 0 &&
                       formattedCommentLinesBuilder[0].Length == 0)
                {
                    formattedCommentLinesBuilder.RemoveAt(0);
                }

                // Eliminate any blank lines at the end.
                while (formattedCommentLinesBuilder.Count > 0 &&
                       formattedCommentLinesBuilder[^ 1].Length == 0)
                {
                    formattedCommentLinesBuilder.RemoveAt(formattedCommentLinesBuilder.Count - 1);
                }

                return(formattedCommentLinesBuilder.ToImmutableAndFree());
            }
Beispiel #30
0
        public static DocumentationComment GetDocumentationComment(this ISymbol symbol, CultureInfo preferredCulture = null, bool expandIncludes = false, CancellationToken cancellationToken = default(CancellationToken))
        {
            string xmlText = symbol.GetDocumentationCommentXml(preferredCulture, expandIncludes, cancellationToken);

            return(string.IsNullOrEmpty(xmlText) ? DocumentationComment.Empty : DocumentationComment.FromXmlFragment(xmlText));
        }
        static XmlDocumentationElement Create(DocumentationComment documentationComment, IEntity declaringEntity)
        {
            var doc = new AXmlParser().Parse(documentationComment.Xml);

            return(new XmlDocumentationElement(doc, declaringEntity, documentationComment.ResolveCref));
        }