11

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Antoine Aubry
  • 12,203
  • 10
  • 45
  • 74

10 Answers10

5

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
James Nies
  • 101
  • 1
  • 2
4

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dana the Sane
  • 14,762
  • 8
  • 58
  • 80
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lucas Wilson-Richter
  • 2,274
  • 1
  • 18
  • 24
1

Take a look at Polystyle

jmatthias
  • 7,375
  • 7
  • 27
  • 36
1

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

Before:

Alt text

After:

Alt text

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cheeso
  • 189,189
  • 101
  • 473
  • 713
1

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.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
0

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

0

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

NinjaCross
  • 784
  • 2
  • 9
  • 20
0

I am going to second the ReSharper suggestion. I can't live without it.

The built-in reformatting is under ReSharper → ToolsCleanup Code menu and is bound to Ctrl + E, Ctrl + C by default.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rboarman
  • 8,248
  • 8
  • 57
  • 87
0

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

Joel Lucsy
  • 8,520
  • 1
  • 29
  • 35