// cast the first child node of a syntax tree to a VariableDeclarationSyntax var variableDeclaration = root.ChildNodes().First().As(); if (variableDeclaration != null) { // process the variable declaration node }
// check if a syntax node is a StatementSyntax object if (node is StatementSyntax statement) { // process the statement node }In this example, we are using the C# 7 pattern matching feature to cast a `SyntaxNode` object to a `StatementSyntax` object. The `SyntaxNode.As` method is part of the `Microsoft.CodeAnalysis` package library.