问题
I am looking for a (preferably) command-line tool that can reformat the C# source code on a directory tree. Ideally, I should be able to customize the formatting. Bonus points if the tool can be run on mono (or linux).
回答1:
A bit late coming across this... You could also try NArrange to reformat your code. The formatting options it supports are still pretty limited, but it can process an entire directory and is a command-line tool. Also, NArrange runs under Mono.
回答2:
You could give Artistic Style a try, it requires perl to be installed though. It's got a decent list of formatting options, and supports C and Java as well.
回答3:
This isn't command-line, mono or linux, but it's something: I've been using ReSharper (made by JetBrains) and it's rather good. It's a Visual Studio plugin, so I'm guessing it's not your cup of tea, but hopefully someone will come along with a better answer :)
回答4:
Take a look at Polystyle
回答5:
See our SD C# Formatter. Uses a full C# parser and prettyprinter; it will not break your code.
EDIT: September, 2013: Now runs on Windows and Linux. Covers C# v5.
回答6:
I use emacs and csharp-mode. One keystroke and the module is reformatted according to my desires.
before:
after:
回答7:
For completeness, check out http://uncrustify.sourceforge.net/
回答8:
Check out astyle. I am sure the KDE guys use it, but the website said that it supports C#.
回答9:
I know this is an old post but I am going to second the ReSharper suggestion anyways. I can't live without it.
The built-in reformatting is under the ReSharper->Tools->Cleanup Code menu and is bound to Ctrl-E Ctrl-C by default.
回答10:
Maybe you could take a look at this free Addin for Visual Studio 2010/2012 i recently wrote :)
来源:https://stackoverflow.com/questions/27253/is-there-any-tool-for-reformatting-c-sharp-code