Skip to main content

Convert ?: to if-else

PropertyValue
IdRR0120
Applicable Syntax?: operator that is part of local declaration, assignment or (yield) return statement
Enabled by Default

Usage

Example #1

before.cs
string s = (x) ? "a" : "b";
after.cs
string s;
if (x)
{
s = "a";
}
else
{
s = "b";
}

Example #2

before.cs
string s = (x) ? "a" : (y) ? "b" : "c";
after.cs
string s;
if (x)
{
s = "a";
}
else if (y)
{
s = "b";
}
else
{
s = "c";
}

Configuration

roslynator_refactoring.convert_conditional_expression_to_if_else.enabled = true|false