如何阻止 VisualStudio 项目中的编码人员使用 DateTime.parse()?
我们希望我们的程序员不要使用 DateTime.parse()
。
我们如何阻止使用它?
我们可以覆盖这个,以躲避他们吗?
编辑1
实际上我们想重写这个方法,我们有自己的方法,可以这样调用:clsStrUtils.ISOToDate()
。
EDIT2
我们确实信任我们的程序员,但这是一个特定的情况。我不想限制任何人使用更好的方法,我只是想限制 Parse()。他们仍然可以使用ParseExact()。
We want our coders to NOT use DateTime.parse()
.
How can we block to use it?
Can we override this, to hide from them?
EDIT1
Actually we want to override this method, we have our own method which gets called this way: clsStrUtils.ISOToDate()
.
EDIT2
We do trust our programmers, but this is a specific situation. I don't want to restrict no-one using a better way, I just want to restrict Parse(). They can still use ParseExact().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您也许可以在 FxCop 中编写自定义规则来执行此操作。 查看此网站上的教程了解如何操作的信息。然后,您可以定期运行它来验证团队成员是否正在使用您制定的标准。
You might be able to write a custom rule in FxCop to do this. Check out the tutorials on this site for information on how. You then might be able to run it periodically to validate that the members of the team are using the standards you put in place.
你们有持续集成系统吗?如果这样做,如果样式检查未通过,您可以将构建标记为失败。确保在样式检查中扫描对“DateTime.Parse”的引用。
更好的解决方案是对代码进行单元测试。 DateTime.Parse 有很多有效的用途,最好确保测试涵盖它们。
Do you have a continuous integration system? If you do, you could mark a build as failed if a style check check does not pass. Make sure to scan for references to "DateTime.Parse" in your style check.
A better solution would be to unit test your code. DateTime.Parse has plenty of valid uses, and it might be better to just make sure tests cover them.
根据我的经验,“强迫”程序员使用某些东西只会抑制他们的思维过程,并导致整个团队的不满情绪增长。
It is my experience that "forcing" programmers to use something only inhibits their thought process and causes resentment to grow throughout the group.
我们已开始使用 FXCop 而且,作为一名开发人员来说,这还不算太糟糕。它应该能够轻松阻止某些方法的使用。
We've started using FXCop and, speaking as a developer, it's not so bad. It should be able to easily block the usage of certain methods.
如果您正在进行代码审查(您应该这样做),您可以在审查期间发现它。否则,无法阻止某人调用 .NET Framework 中的静态方法(据我所知)。
If you are doing code reviews, which you should be, you can catch it during the review. Otherwise, there is no way to prevent someone from calling a static method in the .NET Framework (that I'm aware of).