How to do it...

  1. Open Roslyn.sln in Visual Studio 2017.
  2. Open source file <%REPO_ROOT%>\src\Compilers\CSharp\Test\Syntax\Parsing\ExpressionParsingTests.cs.
  3. [Parsing Test] Add the following new unit test at the end of the source file:
[Fact]public void TestSwitchExpression(){ var text = @"expr ?: [0, 1, 2] : [""Zero"", ""One"", ""Two"", ""More than two""]"; var expr = SyntaxFactory.ParseExpression(text); Assert.NotNull(expr); Assert.Equal(SyntaxKind.SwitchExpression, expr.Kind()); Assert.Equal(text, expr. ToString()); Assert.Equal(0, expr.Errors().Length); var switchExpr = (SwitchExpressionSyntax)expr; Assert.NotNull(switchExpr.Expression); Assert.Equal("expr", switchExpr.Expression.ToString()); Assert.NotNull(switchExpr.QuestionColonToken); ...

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.