C# 检查或强制命名约定
我从以前的开发人员那里继承了一些程序,他在命名变量、方法和类时有点草率,使用不同的大小写,有时还使用下划线。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
你可以看看微软的StyleCop和FXCop
You could look at Microsoft StyleCop and FXCop
为此,我使用 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.
看看 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
您正在寻找的是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.
FXCop 不仅具备这些功能,而且还有更多功能。
FXCop has that and much more.
FXCop 和 StyleCop 可用于检查是否符合最佳实践和标准。
FXCop and StyleCop can be used to check for conformance to best practices and standards.
FxCop 将完成这项工作(或更新的< a href="http://code.msdn.microsoft.com/codeanalysis" rel="nofollow noreferrer">代码分析)。
FxCop will do the job (or more up-to-date Code Analysis).
这听起来像是一份工作:
StyleCop
来自网站:
This sounds like a job for:
StyleCop
From the website:
正如其他人所说: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!)