Exemplo n.º 1
0
        private static PropertyDeclarationSyntax CreateAutoProperty(PropertyDeclarationSyntax property, EqualsValueClauseSyntax initializer)
        {
            AccessorListSyntax accessorList = CreateAccessorList(property);

            accessorList = WhitespaceOrEndOfLineRemover.RemoveFrom(accessorList);

            if (initializer != null)
            {
                accessorList = accessorList
                               .WithCloseBraceToken(accessorList.CloseBraceToken.WithoutTrailingTrivia());
            }

            PropertyDeclarationSyntax newProperty = property
                                                    .WithIdentifier(property.Identifier.WithTrailingSpace())
                                                    .WithExpressionBody(null)
                                                    .WithAccessorList(accessorList);

            if (initializer != null)
            {
                newProperty = newProperty
                              .WithInitializer(initializer)
                              .WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
            }
            else
            {
                newProperty = newProperty
                              .WithSemicolonToken(Token(SyntaxKind.None));
            }

            return(newProperty
                   .WithTriviaFrom(property)
                   .WithAdditionalAnnotations(Formatter.Annotation));
        }