views:

159

answers:

3

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.

A: 

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?".

M.A. Hanin
No, I don't want to fool myself. I want it become real Option Strict code, but not manually -- adding CInt, CStr to every implict tpe conversion.
deerchao
It should be done manually, because otherwise it'll just be a fake strict code. All narrowing conversions must be checked manually to ensure they will not throw runtime errors.
M.A. Hanin
I just want what the VB compiler has done to make it work exprssed explicitly in the code. Guess that's too hard..
deerchao
+1  A: 

Just adding CInt or CStr, or convert.tostring for that matter doesnt gain you anything. you need to look at the design on an individual case by case basis and figure out why they datatypes are mismatched from the ground up.

JohnnyJP
+1  A: 

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.

MikeG