0

(Note: This, 7-year-old reply refers to a JetBrains request for this feature which was subsequently marked as "done" in 2017. But they've rearranged their Options dialog since then and I cannot find the equivalent. So I am posting again)

I'm typing a switch statement in C#. When the case statements are short, I generally want to line them up in columns because it makes the code easier to grasp at a glance. So for example, I might want it look like this

switch (XyLengthUnit)
{
case LengthUnit.CM: _precision = 6; break;
case LengthUnit.MM: _precision = 3; break;
}

And mostly it works. But every time I get to the end of a line and type the semicolon, Resharper insists on moving the break down to the next line

switch (XyLengthUnit)
{
case LengthUnit.CM: _precision = 6; break;
case LengthUnit.MM: _precision = 3; 
    break;    
}

So I have to hit backspace to fix it. Every time.

I am sure that it is Resharper doing this because when I disable it, the behavior stops and my 'break' statement remains on the same line.

I've gone through every single setting under Resharpers Options >> Code Editing >> C# >> Formatting Style >> Tabs, Indents, Alignment Nothing there seems to change this. I found a few settings under "Line Breaks and Wrapping that seemed appropriate (and related the previously mentioned feature request) but they did not change the behavior

enter image description here

(This is how I have the settings now but I've monkeyed with them extensively. They do not seem to change anything. As soon as I hit semicolon, the break gets moved)

I know that many Resharper settings have "hard breaks" at a certain column and all that but I generally set those to really high numbers (e.g. column 150).

Is there a setting for it that I am missing? Is it possible to make Resharper align things like this?

Joe
  • 5,394
  • 3
  • 23
  • 54
  • Look at [switch expression](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/switch-expression) which has nothing to do with Resharper other than when using a switch statement if possible Resharper will provide an option to change to a switch expression. – Karen Payne Oct 23 '22 at 11:29
  • Thank you for answering. However I am familiar with the switch expression. But I do have cases where I need to use a regular switch statement. The example I wrote was just a simplified version of what I want to do. – Joe Oct 23 '22 at 17:35

1 Answers1

0

No, it's not possible right now. The "Place simple case statements" takes effect when there's only one statement inside a case section, where's in your case there are two including the break; statement.

Igor Akhmetov
  • 1,807
  • 13
  • 15