REM Dynamic Compilation Demo in VB
REM translated from the C# code found on Internet.
REM by Qin Yongliang, 20120831
REM feel free to use the code for any purpose
Imports XXXXXXXXXXXXXXXXXXpiler
Imports XXXXXXXXXXXXsualBasic
Imports Microsoft.CSharp
'optional.
Imports XXXXXXXXXflection
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles XXXXXXXXXXick
Button1.Text = "Compiling..."
Me.Enabled = False
XXXXXfresh()
Dim cpara = New CompilerParameters
XXXXXXXXXpilerOptions = Trim(TextBox2.Text)
'options like "/optimize" or whatever
XXXXXXXXnerateInMemory = True
'stores the compile result in memory.
XXXXXXXXcludeDebugInformation = False 'we are unlikely to debug it
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXd("mscorlib.dll")
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXd("system.dll")
'add references if needed.
Dim cdp = XXXXXXXXXXXXXXXXXXeateProvider("VisualBasic")
'self-explaining
Dim res = XXXXXXXpileAssemblyFromSource(cpara, TextBox1.Text) 'show results
'MsgBox(XXXXXXrors(0).ToString)
'check if errors occur.
Dim asm = XXXXXXXpiledAssembly 'as XXXXXXXXXXXXXXXXXXXXsembly
Dim newclass = XXXXXXeateInstance("newclass") 'create instance from compiled assembly
Dim newclasstype = XXXXXXXXXXXtType
Button1.Text = "Running..."
Dim ret As Double = XXXXXXXXXXXXXXXtMethod("test").Invoke(newclass, Nothing)
'assume the code returns a number; assume the code has no parameters("Nothing");
Button1.Text = "Finished!"
MsgBox(XXXXXXString, , "Result of test()") 'show result of the invoked method
Button1.Text = "Compile and Run"
Me.Enabled = True
End Sub
End Class