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
CodeSnippetComp ileUnit
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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 CodeSnippetComp ileUnit(strTemp )
Dim cop As New CodeGeneratorOp tions
Dim provider As New VBCodeProvider
Dim CodeGenerator As ICodeGenerator =
provider.Create Generator()
' Set cop properties
cop.IndentStrin g = " "
Dim sbCode As StringBuilder = New StringBuilder
Dim sw As StringWriter = New StringWriter(sb Code)
CodeGenerator.G enerateCodeFrom CompileUnit(myC U, 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 CodeGeneratorOp tions
Dim provider As New VBCodeProvider
Dim CodeGenerator As ICodeGenerator =
provider.Create Generator()
' Set cop properties
cop.IndentStrin g = " "
Dim myCompileUnit As New CodeCompileUnit
' Option Strict On
myCompileUnit.U serData.Add("Al lowLateBound", False)
' Option Explicit On
myCompileUnit.U serData.Add("Re quireVariableDe claration ",
False)
myCompileUnit.U serData.Add("/optioncompare:" , "Text") ' <--
Does not work
Dim sbCode As StringBuilder = New StringBuilder
Dim sw As StringWriter = New StringWriter(sb Code)
CodeGenerator.G enerateCodeFrom CompileUnit(myC ompileUnit, sw,
cop)
txtResult.Text = sbCode.ToString
End Sub
These results are
'------------------------------------------------------------------------------
' <autogenerate d>
' 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
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
CodeSnippetComp ileUnit
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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 CodeSnippetComp ileUnit(strTemp )
Dim cop As New CodeGeneratorOp tions
Dim provider As New VBCodeProvider
Dim CodeGenerator As ICodeGenerator =
provider.Create Generator()
' Set cop properties
cop.IndentStrin g = " "
Dim sbCode As StringBuilder = New StringBuilder
Dim sw As StringWriter = New StringWriter(sb Code)
CodeGenerator.G enerateCodeFrom CompileUnit(myC U, 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 CodeGeneratorOp tions
Dim provider As New VBCodeProvider
Dim CodeGenerator As ICodeGenerator =
provider.Create Generator()
' Set cop properties
cop.IndentStrin g = " "
Dim myCompileUnit As New CodeCompileUnit
' Option Strict On
myCompileUnit.U serData.Add("Al lowLateBound", False)
' Option Explicit On
myCompileUnit.U serData.Add("Re quireVariableDe claration ",
False)
myCompileUnit.U serData.Add("/optioncompare:" , "Text") ' <--
Does not work
Dim sbCode As StringBuilder = New StringBuilder
Dim sw As StringWriter = New StringWriter(sb Code)
CodeGenerator.G enerateCodeFrom CompileUnit(myC ompileUnit, sw,
cop)
txtResult.Text = sbCode.ToString
End Sub
These results are
'------------------------------------------------------------------------------
' <autogenerate d>
' 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