Visual Studio -> wrap every parameter
Asked Answered
B

2

10

Using Visual Studio 2019, I found a really useful refactoring option in 'Quick actions and refactoring': (might come from PowerTools, whatever)

enter image description here

I just wondered how:

  • I can make this wrapping settings a default formatting settings
  • Or apply this formatting on my whole solution at once (without resharper)

For the later, a solution with Visual Studio Code would be perfect as well !

Thanks for your help

Benzocaine answered 15/5, 2019 at 9:32 Comment(2)
Just a little heads up, if you have that much parameters, you should consider creating a class, which represents those parameters. If that is not possible, it might be an indicator, that your method is doing to much (functional background instead of object oriented).Diapause
@ChristianGollhardt There are plenty of system and 3rd party package APIs that require even more parameters and when we use them it'd be nice to automatically format the list. It's not just for the functions thought - class constructors, records, LINQ. VS2022 is capable of doing it, just not automatically. It should be a part of .editorconfig with an automatic fix but it seems like MS waits for someone to create a Pull Request for this feature github.com/dotnet/roslyn/issues/59927Ferryboat
A
2

You can try using Rewrap extension which formats code, comments, and other text to a given line length (80 by default).

The main Rewrap command is: Rewrap Code / Comment, by default bound to Alt+Q. Put the text cursor inside a comment line, block or plain text paragraph and invoke the command to wrap. You can also select just a few lines, or multiple comments in one selection.

There is currently an Open request for this in the VS Code Issue tracker on GitHub

Anticlimax answered 4/6, 2019 at 10:46 Comment(0)
C
0

... apply this formatting on my whole solution at once ...

You can apply this formatting to an entire document at once with the free CodeRush Visual Studio extension. https://www.devexpress.com/products/coderush/

After installing the extension, use the CodeRush Format Document action.

Alternatively, you can automatically format on save from CodeRush > Options > Editor > C# > Code Cleanup:

  • Apply Code Cleanup when savings a document
  • Code Style > Apple CodeRush formatting > Apply On Save

If needed you can also customize the wrapping in the C# > Formatting > Wrapping options area.

For a solution-wide analyzer, there is an open issue for this at https://github.com/dotnet/roslyn/issues/59927

Coronagraph answered 22/5, 2023 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.