Ejemplo n.º 1
0
        public PropertyDeclarationSyntax GetPropertyDeclarationSyntax(string propertyName, SyntaxKind syntaxKind)
        {
            var typeSyntax = ListPropertyDeclarationSyntaxGenerator.GetTypeSyntax(propertyName, syntaxKind);

            return(SyntaxFactory.PropertyDeclaration(typeSyntax,
                                                     SyntaxFactory.Identifier(
                                                         SyntaxFactory.TriviaList(),
                                                         propertyName,
                                                         SyntaxFactory.TriviaList(
                                                             SyntaxFactory.Space)))
                   .WithModifiers(
                       SyntaxFactory.TokenList(
                           SyntaxFactory.Token(
                               SyntaxFactory.TriviaList(),
                               SyntaxKind.PublicKeyword,
                               SyntaxFactory.TriviaList(
                                   SyntaxFactory.Space))))
                   .WithAccessorList(
                       SyntaxFactory.AccessorList(
                           SyntaxFactory.List <AccessorDeclarationSyntax>(
                               new AccessorDeclarationSyntax[]
            {
                SyntaxFactory.AccessorDeclaration(
                    SyntaxKind.GetAccessorDeclaration)
                .WithSemicolonToken(
                    SyntaxFactory.Token(SyntaxKind.SemicolonToken))
            }))
                       .WithCloseBraceToken(
                           SyntaxFactory.Token(
                               SyntaxFactory.TriviaList(),
                               SyntaxKind.CloseBraceToken,
                               SyntaxFactory.TriviaList(
                                   new[] { SyntaxFactory.Space, SyntaxFactory.LineFeed })))));
        }
        public PropertyDeclarationSyntax GetPropertyDeclarationSyntax(string propertyName, SyntaxKind underlyingSyntaxKind)
        {
            var typeSyntax = ListPropertyDeclarationSyntaxGenerator.GetTypeSyntax(propertyName, underlyingSyntaxKind);

            return(SyntaxFactory.PropertyDeclaration(
                       SyntaxFactory.GenericName(
                           SyntaxFactory.Identifier("List"))
                       .WithTypeArgumentList(
                           SyntaxFactory.TypeArgumentList(
                               SyntaxFactory.SingletonSeparatedList <TypeSyntax>(typeSyntax))),
                       SyntaxFactory.Identifier(propertyName))
                   .WithModifiers(
                       SyntaxFactory.TokenList(
                           SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
                   .WithAccessorList(
                       SyntaxFactory.AccessorList(
                           SyntaxFactory.List <AccessorDeclarationSyntax>(
                               new AccessorDeclarationSyntax[] {
                SyntaxFactory.AccessorDeclaration(
                    SyntaxKind.GetAccessorDeclaration)
                .WithSemicolonToken(
                    SyntaxFactory.Token(SyntaxKind.SemicolonToken))
            }))));
        }