Home All Groups Group Topic Archive Search About
Author
23 May 2009 5:05 AM
Mike
Hi,

I generally like to be very tight with my type casting and matching,
so I like the use Option Strict On.

However, I am coming across some needs where I would to turn it off.

As far as I can see, the compiler doesn't support turning it off/on
between code lines.

If this possible?

I guess I can break up the code and put these parts in a new module
where I know  the type casting is safe and use Option Strict off but
is it possible with some other method?

Thanks

--

Author
23 May 2009 9:01 AM
Cor Ligthert[MVP]
Mike,

The partial class can be your friend in this, although I have never that I
cannot cast.

Cor
Author
23 May 2009 4:01 PM
Herfried K. Wagner [MVP]
"Mike" <unkn***@unknown.tv> schrieb:
> I generally like to be very tight with my type casting and matching, so I
> like the use Option Strict On.
>
> However, I am coming across some needs where I would to turn it off.
>
> As far as I can see, the compiler doesn't support turning it off/on
> between code lines.
>
> If this possible?

Unfortunately no.  You can only turn it on/off on a member basis by using a
partial class and setting 'Option Strict On'/'Option Strict Off' for each of
the partial type declarations.

I tend to use this approach when dealing with COM Interop scenarios such as
in Office programming.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
23 May 2009 4:06 PM
Mike
Herfried K. Wagner [MVP] wrote:
Show quoteHide quote
> "Mike" <unkn***@unknown.tv> schrieb:
>> I generally like to be very tight with my type casting and matching,
>> so I like the use Option Strict On.
>>
>> However, I am coming across some needs where I would to turn it off.
>>
>> As far as I can see, the compiler doesn't support turning it off/on
>> between code lines.
>>
>> If this possible?
>
> Unfortunately no.  You can only turn it on/off on a member basis by
> using a partial class and setting 'Option Strict On'/'Option Strict Off'
> for each of the partial type declarations.
>
> I tend to use this approach when dealing with COM Interop scenarios such
> as in Office programming.

Ok, thanks Herfried and Cor for the tip.

--