TypeName | ConvertToSwitchAnalyzer |
Check Id | CC0019 |
Category | Style |
Severity | Info |
Multiple ‘if’ and ‘else if’ on the same variable can be replaced with a ‘switch’ on the variable
Note: This diagnostic trigger for 3 or more ‘case’ statements
public async Task Foo(string s)
{
if (s == "A")
{
// ..
}
else if (s == "B")
{
// ..
}
else if (s == "C")
{
// ..
}
else
{
// ..
}
}
A code fix will be presented to you that will transform the code:
public async Task Foo(string s)
{
switch (s)
{
case "A":
break;
case "B":
break;
case "C":
break;
default:
break;
}
}
None
TBD