Convert 'switch' expression to 'switch' statement
Property | Value |
---|---|
Id | RR0214 |
Applicable Syntax | switch expression |
Syntax Span | switch 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