将 option strict off 代码转换为 option strict on 的工具?
我要接手一个用vb.net编写的项目,其中包含超过40万行以option strict off模式编写的代码。我想在做任何其他事情之前首先在选项 strict on 下构建它——这可能会将其转换为 C#。我发现有数千行代码引发编译错误,大部分是关于隐式类型转换的。
如果我不想手动更正每一行,是否有任何工具可以帮助使其在选项严格模式下进行编译?因为我自己将 CStr/CInt 调用添加到每一行代码中确实很痛苦。
I have to take over a project written in vb.net, which contains more than 400k lines of code written in option strict off mode. I want to build it under option strict on first before I do anything else -- which maybe converting it into C#. I found there's thousands of lines of code raises compilation error, mostly are about implicit type casts.
Is there any tool would help to make it compile under option strict on mode if I don't want to correct every single line manually? Because it's really painful to add CStr/CInt invocation into every line of Code myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅添加 CInt 或 CStr 或 Convert.ToString 不会为您带来任何好处。您需要根据具体情况查看设计,并从头开始找出数据类型不匹配的原因。
Just adding CInt or CStr, or Convert.ToString for that matter doesn't gain you anything. you need to look at the design on an individual case by case basis and figure out why the datatypes are mismatched from the ground up.
混合搭配如何让你跑步。
这就是我认为你应该做的。
将项目设置设置为“Option strict On”
所有存在编译错误的单个 .vb 文件...将“Option strict Off”作为该文件的第一行。 (这将覆盖项目范围的设置)
您现在有一个编译项目。
下一个工作是当您有时间选择单个文件时(搜索“Option strict Off”)(或者当您出于其他原因修改文件时)
从单个文件中删除“Option strict Off”,让 VisualStudio 自动更正标记为您修复错误。
How about mix and match just to get you running.
This is what I think you should do.
Set project setting to "Option strict On"
All individual .vb files that have a compile error... put "Option strict Off" as the first line in that file. (this will override the project wide setting)
You now have a compiling project.
Next job is when you've got time pick an individual file (search for "Option strict Off") (or when you modify a file for another reason)
Remove the "Option strict Off" from the individual file and let VisualStudio auto correct tags fix the errors for you.
那么您想同时使用 Option Strict 并且不使用它吗?
我会告诉您:首先将“Option Strict”设置为“On”,然后在“警告配置”下将“隐式转换”条件从“错误”更改为“警告”(或“无”)。然后您将看到配置显示:Option Strict - “Custom”。
但不要欺骗自己:这个自定义设置并不严格,因为它允许隐式的事情发生。
您需要问自己:“为什么我要在选项 Strict 下编译它?”。
So you want to both use Option Strict and to not-use it at the same time?
I'll tell you what: first turn Option Strict to On, then under Warning Configurations change the "Implicit Conversion" condition from "Error" to "Warning" (or "None"). You will then see that the configuration says: Option Strict - "Custom".
But don't fool yourself: this custom setup isn't Strict, as it allows Implicit things to take place.
You need to ask yourself: "Why do i want to compile this under option Strict?".