Is there an automatic code formatter for C#? [clos

2019-01-30 22:49发布

In my work I deal mostly with C# code nowadays, with a sprinkle of java from time to time. What I absolutely love about Eclipse (and I know people using it daily love it even more) is a sophisticated code formatter, able to mould code into any coding standard one might imagine. Is there such a tool for C#? Visual Studio code formatting (Crtl+K, Crtl+D) is subpar and StyleCop only checks the source without fixing it.

My dream tool would run from console (for easy inclusion in automated builds or pre-commit hooks and for execution on Linux + Mono), have text-file based configuration easy to store in a project repository and a graphical rule editor with preview - just like the Eclipse Code Formatter does.

14条回答
【Aperson】
2楼-- · 2019-01-30 23:08

Another option: NArrange;

  • free
  • console based (so good for commit hooks etc, but can still be used as an "External Tool" in VS)
  • flexible config file
查看更多
Ridiculous、
3楼-- · 2019-01-30 23:08

I've heard only good things about ReSharper. It's on my to-learn list.

查看更多
贼婆χ
4楼-- · 2019-01-30 23:10

Here is an open source code formatting tool which has amazing features

CodeMaid

查看更多
做自己的国王
5楼-- · 2019-01-30 23:16

Also take a look at Microsoft StyleCop

查看更多
smile是对你的礼貌
6楼-- · 2019-01-30 23:18

Not directly, but I use the Agent Smith plugin for R# to do this. Unfortunately, R# isn't free.

查看更多
时光不老,我们不散
7楼-- · 2019-01-30 23:20

http://www.sourceformat.com/

This tool is around (~30$), I tried it and it works nice (with multiple languages) I like this tool the best cuz it doesn't check code file for correctness. I can post code snippets from the net and it will traslate them correclty no matter if they are in missing parts of the code. Other tools I try complain in that cases. The tool can also be integrated easily into editors as it allows command line driving.

Other tools:

http://www.polystyle.com/index.jsp

http://astyle.sourceforge.net/ (open source)

查看更多
登录 后发表回答