有人可以向我解释汇编类的function吗?

我想在运行时加载和创建程序集,有人告诉我使用命名空间System.Reflection.Assembly和System.Reflection.Emit。

我在msdn上找到的只有参考资料,但是当你不知道在哪里以及如何开始时,它不适合使用它。 我已经谷歌搜索,但我没有找到任何有用的教程/样本/参考。

有人可以向我解释function或给我一些示例/教程吗?

http://msdn.microsoft.com/en-us/library/saf5ce06.aspx

public static void CompileScript(string source) { CompilerParameters parms = new CompilerParameters(); parms.GenerateExecutable = true; parms.GenerateInMemory = true; parms.IncludeDebugInformation = false; parms.ReferencedAssemblies.Add("System.dll"); // Add whatever references you might need here CodeDomProvider compiler = CSharpCodeProvider.CreateProvider("CSharp"); CompilerResults results = compiler.CompileAssemblyFromSource(parms, source); file.move(results.CompiledAssembly.Location,"c:\myassembly.dll"); } 

从源文件创建程序集的一种可能方法是运行CSC(C#命令行编译器),将源文件和引用作为参数传递。 手动IL生成可能过于先进,特别是如果您想从其他人提供的代码构建程序集。

要加载 – 使用Assembly.Load。