Reputation: 10078
I have Visual Studio 2019 (Community at home; Professional in the office). I also have ReSharper. I set up line length to be 120; indentation at 4, and autoformatting on close brace or semicolon. The language is C#
The problem is that indentation of the wrapped line is completely unpredictable (at least to me). Sometimes it is indented 4 characters as I expect; sometimes it is under a parenthesis or to the right of =>
or same operator (like &&
). So, frequently wrapped line starts at character 80 or 90!
How can I make it always indent 4 characters from the previous line?
Needless to say that I tried a dozen of combinations of options under Visual Studio and Resharper Code Editing - Formatting options. Visual studio doesn't seem to have any option that would make it push the new line. Resharper has Parenthesis section under C# - Formatting style. But nothing makes wrapping simple
Example:
lstGroup.Select(s => new Group
{
...
Status = lookup.Where(w => w.LookupType == LookupConstants.CRIMETYPE &&
(int?)w.LookupIndex == (string.IsNullOrEmpty(s.TempCrimeType) ? 0
: Convert.ToInt32(s.TempCrimeType))).Select(w => w.LookupDescription).FirstOrDefault(),
...
});
(it may not be clear, but the lines don't run past char; so I would like it to stay this way!). After hitting semicolon at the end of the statement, it turns into
Status = lookup.Where(w => w.LookupType == LookupConstants.CRIMETYPE &&
(int?) w.LookupIndex == (string.IsNullOrEmpty(s.TempCrimeType)
? 0
: Convert.ToInt32(s.TempCrimeType))).Select(w => w.LookupDescription).FirstOrDefault(),
Upvotes: 0
Views: 1331
Reputation: 10118
I'm not sure if you can completely simplify indents for wrapped statements/expressions, but the following options should make it much easier. If something still irritates you, please amend your question with examples.
Tabs, Indents, Alignment
Brace Layout
UPDATE: To prevent ReSharper from re-wrapping your code, go to "Line breaks and wrapping" page and look for options called "Wrap ..." with values "Chop if long or multiline" and "Chop always". Change them to "Simple wrap" as needed. You may also want to ensure that all "Keep existing arrangement..." options are turned on. Your particular example is influenced by a setting called "Wrap ternary expression".
Upvotes: 2