Question

I'm turning On Option Strict on all project in my newly inherited VB.NET application. I'm mostly adding alot of CStr, CBool, CType statements to get rid of all the compile errors.

Dim x As String = someObject
dim val As SomeEnumType = 1

becomes

Dim x As String = CStr(someObject) ' Not .ToString() because someObject could be Nothing
Dim val As SomeEnumType = CType(1, SomeEnumType)

etc.

I'm doing everything pretty much by hand one error at a time and have a test application to test the Nothing, ... bordercases.

But is it possible I'm missing something that is going to generate exceptions at runtime? And what kind of code is being generated due to Option Strict? Is it just some conversions that are going to be added or does OptionStrict do other things aswell?

Was it helpful?

Solution

Option Strict On does not generate any extra code, it merely tells the compiler to generate errors when your vb.net statements are relying on implicit type conversions. Like assigning an object to a string. What you've written in your snippet is exactly what the compiler does with Option Strict Off so no extra code is generated by your type conversion operators.

But of course, there's always a non-zero chance that you use the wrong conversion and break the existing code. You'll have to do what's always required when you make changes to code, you'll have to re-test it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top