Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ReSharper providing strange formatting with string interpolation?

Tags:

c#

.net

resharper

ReSharper's formatting keeps placing string interpolations on different lines, such as:

$" whatever = {somethingelse}"

becomes:

$" whatever={
         somethingelse
      }"

Any idea which option this is?

like image 442
Alan Ciantar Avatar asked Sep 17 '15 11:09

Alan Ciantar


People also ask

Why do we use string interpolation in C#?

Beginning with C# 10, you can use string interpolation to initialize a constant string. All expressions used for placeholders must be constant strings. In other words, every interpolation expression must be a string, and it must be a compile time constant.

What is interpolation C #?

C# string interpolation is used to format and manipulate strings. This feature was introduced in C# 6. Using string interpolation, we can use objects and expressions as a part of the string interpolation operation. C# string interpolation is a method of concatenating, formatting and manipulating strings.


1 Answers

"Wrap object and collection initializer" is the setting you're after. Set it to chop if long and then if it's still wrapping incorrectly you can modify the "Right Margin (columns)" number to a much larger value and it will stop the behavior. Though by expanding the columns resharper will stop wrapping anything with fewer characters on the line than the value you set so it may make other reformatting perform in an undesirable way.

Resharper object initializer options

Resharper Column Options

like image 153
P. Roe Avatar answered Oct 21 '22 04:10

P. Roe