How to do it...

  1. Define the grammar for the new ternary operator ?:: in the C# language specification :
switch-expression: null-coalescing-expression null-coalescing-expression ?: bracketed-argument-list : bracketed-argument-list  bracketed-argument-list: [ argument-list ]
  1. Define the compile time semantics associated with the new operator and the switch expression in C# language specification:

A switch expression of the form expr ?: [label1, label2, ..., labeln] : [val1, val2, ..., valn, valn+1] has the following compile time semantics:

  • The governing type of the switch expression is established by the same set of rules as the governing type of a switch statement.
  • The first bracketed argument list [label1, label2, ..., labeln] must contain ...

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.