Example #1
0
        /// <summary>
        /// Get summary.
        /// </summary>
        /// <param name="theSyntaxNode">The syntax node to add the summary.</param>
        /// <returns>The syntax list.</returns>
        private static DocumentationCommentTriviaSyntax GetSummary(EventFieldDeclarationSyntax 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 = string.Empty;
            var variable       = theSyntaxNode.ChildNodes().OfType <VariableDeclarationSyntax>().FirstOrDefault();
            var field          = variable?.ChildNodes().OfType <VariableDeclaratorSyntax>().FirstOrDefault();

            if (field != null)
            {
                summaryComment = " " + Convert.Event(field.Identifier.ValueText, variable.Type.ToString());
            }

            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 });

            return(DocumentationCommentTrivia(SyntaxKind.SingleLineDocumentationCommentTrivia, list));
        }
        // 通常のイベント定義
        // public event EventHandler Clicked;
        public override void VisitEventFieldDeclaration(EventFieldDeclarationSyntax node)
        {
            var variable   = node.ChildNodes().FirstOrDefault(x => x is VariableDeclarationSyntax);
            var defineType = variable.ChildNodes().FirstOrDefault().ToString();
            var defineName = variable.ChildNodes().FirstOrDefault(x => x is VariableDeclaratorSyntax).ToString();

            var startLength     = node.Span.Start;
            var endLength       = node.Span.End;
            var parentNamespace = GetNamespace(DefineKinds.Event, startLength, endLength);

            UserDefinitions.Add(new UserDefinition
            {
                DefineKinds    = DefineKinds.Event,
                Namespace      = parentNamespace,
                DefineName     = defineName,
                DefineFullName = $"{parentNamespace}.{defineName}",
                ReturnType     = RemoveNamespace(defineType),
                SourceFile     = SourceFile,
                StartLength    = startLength,
                EndLength      = endLength,
            });

            base.VisitEventFieldDeclaration(node);
        }