/// <summary> /// Get summary. /// </summary> /// <param name="theSyntaxNode">The syntax node to add the summary.</param> /// <returns>The syntax list.</returns> private static DocumentationCommentTriviaSyntax GetSummary(IndexerDeclarationSyntax theSyntaxNode) { var summaryStart = XmlElementStartTag(XmlName(Identifier(Constants.Summary))) .WithLessThanToken(Token(SyntaxKind.LessThanToken)) .WithGreaterThanToken(Token(SyntaxKind.GreaterThanToken)).NormalizeWhitespace(); var summaryEnd = XmlElementEndTag(XmlName(Identifier(Constants.Summary))).NormalizeWhitespace() .WithLessThanSlashToken(Token(SyntaxKind.LessThanSlashToken)) .WithGreaterThanToken(Token(SyntaxKind.GreaterThanToken)); var summaryComment = " The Indexer."; var summaryText = SingletonList <XmlNodeSyntax>( XmlText().NormalizeWhitespace() .WithTextTokens( TokenList( XmlTextNewLine(TriviaList(), Environment.NewLine, Environment.NewLine, TriviaList()).NormalizeWhitespace(), XmlTextLiteral( TriviaList(DocumentationCommentExterior("///")), summaryComment, summaryComment, TriviaList()).NormalizeWhitespace(), XmlTextNewLine(TriviaList(), Environment.NewLine, Environment.NewLine, TriviaList()).NormalizeWhitespace(), XmlTextLiteral( TriviaList(DocumentationCommentExterior("///")), " ", " ", TriviaList()))).NormalizeWhitespace()); var xmlComment = XmlText() .WithTextTokens( TokenList( XmlTextLiteral( TriviaList(DocumentationCommentExterior("///")), " ", " ", TriviaList()))).NormalizeWhitespace(); var newLine = XmlText().WithTextTokens(TokenList(XmlTextNewLine(TriviaList(), Environment.NewLine, Environment.NewLine, TriviaList()))).NormalizeWhitespace(); var summaryElement = XmlElement(summaryStart, summaryEnd).WithContent(summaryText); var list = List(new XmlNodeSyntax[] { xmlComment, summaryElement, newLine }); // Add exceptions comments var throws = theSyntaxNode.DescendantNodes().OfType <ThrowStatementSyntax>(); foreach (var syntax in throws) { if (syntax.ChildNodes().OfType <ObjectCreationExpressionSyntax>().Any()) { var identifier = syntax.DescendantNodes().OfType <IdentifierNameSyntax>().FirstOrDefault(); var argumentList = syntax.DescendantNodes().OfType <ArgumentListSyntax>().FirstOrDefault(); var parms = argumentList.DescendantTokens().Where(x => x.IsKind(SyntaxKind.StringLiteralToken)).ToList(); var parmText = string.Empty; if (parms.Any()) { parmText = parms.Last().ValueText; } list = list.AddRange( List( new XmlNodeSyntax[] { xmlComment, XmlElement( XmlElementStartTag(XmlName(Identifier("exception"))) .WithAttributes( SingletonList <XmlAttributeSyntax>( XmlNameAttribute( XmlName(Identifier(TriviaList(Space), "cref", TriviaList())), Token(SyntaxKind.DoubleQuoteToken), IdentifierName(identifier.Identifier.ValueText), Token(SyntaxKind.DoubleQuoteToken)))), XmlElementEndTag(XmlName(Identifier("exception")))) .WithContent( SingletonList <XmlNodeSyntax>( XmlText() .WithTextTokens( TokenList( XmlTextLiteral( TriviaList(), parmText, "comment", TriviaList()))))), newLine })); } } // Add parameter comments foreach (var parameter in theSyntaxNode.ParameterList.Parameters) { list = list.AddRange( List( new XmlNodeSyntax[] { xmlComment, XmlElement( XmlElementStartTag(XmlName(Identifier("param"))) .WithAttributes( SingletonList <XmlAttributeSyntax>( XmlNameAttribute( XmlName(Identifier(TriviaList(Space), "name", TriviaList())), Token(SyntaxKind.DoubleQuoteToken), IdentifierName(parameter.Identifier.ValueText), Token(SyntaxKind.DoubleQuoteToken)))), XmlElementEndTag(XmlName(Identifier("param")))) .WithContent( SingletonList <XmlNodeSyntax>( XmlText() .WithTextTokens( TokenList( XmlTextLiteral( TriviaList(), $"The index {parameter.Identifier.ValueText}.", "comment", TriviaList()))))), newLine })); } // Add returns comments list = list.AddRange( List( new XmlNodeSyntax[] { xmlComment, XmlElement(XmlElementStartTag(XmlName(Identifier("returns"))), XmlElementEndTag(XmlName(Identifier("returns")))) .WithContent( SingletonList <XmlNodeSyntax>( XmlText().WithTextTokens(TokenList(XmlTextLiteral(TriviaList(), $"One element of type {theSyntaxNode.Type}.", "comment", TriviaList()))))), newLine })); return(DocumentationCommentTrivia(SyntaxKind.SingleLineDocumentationCommentTrivia, list)); }