How it works...

In this recipe, we added basic binding/semantic analysis support for the switch operator (?:), which enabled us to compile and execute source code with this new operator. Note that this is not a comprehensive implementation of the binding phase for this operator, and requires further work such as enhanced error reporting. See the next section, There's more..., in this recipe for further details.

The C# binder is responsible for semantic analysis of the syntax tree produced by the parser. It transforms the syntax tree into a bound tree with BoundNodes, which is essentially an abstract syntax tree with rich semantic information associated with each node in the tree.

We first added a new BoundNode definition for the switch operator, ...

Get Roslyn Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.