Skip to main content

Convert 'switch' expression to 'switch' statement

PropertyValue
IdRR0214
Applicable Syntaxswitch expression
Syntax Spanswitch keyword
Enabled by Default

Usage

Example #1

before.cs
return dayOfWeek switch
{
DayOfWeek.Monday => 1,
DayOfWeek.Tuesday => 2,
DayOfWeek.Wednesday => 3,
DayOfWeek.Thursday => 4,
DayOfWeek.Friday => 5,
_ => throw new Exception(),
};
after.cs
switch (dayOfWeek)
{
case DayOfWeek.Monday:
return 1;
case DayOfWeek.Tuesday:
return 2;
case DayOfWeek.Wednesday:
return 3;
case DayOfWeek.Thursday:
return 4;
case DayOfWeek.Friday:
return 5;
default:
throw new Exception();
}

Configuration

roslynator_refactoring.convert_switch_expression_to_switch_statement.enabled = true|false