Hi All,
I have been playing with the codedom and can't get it to output for
option compare Binary with a CodeCompileUnit. I have searched the web
and Don't now if it's possible. If it's not possible I just go with
CodeSnippetCompileUnit
Please email me a copy at:
programmer @ jenck . net (remove the extra spaces)
Thanks in advance,
Mike
<-------
Put the following code in a form with a textbox called txtResult
and a button
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTest.Click
'Test()
Test2()
End Sub
------->
Option Strict On
Option Explicit On
Option Compare Binary
Imports System.IO
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports System.Text
Private Sub Test()
Dim strTemp As String
strTemp = "Option Strict On" & vbCrLf
strTemp += "Option Explicit On" & vbCrLf
strTemp += "Option Compare Binary" & vbCrLf
Dim myCU As New CodeSnippetCompileUnit(strTemp)
Dim cop As New CodeGeneratorOptions
Dim provider As New VBCodeProvider
Dim CodeGenerator As ICodeGenerator =
provider.CreateGenerator()
' Set cop properties
cop.IndentString = " "
Dim sbCode As StringBuilder = New StringBuilder
Dim sw As StringWriter = New StringWriter(sbCode)
CodeGenerator.GenerateCodeFromCompileUnit(myCU, sw, cop)
txtResult.Text = sbCode.ToString
End Sub
This results in:
Option Strict On
Option Explicit On
Option Compare Binary
However, if I try and use
Private Sub Test2()
Dim cop As New CodeGeneratorOptions
Dim provider As New VBCodeProvider
Dim CodeGenerator As ICodeGenerator =
provider.CreateGenerator()
' Set cop properties
cop.IndentString = " "
Dim myCompileUnit As New CodeCompileUnit
' Option Strict On
myCompileUnit.UserData.Add("AllowLateBound", False)
' Option Explicit On
myCompileUnit.UserData.Add("RequireVariableDeclara tion ",
False)
myCompileUnit.UserData.Add("/optioncompare:", "Text") ' <--
Does not work
Dim sbCode As StringBuilder = New StringBuilder
Dim sw As StringWriter = New StringWriter(sbCode)
CodeGenerator.GenerateCodeFromCompileUnit(myCompil eUnit, sw,
cop)
txtResult.Text = sbCode.ToString
End Sub
These results are
'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.2032
'
' Changes to this file may cause incorrect behavior and will be
lost if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
<-- MISSING Option Compare Binary