在我的工作中,我现在主要处理 C# 代码,不时会使用一些 java.我绝对喜欢 Eclipse(而且我知道每天使用它的人更喜欢它)是一个复杂的代码格式化程序,能够将代码塑造成人们可以想象的任何编码标准.C#有这样的工具吗?Visual Studio 代码格式(Crtl+K、Crtl+D)低于标准,StyleCop 只检查源而不修复它.
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.
我梦寐以求的工具可以从控制台运行(以便轻松包含在自动构建或预提交挂钩中以及在 Linux + Mono 上执行),具有易于存储在项目存储库中的基于文本文件的配置和图形规则编辑器预览 - 就像 Eclipse Code Formatter 一样.
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.
对于 Visual Studio,看看 ReSharper.这是一个很棒的工具,也是绝对必备的.4.0 之后的版本具有您正在寻找的代码格式化和清理功能.还有 与 StyleCop 的插件集成,包括格式设置文件.
For Visual Studio, take a look at ReSharper. It's an awesome tool and a definite must-have. Versions after 4.0 have the code formatting and clean-up feature that you are looking for. There's also plugin integration with StyleCop, including formatting settings file.
您可能还需要 Agent Smith 插件,因为对标识符和注释进行拼写检查.ReSharper 支持每个解决方案的格式化设置文件,这些文件可以签入版本控制系统并由整个团队共享.代码清理的快捷键是Ctrl + E, C.
You'll probably want Agent Smith plugin as well, for spell-checking the identifiers and comments. ReSharper supports per-solution formatting setting files, which can be checked into version control system and shared by the whole team. The keyboard shortcut for code cleanup is Ctrl + E, C.
在'vanilla' Visual Studio中,当前文件可以通过Ctrl + K, Ctrl + D<自动格式化/kbd> 和 Ctrl + K、Ctrl + F 格式化所选文本.
In 'vanilla' Visual Studio, the current file can be automatically formatted with Ctrl + K, Ctrl + D, and Ctrl + K, Ctrl + F formats the selected text.
关于与提交挂钩使用的无处不在的命令行工具,请尝试 NArrange.它是免费的,可以一次处理整个目录并在 Mono 和 Microsoft .NET 上运行.
As for a runs-everywhere command line tool to be used with commit hooks, try NArrange. It's free, can process whole directories at once and runs on Mono as well as on Microsoft .NET.
有些人也使用 Artistic Style 命令行工具,虽然它需要 Perl 并且与 C 配合得更好/C++ 代码而不是 C#.
Some people also use the Artistic Style command line tool, although it requires Perl and works better with C/C++ code than with C#.
这篇关于C# 有自动代码格式化程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!