On Thu, 5 Aug 2004 16:11:26 -0500, Chris Dunaway wrote:
>
> I am stuck on creating and instanciating the class at runtime.
>
In answer to my own question, I offer the following code. The form has a
TextBox, a button, and a PropertyGrid, all with their default names. Run
the program and type the following code in the textbox:
Class Test
Private _MyProp As Integer
Public Property MyProp() As Integer
Get
Return _MyProp
End Get
Set(ByVal Value As Integer)
_MyProp = Value
End Set
End Property
End Class
'*** CODE BEGINS
Private Sub Button1_Click(...) Handles Button1.Click
Dim VB As New VBCodeProvider
Dim obj As Object
Dim Compiler As ICodeCompiler = VB.CreateCompiler()
Dim cParams As New CompilerParameters
cParams.GenerateExecutable = False
cParams.GenerateInMemory = True
cParams.IncludeDebugInformation = False
Dim cResults As CompilerResults
cResults = Compiler.CompileAssemblyFromSource(cParams, TextBox1.Text)
If cResults.Errors.Count = 0 Then
Dim assyResult As [Assembly] = cResults.CompiledAssembly
Dim aType As Type
aType = assyResult.GetType("Test")
obj = assyResult.CreateInstance(aType.FullName)
PropertyGrid1.SelectedObject = obj
PropertyGrid1.Refresh()
End If
VB.Dispose()
End Sub
'*** CODE ENDS
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
|