Question

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).

Was it helpful?

Solution

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.

OTHER TIPS

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.

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 :)

Take a look at Polystyle

I use emacs and csharp-mode. One keystroke and the module is reformatted according to my desires.

before:
alt text http://i43.tinypic.com/svot8n.jpg

after:
alt text http://i42.tinypic.com/x45j0n.jpg

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.

For completeness, check out http://uncrustify.sourceforge.net/

Check out astyle. I am sure the KDE guys use it, but the website said that it supports C#.

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.

Maybe you could take a look at this free Addin for Visual Studio 2010/2012 i recently wrote :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top