How to do it...

  1. Open Roslyn.sln in Visual Studio 2017
  2. Copy the method implementations for VisitSwitchOperator and RewriteSwitchOperator from the attached code sample source file CSharpCodeAnalysis\LocalRewriter_SwitchOperator.cs and paste them into source file %REPO_ROOT%\src\Compilers\CSharp\Portable\Lowering\LocalRewriter\LocalRewriter_SwitchOperator.cs.
  3. Build project csc.csproj to generate %REPO_ROOT%\Binaries\Debug\Exes\csc\csc.exe with our local changes.
  4. Create a new source file, say test.cs, with the following source code:
class Class{ public static void Main(string[] args) {  System.Console.WriteLine(args.Length ?: [0, 1, 2] : ["Zero", "One", "Two", "More than two"]); }}
  1. Compile this source file with locally built csc.exe and verify ...

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.