Navigating syntax trees
Every node in the syntax tree implements
ITreeNode, as well as interfaces that better reflect the node's type and purpose, such as
ITreeNode interface includes members pertinent to navigating and processing the tree. These members are shown below (other members removed for brevity):
There are several ways of navigating the tree.
Manually walking the tree, using the interface members shown above. This is the least recommended, requiring boilerplate tree walking code that is time consuming and easy to get wrong.
TreeNodeExtensionshelper methods to manually walk the tree.
Use strongly typed navigation, using accessors on derived
ITreeNodeimplementations, and the strongly typed "navigator" classes.
Process the tree using the visitor pattern or the
IRecursiveElementProcessorset of classes.
Finding child or parent nodes of a specific type.