可能重复:
如何公开当前装配到CodeProvider
我写了一个字符串从一个文本框在vb.net在本例转换像代码: 如何将字符串转换为C#代码
但是,在这个类我不能把从主体工程的任何静态变量和方法。 这是代码vb.net:
Dim vb As New VBCodeProvider()
Dim icc As ICodeCompiler = vb.CreateCompiler()
cp = New CompilerParameters
cp.ReferencedAssemblies.Add("System.dll")
cp.ReferencedAssemblies.Add("System.Windows.Forms.dll")
cp.ReferencedAssemblies.Add("System.Xml.dll")
cp.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
cp.ReferencedAssemblies.Add("Comatic(de-ch).exe")
cp.ReferencedAssemblies.Add("System.Data.dll")
cp.ReferencedAssemblies.Add("mscorlib.dll")
cp.CompilerOptions = "/t:library"
cp.GenerateInMemory = True
Dim sb As New StringBuilder("")
sb.Append("Imports System" & vbNewLine)
sb.Append("Imports Microsoft.VisualBasic" & vbNewLine)
sb.Append("Imports System.Windows.Forms" & vbNewLine)
sb.Append("Imports System.Xml" & vbNewLine)
sb.Append("Imports Comatic" & vbNewLine)
sb.Append("Imports System.Data" & vbNewLine)
sb.Append("<System.ComponentModel.ToolboxItem(False)> _" & vbNewLine)
sb.Append("Public Class VbCodeEvaler" & vbNewLine)
sb.Append("Public Sub EvalCode()" & vbNewLine)
sb.Append(TxVbCode.Text & vbNewLine)
sb.Append("End Sub" & vbNewLine)
sb.Append("Dim t As New System.Threading.Thread(AddressOf Me.EvalCode)" & vbNewLine) 'System.Threading.
sb.Append("Public Sub StartThred()" & vbNewLine)
sb.Append("t.Start()" & vbNewLine)
sb.Append("End Sub" & vbNewLine)
sb.Append("Public Sub StopThred()" & vbNewLine)
sb.Append("t.Abort()" & vbNewLine)
sb.Append("End Sub" & vbNewLine)
sb.Append("End Class" & vbNewLine)
cr = icc.CompileAssemblyFromSource(cp, sb.ToString())
If cr.Errors.Count > 0 Then
MsgBox("Error: " & cr.Errors(0).ErrorText)
Return Null
End If
Dim a As System.Reflection.Assembly = cr.CompiledAssembly
Dim o As Object = a.CreateInstance("VbCodeEvaler")
Dim t As Type = o.GetType()
'Dim mi As MethodInfo = t.GetMethod("EvalCode")
Dim mi As MethodInfo = t.GetMethod("StartThred")
mi.Invoke(o, Null)
我怎么能叫从主要项目所有的静态和公共方法和变量? 谢谢!