ASP.NET MVC 的 Lint?
是否有适用于 ASP.NET MVC 的 lint 实用程序?鉴于我经常通过字符串指定视图和链接,当我移动事物或更改实体名称时,我经常会破坏事物,然后只有在运行时出现故障时我才会发现。
Is there a lint utility for ASP.NET MVC? Given that I frequently specify views and links via strings, when I move things around or change entity names I often break things, which I then only find out about when something fails at runtime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道有类似的东西,但我会告诉你我做了什么:我所有的视图名称都在包含字符串常量的结构中。随着项目的变化保持同步是很痛苦的,但这是值得的,因为如果你使用
而不是
I don't know that there's something like that, but I'll tell you what I do: All my view names are in a struct that contains string constants. It's a pain to keep it sync'ed as the project changes, but it's worth it because you're far more likely to catch errors if you're using
rather than
其他选项——使用强类型助手(可能仍然在 futures 程序集中)。 EG,
Html.Action(x => x.ShowProduct(id))
;确实是飞翔的唯一方法。Other option -- use the strongly typed helpers (which might still be in the futures assemblies). EG,
Html.Action<ProductsController>(x => x.ShowProduct(id))
; really the only way to fly.ReSharper 的 v6(如果您不介意生活在边缘,现在可以使用其夜间模式)将为您捕获此类错误。
ReSharper's v6 (whose nightlies are now available, if you don't mind living on the edge) will catch this kind of error for you.
您可以使用重构->重命名并启用“在字符串中搜索”以替换解决方案中的每个字符串
You can use Refactor -> Rename and enable Search in Strings to replace every string in the solution