![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
CSharpCodeSource
=
"
using System;
using System.Windows.Forms;
namespace TestNameSpace
{
public class TestClass
{
public void Test(string theString)
{
MessageBox.Show(theString);
}
}
}
"
CSharpProvider = dotnetobject " Microsoft.CSharp.CSharpCodeProvider "
CompilerParams = dotnetobject " System.CodeDom.Compiler.CompilerParameters "
CompilerParams.ReferencedAssemblies.Add( " System.dll " )
CompilerParams.ReferencedAssemblies.Add( " System.Windows.Forms.dll " )
CompilerParams.GenerateExecutable = false
CompilerParams.GenerateInMemory = false
CompilerResults = CSharpProvider.CompileAssemblyFromSource CompilerParams #(CSharpCodeSource)
WinAssembly = CompilerResults.CompiledAssembly
TestAssembly = WinAssembly.CreateInstance " TestNameSpace.TestClass "
TestAssembly.Test " 动态编译的C# "
(DotNetObject " TestNameSpace.TestClass " ).Test " 动态编译的C# "
using System.Windows.Forms;
namespace TestNameSpace
{
public class TestClass
{
public void Test(string theString)
{
MessageBox.Show(theString);
}
}
}
"
CSharpProvider = dotnetobject " Microsoft.CSharp.CSharpCodeProvider "
CompilerParams = dotnetobject " System.CodeDom.Compiler.CompilerParameters "
CompilerParams.ReferencedAssemblies.Add( " System.dll " )
CompilerParams.ReferencedAssemblies.Add( " System.Windows.Forms.dll " )
CompilerParams.GenerateExecutable = false
CompilerParams.GenerateInMemory = false
CompilerResults = CSharpProvider.CompileAssemblyFromSource CompilerParams #(CSharpCodeSource)
WinAssembly = CompilerResults.CompiledAssembly
TestAssembly = WinAssembly.CreateInstance " TestNameSpace.TestClass "
TestAssembly.Test " 动态编译的C# "
(DotNetObject " TestNameSpace.TestClass " ).Test " 动态编译的C# "