是否有 C# 自动格式化程序可用于定义自定义格式化规则?
我的团队有一个源分析工具,可以强制执行我们必须遵守的某些样式。 我无法改变它,而且有些规则只是一种痛苦。 一个例子是所有属性都必须出现在方法之前,并且所有构造函数都必须出现在属性之前。 对我来说,当对编译器来说是相同的时候,我必须花时间对程序做一些事情,这似乎很愚蠢。 我想要一些 VS 的插件,它可以让我自动做这样的事情。 另外,如果能自动将 using 放入命名空间块中,那就太好了。
My group has a source analysis tool that enforces certain styles that we have to comply with. I can't change it, and some of the rules are just a pain. One example is that all properties have to come before methods, and all constructors must come before properties. It seems silly to me that I have to take time to do something to the program when to the compiler it is the same. I would like some thing that is a plugin to VS that will let me do things like this automatically. Also, it would be nice to have it automatically put using's inside the namespace block.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据您具体想要做什么,您有不同的可能性:
Resharper:有一个自动格式化功能,可以根据您选择的规则格式化单个文件或项目/解决方案中所有文件的源代码。 因此,您可以设置大括号、命名、空格、运算符、拉姆达等设置……有关详细信息,请参阅此处< /a>. Resharper 还支持为所有解决方案设置源代码文件或对团队中所有人都相同的共享设置文件。
FxCop:我在工作中从未使用过这个,但它也是一个很棒的工具,您还可以选择要执行的规则。
You have different possibilities, depending on what exactly you want to do:
Resharper: There is a auto-format function which formats the source code of a single file or all files in the project / solution depending on your selected rules. So you set the settings for braces, naming, whitespaces, operators, lamdas, ... For more information see here. Resharper also supports settings a source- code file for all solutions or a shared settings file which is the same for all persons in the team.
FxCop: I havn't ever used this at work, but it's also a great tool an you can also select the rules which you want to enforce.
除非他们将其烘焙到 VS2010 中,否则 Resharper 具有您可能正在寻找的自动格式化功能。 CodeSmith 可能也有,只是我没用过......
Unless they bake it into VS2010, Resharper has the auto formatting capabilities you're probably looking for. CodeSmith probably has it too, I just haven't used it...
VS 内置了一些格式化选项。
转到工具-->选项-->文本编辑器-->C#-->格式。
它们并不包括所有场景,但可能会让您接近。
There are some formatting options built into VS.
Goto Tools-->Options-->Text Editor-->C#-->Formatting.
They don't include every scenario, but might get you close.
Resharper - 多么棒的工具啊。 我想没有它我就无法应付。 它一定是 Visual Studio 的终极生产力工具。 重构、代码分析、代码格式化、代码完成——它有很多。
Resharper - what a fantastic tool. I don't think I could manage without it. It must be the ultimate productivity tool for Visual Studio. Re-factoring, code analysis, code formatting, code completion - it has the lot.