'传入参数 Me.m_Source = String.Format(Me.m_Source, Me.m_Expression) End If Dim mCompResult As CompilerResults = Me.m_Compiler.CompileAssemblyFromSource(Me.m_CompilerParameters, Me.m_Source) '//错误提示 If (mCompResult.Errors.HasErrors) Then Dim ErrorMessage As String ErrorMessage = "编译错误:" & vbCrLf Dim Err As CompilerError For Each Err In mCompResult.Errors ErrorMessage = ErrorMessage & Err.ErrorText & vbCrLf Next Throw New Exception("编译错误: " + ErrorMessage) End If Me.m_Assembly = mCompResult.CompiledAssembly Me.m_Compiled = True End Sub '//如果是默认源代码,此函数取表达式的值; '//如果自定义源代码,请参考本函数视实际自己写 Public Function GetExpressionValue(ByVal Expression As String) As Object If Not Me.m_Is_Default Then MsgBox("所用的代码不是默认代码,此函数无效") Return Nothing End If '如果还没有编译则编译 If Not Me.m_Compiled Then '//传入参数表达式作为代码 Me.m_Expression = Expression
Complile() '//生成实例,注意类名区分大小写 Me.m_tmpClass = Me.m_Assembly.CreateInstance("tmpClass") '//取函数,注意大小写 m_MethodInfo = Me.m_tmpClass.GetType().GetMethod("GetExpressionValue") End If |