// assuming 'node' is already defined as a SyntaxNode instance var childNodes = node.ChildNodes(); foreach (var child in childNodes) { // do something with 'child' }
// assuming 'node' is already defined as a SyntaxNode instance var localDecls = node.ChildNodes().OfTypeThis code retrieves all immediate child nodes of a given syntax node that are of type LocalDeclarationStatementSyntax, using the OfType LINQ method to filter the list of child nodes. The Microsoft.CodeAnalysis package/library provides the necessary types and APIs for working with C# and VB.NET syntax trees in code analysis and transformation scenarios.(); foreach (var localDecl in localDecls) { // do something with 'localDecl' }