roslynator
roslynator copied to clipboard
RCS1111 should trigger when case returns directly or throws an exception
Product and Version Used: Roslynator 4.12
Steps to Reproduce:
private string Test(int i)
{
var result = string.Empty;
switch (i)
{
case 0:
result = i.ToString();
break;
case 1:
var s = i.ToString();
return s;
case 2:
return i.ToString();
default:
throw new Exception();
}
return result;
}
Actual Behavior:
private string Test(int i)
{
var result = string.Empty;
switch (i)
{
case 0:
{
result = i.ToString();
break;
}
case 1:
{
var s = i.ToString();
return s;
}
case 2:
return i.ToString();
default:
throw new Exception();
}
return result;
}
Expected Behavior:
private string Test(int i)
{
var result = string.Empty;
switch (i)
{
case 0:
{
result = i.ToString();
break;
}
case 1:
{
var s = i.ToString();
return s;
}
case 2:
{
return i.ToString();
}
default:
{
throw new Exception();
}
}
return result;
}
RCS1111 is called "Add braces to switch section with multiple statements". Why do you think is should trigger when there is a single statement?
Yes, you are right. The title says is all.
Anyway it would be nice to have another analyzer "Add braces to switch section" like it exists for if statements (IDE0011).