Is there an automatic formatting code for C #?

In my work, I mostly deal with C # code now, with java painting from time to time. What I absolutely love in Eclipse (and I know that people who use it daily love it even more) is a complex formatting code that can generate code into any encoding standard you can imagine. Is there such a tool for C #? Visual Studio code formatting (Crtl + K, Crtl + D) is a subparameter, and StyleCop checks the source code without fixing it.

My dream tool is launched from the console (for easy inclusion in automatic assemblies or prefixes and for execution in Linux + Mono), a text-based configuration is easily stored in the project repository and a graphic rules editor with Preview - just like formatting Eclipse code.

+44
c # formatting build-automation
Aug 27 '08 at 13:31
source share
14 answers

For Visual Studio, take a look at ReSharper . This is an amazing tool and a definite necessity. Versions after 4.0 have the formatting and code cleanup feature you are looking for. There is also plugin integration with StyleCop , including a formatting settings file. You will probably need the Agent Smith plugin to spell identifiers and comments. ReSharper supports formatting settings files for each solution, which can be checked in the version control system and shared by the whole team. The key combination to clear the code is Ctrl + E C.

In 'vanilla' Visual Studio, the current file can be automatically formatted with Crtl + K Crtl + D , and Ctrl + K Ctrl + F formats the selected text.

For the run-where command-line tool that will be used with commit commit, try NArrange . It is free, can process entire directories at once and work with both Mono and Microsoft.Net.

Some people also use the Artistic Style command line tool, although it requires perl and works better with C / C ++ code than with C #.

+40
Aug 27 '08 at 13:34
source share

In response to @Chris Karcherโ€™s answer, you can also automatically format the entire document by pressing Ctrl + K , Ctrl + D.

These formatting functions work in a variety of file formats - it works wonders in ugly HTML.

+14
Aug 27 '08 at 14:19
source share

.NET Foundation just released its GitHub code formatting tool

https://github.com/dotnet/codeformatter

It uses Rosyln's compiler services to parse design documents and translate them into its expected formatting conventions. They apply this to very old CLR codes to make all projects consistent.

+12
Feb 10 '15 at 0:23
source share

Another option: NArrange ;

  • is free
  • console-based (so well suited for fixing, etc., but can still be used as an โ€œexternal toolโ€ in VS)
  • flexible configuration file
+6
Apr 22 '09 at 13:55
source share

For me, Ctrl + Shift + F is displayed for searching files. When I need to format the code, I select it and press Ctrl + K , Ctrl + F.

I understand that this does not apply to automated formatting, I just wanted to clarify those who may not know that this function exists even in VS.

+5
Aug 27 '08 at 13:43
source share

I only heard good things about ReSharper . This is on my training list.

+3
Aug 27 '08 at 13:42
source share

Not directly, but I use the Agent Smith plugin for this. Unfortunately, R # is not free.

+2
Aug 27 '08 at 13:33
source share

Also check out Microsoft StyleCop

+2
Aug 27 '08 at 13:47
source share

http://www.sourceformat.com/

This tool is around (~ $ 30), I tried it and it works well (with several languages) I like this tool because it does not check the correctness of the code. I can publish code snippets from the network, and it will convert them to correspondence, regardless of whether they are in the missing parts of the code. In other cases, I try to complain. The tool can also be easily integrated into editors, as it allows you to manage the command line.

Other tools:

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

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

+2
Apr 22 '09 at 12:50
source share

I have not tried this (found it via Google). Can work? http://www.semdesigns.com/Products/Formatters/CSharpFormatter.html It's pretty cheap at USD50, but no samples are available.

+1
03 Mar. '09 at 22:33
source share

See the previous question:

Is there any tool to reformat C # code?

The search for [C #] astil shows a few more previous questions.

+1
Apr 22 '09 at 12:55
source share

Here is an open source formatting tool that has amazing features

CodeMaid

+1
Nov 27
source share

I understand that this is a very late answer, but you might be interested in this free add-on for Visual Studio 2010/2012

+1
Sep 22 '13 at 16:42 on
source share

I want to do online: freecodeformat

0
Mar 03 '17 at 16:06
source share



All Articles