运行时调试代码

时间:2011-12-14 06:17:36

标签: vb.net

我正在运行时编译并运行代码。是否有可能在代码运行时将信息传递给我的应用程序......有点像debug.print命令,然后检索这些信息并按照我的意愿处理它?

这是我目前的代码:

        Dim SourceCode As String = txtCode.Text

    Dim Dlls() As String = {"System.dll", "System.Core.dll", "System.Data.dll", "System.Windows.Forms.dll"} 'Any referenced dll's
    Dim Compiler As New VbCompiler(SourceCode, Dlls)
    Dim CodeAssembly As Assembly = Compiler.Compile
    If Compiler.Successful Then
        Dim instance As Object = CodeAssembly.CreateInstance("TestCode.Class1")
        Dim CodeType As Type = instance.GetType
        Dim Info As MethodInfo = CodeType.GetMethod("Main")

        Dim paramTypes() As ParameterInfo = CodeType.GetMethod("Main").GetParameters()
        Dim paramCount = paramTypes.Length

        Info.Invoke(instance, Nothing)
    Else
        For Each i As CompilerError In Compiler.Errors
            MsgBox(i.ErrorText)
        Next
    End If

0 个答案:

没有答案