c# formatting

HI:

I know in the rider setting, there is c# code style section where you can configure how to format your c# code. But i was wondering if there is format plugin or some setting file which we can apply directly apply to rider to format the code same as visual studio style ?

 

Cheers

0
3 comments

Hi,

Rider is not able to import Visual Studio settings yet. May I ask you how you expect this feature to look like? How you normally share your VS settings between machines and/or teammates?

For now, I'd suggest that you use the new Auto-Detect Formatting Rules feature introduced in Rider 2020.3.x. You can call it on a code snippet:

- Select the code where you'd like to detect the code style

- Call the intentions actions menu on it via Alt-Enter

Go to Format selection ->Detect formatting settings 

Alternatively, you can call auto-detect on your whole solution (which can take some time though):

- Go to File | Settings | Editor | Code Style | C#

Press Auto-Detect Formatting Rules button:

 

0

HI Julia:

Normally I use the functionality call "Reformat Code" (shortcut, option + command + L on mac) to format the code. 
If i remember correctly, when i use this functionality in Intellj, it will format and tidy up the code nicely without i configure any java coding style, i would expect this will be the same in rider.
However, when i click the Reformat code in rider, it did not format the code, as you can see from the screenshot. The first writeline and second writeline still have 2 lines of space.  Isn't 
the reformat code should tidy up the code ?
 
 
Expected
 
Additionally, when i use intellj, i normally dont do custom style setup, i just use the plugin call "google-java-format" or "alibaba java coding guidelines" to help me to format the code. so i would
expect rider to have some sort similar microsoft or google-c# coding standard.
 
0

zhe wu,

Please accept my apologies for the delayed reply. Indeed, reformatting code with default set of Rider settings doesn't remove empty lines between declarations if there are less than three. To achieve your code style with one blank line between methods, please do the following:

1. Go to File | Settings | Editor | Code Style | C#

2. Open Blank lines tab, scroll to Blank lines in declarations, and set Keep max blank lines in declarations to 1

Rider code formatting rules has a default configuration that takes into account many best practices. I have just checked how Visual Studio with default settings behaves in this case. I can confirm that it doesn't remove empty lines between methods either.

We believe that Rider settings default are always in line with Microsoft guidelines, so our users are not expected to install any additional plugins to achieve that code style. If you notice anything in settings that differs from Visual Studio defaults, please let us know.

Thank you!

0

Please sign in to leave a comment.