C# Code Editing - Wrap right side of assigment
Regarding C# Code Editing options under R# 2020.2
Code Editing options allow for chopping long initializers (and invocation arguments). I'm looking for an option, than when the right side of an assignment exceeds the hard wrap length, first the the right-side is put on a newline, then if necessary is chopped/wrapped per the correct context.
For example, given a long initializer, first a newline is inserted before the 'new'. Then if necessary the statement if further chopped/wrapped. Is there a combination of options to allow this during cleanup?
E.g.
myVariable = new C() { Property1 = 1, Property2 = 1, Property3 = 1, Property4 = 1, Property5 = 1, };
becomes
myVariable =
new C()
{
Property1 = 1,
Property2 = 2,
Property3 = 3,
Property4 = 4,
Property5 = 5,
};
Currently I can only obtain:
myVariable = new C()
{
Property1 = 1,
Property2 = 2,
Property3 = 3,
Property4 = 4,
Property5 = 5,
};
To achieve this we've been forced to have "Keep existing line breaks" enabled and format the code by hand.
Further it would be desirable to configure if the wrap occurs before or after the '=' as described here https://youtrack.jetbrains.com/issue/RSRP-471020
Please sign in to leave a comment.
Hi Terrence,
The issue you referenced to implies configuration of wrap on assignment near the equals sign.
Its implementation will allow you to achieve the desirable styling per your description.
You are welcome to comment and vote for the request.
Thank you!
Hi Alexander...
Thanks for the reply. It wasn't clear to me that the other issue would handle the two-step consideration for initializers that I mention. Specifically:
For example, given a long initializer, first a newline is inserted before the 'new'. Then if necessary ,the statement is further chopped/wrapped.
i.e given my above example, first R# would attempt:
If this is still too long, then the initialization is further chopped:
If the other issue handles this case, I'm happy to have this one marked as duplicate and I'll vote for the other.
Thanks again.
Hi Terrance,
In order to make it clear, let me elaborate on this.
You mentioned that the following view can be configured in the current release:
The issue you referenced will add an option to add a wrap before or after the "=" sign, which would allow achieving preferable formatting:
or
I hope there are no doubts left and thank you again for the input!
Yes, I believe we're fully in accord with regard to the other issue.
I'm not sure that you've addressed specifically my concern for the two-step consideration highlighted by my above comment.
Currently for the initial example, R# will chop each initialized value. Our style demands that for long assignments, if it fits, the entire right-side of the assignment should reside on a single new line. If the right side does not fit on a new line, it is then further chopped as I've shown.
It is not clear to me that the other issue's implementation would cover this two-step consideration of mine.
Thanks again
Hi Terrence,
Thank you for the clarification.
As the issue we are talking about is a feature request - its implementation is the thing for discussion.
The two-step consideration also might be included in the scope of this issue.
I have added a comment with reference to this thread, so it will be considered in the planning stage.