CodeDom VBCodeProvider Option Strict

  • Thread starter Thread starter Mark Sargent
  • Start date Start date
M

Mark Sargent

Can anyone tell me how to specify the "Option Strict" setting when
generating code using the VBCodeProvider.

Thanks.
 
Mark,
You can set the option using a CodeGeneratorOptions object when you call
ICodeGenerator.GenerateCode.

Set the '/optionstrict' option to "+"

Something like:

Dim unit As CodeCompileUnit
Dim output As StreamWriter
Dim generator As ICodeGenerator

Dim options as New CodeGeneratorOptions()
options("/optionstrict") = "+"

generator.GenerateCodeFromCompileUnit(unit, output, options)

Hope this helps
Jay
 
Mark,
Doh! I was looking at the wrong part of the code :-|

You need to add the following to the UserData of your CodeCompileUnit:

Dim unit As CodeCompileUnit

' Option Strict On
unit.UserData.Add("AllowLateBound", False)

' Option Explicit On
unit.UserData.Add("RequireVariableDeclaration", True)


The /optionstrict was something else I was trying, but never removed from my
sample... :-(
Hope this helps
Jay
 
Marvellous - works a treat. Thanks!

Jay B. Harlow said:
Mark,
Doh! I was looking at the wrong part of the code :-|

You need to add the following to the UserData of your CodeCompileUnit:

Dim unit As CodeCompileUnit

' Option Strict On
unit.UserData.Add("AllowLateBound", False)

' Option Explicit On
unit.UserData.Add("RequireVariableDeclaration", True)


The /optionstrict was something else I was trying, but never removed from my
sample... :-(
Hope this helps
Jay
 
Back
Top