Skip to main content

Convert 'if' to 'switch'

PropertyValue
IdRR0133
Applicable Syntaxif statement
Syntax Spantop if keyword or selected if statement
Enabled by Default

Usage

Example #1

before.cs
var ch = stringReader.Read();

if (ch == 10 || ch == 13)
{
return;
}
else
{
stringBuilder.Append(ch);
}
after.cs
var ch = stringReader.Read();

switch (ch)
{
case 10:
case 13:
{
return;
}

default:
{
stringBuilder.Append(ch);
break;
}
}

Configuration

roslynator_refactoring.convert_if_to_switch.enabled = true|false