C# 检查或强制命名约定

发布于 2024-07-16 20:42:28 字数 133 浏览 6 评论 0原文

我从以前的开发人员那里继承了一些程序,他在命名变量、方法和类时有点草率,使用不同的大小写,有时还使用下划线。

Visual Studio 中是否有程序或方法来验证每个变量、方法、属性、常量、类的命名...我可以使用标准 C# 约定。

I have inherited a few programs from a previous developer who was a little sloppy with naming variables, methods and classes with different capitalization and sometimes underscores.

Is there a program or a way in visual studio to validate the naming of each variable, method, property, constant, class.... I would be fine with the standard C# conventions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

三生路 2024-07-23 20:42:28

你可以看看微软的StyleCop和FXCop

You could look at Microsoft StyleCop and FXCop

呢古 2024-07-23 20:42:28

为此,我使用 ReSharper 4.5,它有一个优点,即它允许您在编写代码时看到不合格的代码。

您还可以使用 NDepend 和 CQL 以非常精细且灵活的方式检查您的约定。 作为构建脚本的一部分,它非常棒。

这两种工具都要花钱,但都值得。

I use ReSharper 4.5 for that, which has this advantage, that it allows you to see non-comforming code as you write it.

You also can use NDepend and CQL to check your conventions in a very granular and flexible way. It's great as part of your build script.

Both tools cost money, both are worth it.

情绪 2024-07-23 20:42:28

看看 StyleCop / CodeStyleEnforcer

他们会突出显示转向架,但您需要自己修复它们

http: //code.msdn.microsoft.com/sourceanalysis

http://joel .fjorden.se/static.php?page=CodeStyleEnforcer

Have a look at StyleCop / CodeStyleEnforcer

They'll highlight the bogies but you'll hvae to fix them yourself

http://code.msdn.microsoft.com/sourceanalysis

http://joel.fjorden.se/static.php?page=CodeStyleEnforcer

旧话新听 2024-07-23 20:42:28

您正在寻找的是StyleCop

它读取源代码以确保遵守某些规则。

FxCop 用于读取编译后的代码,通常不用于此类风格检查。

What you're looking for is StyleCop.

It reads source code to ensure that certain rules are obeyed.

FxCop is used to read the compiled code and generally is not used for this sort of stylistic checking.

初相遇 2024-07-23 20:42:28

FXCop 不仅具备这些功能,而且还有更多功能。

FXCop has that and much more.

旧话新听 2024-07-23 20:42:28

FXCopStyleCop 可用于检查是否符合最佳实践和标准。

FXCop and StyleCop can be used to check for conformance to best practices and standards.

如果没结果 2024-07-23 20:42:28

FxCop 将完成这项工作(或更新的< a href="http://code.msdn.microsoft.com/codeanalysis" rel="nofollow noreferrer">代码分析)。

FxCop will do the job (or more up-to-date Code Analysis).

浮萍、无处依 2024-07-23 20:42:28

这听起来像是一份工作:

StyleCop

来自网站:

StyleCop 分析 C# 源代码以强制执行一组样式和一致性规则。 它可以从 Visual Studio 内部运行或集成到 MSBuild 项目中

This sounds like a job for:

StyleCop

From the website:

StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project

┼── 2024-07-23 20:42:28

正如其他人所说:FxCop 和 StyleCop。 ReSharper 4.5 还具有可配置的命名约定。 这样做的好处在于,它会突出显示命名错误的项目,并为您提供一个带有建议名称的弹出窗口。 我不是 100% 确定,但我认为这也可以在 ReSharper 的“代码清理”功能期间运行(如果不是,那就太好了!)

当然,一旦您编辑并更正了名称,它们只会在那个时间点是正确的。 为了确保它们现在和永远正确,请将 FxCop/StyleCop 集成到您的持续集成环境中。 这会抓住那些藐视规则和规定的淘气的反社会开发者(你为他们提供什么社区服务取决于你,但这通常涉及成为甜甜圈和/或咖啡的购买者,直到有人不然就搞砸了!)

As the others have said: FxCop and StyleCop. ReSharper 4.5 also has configurable naming conventions. The beauty of this is that it'll highlight misnamed items and give you a popup with a suggested name. I'm not 100% sure, but I think this can also be run during ReSharper's 'Code Cleanup' functionality (if it's not, it'd be great if it could be!)

Of course, once you edit and and correct the names, they'll only be correct at that very point time in time. To ensure they're correct now and forever more, integrate FxCop/StyleCop into your Continuous Integration environment. This'll catch the naughty anti-social developers who flaunt the rules and regulations (what community service you give them is up to you, but it often involves being the doughnut and/or coffee purchaser 'till someone else screws up!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文