public void TestExpressionBody()
        {
            var accessorDeclarationSyntax = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                                            .WithExpressionBody(SyntaxFactory.ArrowExpressionClause(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)));

            Assert.Same(accessorDeclarationSyntax.ExpressionBody, AccessorDeclarationSyntaxExtensions.ExpressionBody(accessorDeclarationSyntax));
        }
Esempio n. 2
0
        public void TestWithExpressionBody()
        {
            var accessorDeclarationSyntax = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration);

            // With default value is allowed
            var accessorWithDefaultBody = AccessorDeclarationSyntaxExtensions.WithExpressionBody(accessorDeclarationSyntax, null);

            Assert.Null(AccessorDeclarationSyntaxExtensions.ExpressionBody(accessorWithDefaultBody));

            // Non-default throws an exception
            var expressionBody = SyntaxFactory.ArrowExpressionClause(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression));

            Assert.Throws <NotSupportedException>(() => AccessorDeclarationSyntaxExtensions.WithExpressionBody(accessorDeclarationSyntax, expressionBody));
        }
Esempio n. 3
0
        public void TestExpressionBody()
        {
            var accessorDeclarationSyntax = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration);

            Assert.Null(AccessorDeclarationSyntaxExtensions.ExpressionBody(accessorDeclarationSyntax));
        }